Search code examples
rtime-seriesforecasting

Finding Mean Absolute Deviation in Holtwinter


Let's say our dataset looks as follows;

demand <- ts(BJsales, start = c(2000, 1), frequency = 12)
plot(demand)

Now I pass the timeseries object to HoltWinter and plot the fitted data.

hw <- HoltWinters(demand)
plot(hw)

I want to difference Demand and fitted data to find Mean Absolute Deviation(MAD). I took the demand by hw$x I took the fit by hw$fit

accu_Holt_data <- as.data.frame(hw$x)
 fore_holt <- as.data.frame(hw$fit)
differnce <- accu_Holt_data - fore_holt  

cant difference as row length is different


Solution

  • Following up on my comment above, you can do something like this:

    dta <- cbind(hw$fit[, 1], hw$x)
    mean(abs(dta[, 2] - dta[, 1]), na.rm = TRUE)
    

    There are two main issues with your approach: First, hw$fit is a multi-column dataframe where the first column, xhat, represents the filtered series. Second, the two times series have different indices. Hence the need for someting like cbind to merge the time series.