Hello -

Keld Jørn Simonsen wrote:
Hi
I have a problem with lm and predict

I have
us
 [1]  2789.53  3128.43  3255.03  3536.68  3933.18  4220.25  4462.83 4739.48
 [9]  5103.75  5484.35  5803.08  5995.93  6337.75  6657.40  7072.23 7397.65
[17]  7816.83  8304.33  8746.98  9268.43  9816.98 10127.95 10469.60 10960.75
[25] 11685.93 12433.93 13194.70 13843.83


 us.p
 [1] 227.62 229.92 232.13 234.25 236.31 238.42 240.59 242.75 244.97 247.29
[11] 250.05 253.39 256.78 260.15 263.33 266.46 269.58 272.82 276.02 279.20
[21] 282.31 285.25 288.10 290.85 293.53 296.26 299.08 301.97

 us.l = lm(log(us) ~ log(us.p))
predict(us.l,n.ahead=5)
1 2 3 4 5 6 7 8 8.079754 8.131908 8.181531 8.228692 8.274111 8.320224 8.367224 8.413588 9 10 11 12 13 14 15 16 8.460813 8.509709 8.567285 8.636117 8.705057 8.772694 8.835719 8.897015 17 18 19 20 21 22 23 24 8.957402 9.019376 9.079867 9.139289 9.196752 9.250495 9.302067 9.351347 25 26 27 28 9.398927 9.446950 9.496094 9.545979


Why does predict not give me any predictions? The result of predict() is
same lenght (28) as the us and us.p variables.

The version of 'predict' being called on 'us.l' (i.e., predict.lm) is doing predictions, and it should be giving you a result of identical length as your original vectors. What are you expecting here? Your usage of the 'n.ahead' parameter suggests to me you might be wanting to fit your model using a different function than 'lm', and use its corresponding prediction function.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to