[R-sig-Geo] interpolating

Tom Gottfried tom.gottfried at o2mail.de
Wed Aug 15 06:10:04 CEST 2012


?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 find a linear regression for each place across the 3 years. I then need to interpolate the data to get the missing years for the given location ie I need all the data for 1991, 1992, 1993 etc. I have a loop and I have figured out how to make the 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 problems is
>
> 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'
>
>   how do I define y without hardcoding the coefficients as they will change for every location. I basically need to do linear regressions for each location then interpolate the data to get yearly data in order to put this data in another model that requires yearly data.
>
> Thanks
>
> KJ
> 	[[alternative HTML version deleted]]
>
>
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list