Looking to find geometric mean of monthly data that's been converted into quarterly data. I've tried several methods but only provide simple arithmetic mean as shown below. Thanks.
monthly <- ts(mydata,start=c(1960,1),frequency=12)
quarterly <- aggregate(monthly, nfrequency=4,mean) ---need geometric mean
This looks promising but unable to mimic the above simple arithmetic mean which considers the monthly to quarterly data transformation:
# Function to calculate the geometric mean
geometricMean <- function(array){
if(!is.numeric(array)){
stop("Passed argument must be an array. Consider using sapply for data frames.")
}
if(any(array<0)){
stop("All values must be greater than zero. If you are attempting to
apply this function to rates, convert to +1 format. For example,
5% becomes 1.05 and -20% becomes .8.")
}
prod(array)^(1/length(array))
}
The data has been transformed into percentage change rates (month_12 - month_11 / month_11)