I am attempting to do the following question and am stuck on part 1 where I am asked to fit the regression model and interpret the results. I was taught how to do this for a model with just B1 and linear (t-1978), but now with B2(t-1978)^2 I am confused how to do it?
library(climate) #R package of choice for Time series module
trend= time(co2) - 1978
#Turn months to factors
M = factor(cycle(co2))
reg = lm(co2 ~ time ( co2 ) + I( time (co2)^2) + trend + M,
na.action = NULL)
summary(reg)
I have tried the above and my trend is NA
so it is clearly wrong
You seem pretty close (I was very confused by the cycle(co2)
, time(co2)
calls, which are working with ts
objects. If I put in trend
instead of time(co2)
I get sensible answers ...
reg = lm(co2 ~ trend + I(trend^2) + M, na.action = NULL)