Hi
Here is some of my code
jan_ppt_i<- structure(c(155.100006103516, 203.931690865494, 218.219503262085
), .Names = c("prec_clim_jan", "pr_2040a1b_jan_ukmo_hadcm3",
"pr_2090a1b_jan_ukmo_hadcm3"))
day<-c(1,18262,36525)
#linear regression of the data
linr_jan<-predict(lm(jan_ppt_i~day))
#prediction where it stops working
x<-data.frame(c(1,2,3,4))
pred<-predict(lm(jan_ppt_i~day), x)
Warning message:
'newdata' had 4 rows but variable(s) found have 3 rows
Thanks for your help
KJ
*From:* Tom Gottfried <tom.gottfried at o2mail.de>
*To:* r-sig-geo at r-project.org
*Sent:* Monday, August 20, 2012 8:16 PM
*Subject:* Re: [R-sig-Geo] Interpolating
Am 20.08.2012 05:08, schrieb K Jjw:
> Hi
> I tried predict but I get an error. Warning message: 'newdata' had 4
rows but variable(s) found have 3 rows
> it only works if the number of rows that i am trying to predict are
the same as the original number of rows (3). It does however work when I
try to do the same thing for example in ?predict (tried with 17 rows to
predict when the original function is 15 rows) . Not sure what is going
on. Has anyone run into the same problem before?
Not sure what is going on neither. But a reproducible example would
surely help you and others on the list to get to know what is going on.
Regards,
Tom
> Thanks
> KJ
>
>
>
> ?predict
> ?predict.lm
>
> HTH,
> Tom
>
> Am 15.08.2012 04:05, schrieb K Jjw:
>> Hi
>>
>>
>> I have data that are from 1990, 2040, and 2090. I
> need to loop through each location (defined in a grid of 240x260) and
> linear regression for each place across the 3 years. I then need to
> the data to get the missing years for the given location ie I need
> for 1991, 1992, 1993 etc. I have a loop and I have figured out how to
> model ie lm(). What I am having difficulty with is interpolating the data
> without hardcoding in the formula of the linear regression.
>>
>> so basically the bit of code that is causing me
>>
>> linr<-lm(jan_ppt~date)
>> linr
>>
>> Call:
>> lm(formula = jan_ppt ~ date)
>>
>> Coefficients:
>> (Intercept) date
>> 1.482e+02 1.728e-03
>>
>> x<- 1990:2090
>> y<-1.482e2 + 1.728e-3*x #this is what I have now
>> y<- intercept+ grad*x #this is what I want where
> 'intercept' and 'grad' are defined from the model 'linr'
> define y without hardcoding the coefficients as they will change for
> location. I basically need to do linear regressions for each location
> interpolate the data to get yearly data in order to put this data in
> model that requires yearly data.
>>
>> Thanks
>>
>> KJ
>> [[alternative