[R-sig-Geo] Raster regression cooeficients plot?

Robert Hijmans r.hijmans at gmail.com
Wed Jun 15 19:53:44 CEST 2011


> I am analysing monthly time series data using rasterbrick.
> Commands below give me one slope plot
>
> fun <- function(x) { lm(x ~ time)$coefficients[2] }
> slope <- calc(s, fun)
> plot(slope)
>
>
> But what other 7 plots means when I run these lines...
> fun <- function(x) { lm(x ~ time)$coefficients }
>  x3<- calc(s, fun)
> plot(x3)

I do not know, because I do not know what "time" refers to. My guess is that
it is a factor with 6 levels as that would give you 7 coefficients
(intercept + 6). 

This might be clear from the layerNames of x3 (shown as the titles of the
plots). 
perhaps this becomes clear if you do:

m <- lm( as.vector(x[1]) ~ time) # assuming that the first cell does not
only have NA values
m$coefficients 
str(m)


If you want an intercept and slope, time should be numeric. For example,
here:

time <- 1:nlayers(s)
fun <- function(x) { lm(x ~ time)$coefficients }
x4 <- calc(s, fun)

should return 2 layers.


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Raster-regression-cooeficients-plot-tp6478377p6479923.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list