[R] forecast.lm() and NEWDATA
Ryan
ryan at urban-econ.com
Mon Nov 4 16:19:22 CET 2013
Hi David (and everyone)
Thank you for your reply.
I see I copied down the code wrong for the regression. I was using the
"+" seperator, and not ",". The regression was working.
I made a mistake with the NEWDATA, where I also used "+", instead of
",", however I see both work but return very different results. I have
corrected the mistake.
However, I am still receiving the same error when I try to run the
forecast.lm.
"
forecast.lm(REGGY, h=5)
i receive the following error
"Error in as.data.frame(newdata) :
argument "newdata" is missing, with no default""
I am sorry to say, I don't understand your reference to the string
output when you mentioned
"
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.
"
As of right now, NEWDATA includes all the independent variables from
the REGGY Regression.
Should the NEWDATA data.frame include the dependent variable?
Also, is it necessary to reformat all variables as time series? (I have
not currently done so)
Regards
Ryan
On 2013-11-01 07:28 PM, David Winsemius wrote:
> 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.
More information about the R-help
mailing list