trelliscope and forecasting

81 views
Skip to first unread message

Enzo

unread,
Sep 14, 2015, 4:51:32 AM9/14/15
to Tessera-Users
I've been trying to use trelliscope to show seasonality and forecasts (using components and techniques from the forecast package).

I actually used qtrellis and the underlying to_ddf() function.  Not surprisingly qtrellis failed with an error (basically ts and matrix are not supported).

What is my best alternative?  Is there a way to avoid to re-do all of the charts using data.frames or ddf?  (It could  take me for ever!)

many thanks for the help so far

Ryan Hafen

unread,
Sep 14, 2015, 6:45:06 PM9/14/15
to Enzo, Tessera-Users
Hi Enzo,

Could you share some code?  I’m not entirely sure what the issue is or what you wish to do.

When you say that it will take forever, do you mean that there is a lot of computation or that it will take a long time to write the code?

Ryan



--
You received this message because you are subscribed to the Google Groups "Tessera-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tessera-user...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tessera-users/ff4fb344-4b62-496c-8e53-aaa1336736f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Enzo

unread,
Sep 14, 2015, 6:53:21 PM9/14/15
to Tessera-Users
This is a code chunk (I hope it makes some sense).  I have a summarised df with data from 43 police forces in England, with monthly crimes etc.  I am using trellis with this dataset for few things.  I would also like to build a trelliscope with seasonality and forecast per force.

This is my attempt:

> 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.

Ryan Hafen

unread,
Sep 14, 2015, 7:25:59 PM9/14/15
to Enzo, Tessera-Users
Are you trying to do seasonplot for each police force?  If so, can you first divide your data frame on police force and then turn it into a ts object inside the panel function and plot?



--
You received this message because you are subscribed to the Google Groups "Tessera-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tessera-user...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.

Enzo

unread,
Sep 16, 2015, 2:16:58 PM9/16/15
to Tessera-Users, emart...@gmail.com
You are absolutely right! I was thinking too much in the box (or not thinking at all!).

Thanks
Reply all
Reply to author
Forward
0 new messages