> dt_ <- dcast.data.table(dt_[,.(year, month, crimes,force)], year+ month ~ force,
+ value.var=c("crimes"), max)
> df_ <- as.data.frame(dt_)
> row.names(df_) <- df_$month
> df_$month <- df_$year <- NULL
> dm_ <- ts(data.matrix(df_), start=c(2012,1),frequency=12)
> panelForecast <- function(x){
+ seasonplot(x, ylab="Crimes", xlab="Year",
+ main=paste0("Seasonal plot: ",force," Crimes"),
+ year.labels=TRUE, year.labels.left=TRUE, col=1:20, pch=21)
+ fit <- ets(dm_[,"crimes"], model="ZZZ")
+ plot(forecast(fit, h=12), ylab="Crimes")
+ }
> dm_ %>% qtrellis(by = c(labs),
+ panelForecast,
+ layout = c(2, 4),
+ conn = getOption("vdbConn"),
+ name= "Forecast by Force")
This is the error I get:
Error in UseMethod("qtrellis") :
no applicable method for 'qtrellis' applied to an object of class "c('mts', 'ts', 'matrix')"
The lengthy time I mentioned is about re-coding part of forecast package (that uses 'mts', 'ts', 'matrix' !) to use da df.
Thanks.