-1

I am using dlnm and lm to fit a linear model of a number of time series. I would like to visually compare the fitted values with the actual values, and so I want to export both in one csv file. However, it appears that I cannot use ts.intersect to bind them because $fitted.values of the model is not a time series. The documentation of lm suggests that $fitted.values will be a time series if na.action = NULL is passed to the lm. However, this is only possible if the values used as input are defined everywhere, which is not the case if crossbasis is applied with non-trivial lag.

Is there a convenient way to get the actual and fitted time series side by side?

oulenz
  • 1,199
  • 1
  • 15
  • 24
  • Is there a reason why you're not plotting the values directly in R, since you did the estimation there? – kristang Mar 09 '16 at 14:45
  • I find spreadsheet graphs easier to work with, but will happily be convinced otherwise, in particular if plotting the values directly in R in one graph is easier to achieve. – oulenz Mar 09 '16 at 14:54
  • There are plenty of ways to plot in `R`. I would say it's one of the main areas of that keeps getting developed almost monthly. `ggplot2` is the major package for plotting outside of base - http://ggplot2.org/ – kristang Mar 10 '16 at 08:42

1 Answers1

0

I've found a reasonable workaround to reconstruct fitted.values as a time series. ts.intersect does not work with zoo series, merge is the appropriate function:

actual <- actual.values
fit <- read.zoo(data.frame(names(model$fitted.values),model$fitted.values))
result <- merge(actual,fit,all=FALSE) #default all=TRUE gives union
oulenz
  • 1,199
  • 1
  • 15
  • 24