[R] forecast.lm() and NEWDATA
David Winsemius
dwinsemius at comcast.net
Fri Nov 1 18:28:50 CET 2013
On Nov 1, 2013, at 6:50 AM, Ryan wrote:
> Good day all.
>
> I am hoping you can help me (and I did this right). I've been working in R for a week now, and have encountered a problem with forecast.lm().
>
> I have a list of 12 variables, all type = double, with 15 data entries.
> (I imported them from tab delimited text files, and then formatted as.numeric to change from list to double)
> (I understand that this leaves me rather limited in my degrees of freedom, but working with what I have, sadly. )
>
> I have a LM model, such that
> REGGY = lm(formula=Y~A,B,C,...,I,J)
This looks wrong. Separating independent predictors with commas would be highly unusual.
> which I am happy with.
>
> I have
> NEWDATA = data.frame(A+B+C+D....+I+J)
This also looks wrong. Separating arguments to data.frame with "+"-signs is surely wrong.
>
> When i try to run
>
> forecast.lm(REGGY, h=5)
>
> i receive the following error
> "Error in as.data.frame(newdata) :
> argument "newdata" is missing, with no default"
If your code prior to calling forecast on the REGGY-object was really what you showed here, I am not surprised. You should post the output of str() on the data-objects that has the 12 variables and if it was modified the data argument pasted to `lm()` when you made REGGY. (Beginners should name their data arguments.)
>
> When I run
> forecast.lm(REGGY, NEWDATA, h=5)
> I receive the confidence intervals of the 15 data entries I already possess. I understand that by including NEWDATA, the "h=5" is ignored, but without NEWDATA, I receive the error message.
>
> Can anyone help me please?
>
> Regards
> Ryan
>
> P.S The forecast is trying to predict the next 5 values for Y from the regression model pasted above. I'm a bit rusty with regressions, but I think I've covered my bases as well as I can, and from what I understand of the R code, I'm following the right steps.
Not if what you posted here was your code. I think you missed a few crucials points about R syntax.
>
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list