# gridded time series analysis

42 messages
123
Open this post in threaded view
|

## gridded time series analysis

 Dear Members, I have two variables on a 507 x 356 grid and each grid cell has a time series of length 120.  Is it possible to perform a time series analysis on the entire grid all at the same time, with the ultimate goal of doing linear regressions for each grid point for the 2 variables? Are there functions available or will I have to utilize for loops and repeat it for each grid cell? I have been trying out the package "ts" but not sure if it can handle 3d variables. Any pointers will be greatly appreciated. Thanks, -- advait godbole         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 this is what I did to perform a regression between two bricks (each brick represent a time series): r <- raster(brick1) for (i in 1:ncell(r)) { r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, i)))\$coefficients[2] } The result will be a slope raster, but it really takes a lot of time, so maybe there is a better solution.. Martin Brandt Department of Geography and Regional Research UZA II, Althanstr. 14 1090 Wien, AUSTRIA http://geooekologie.univie.ac.at
Open this post in threaded view
|

## Re: gridded time series analysis

 that's cool, I'm also interested in a similar problem but just with one brick ending up with a slope raster as the output. It may be possible with stackApply(). have a look. or maybe robert will chime in On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: > > this is what I did to perform a regression between two bricks (each brick > represent a time series): > > r <- raster(brick1) > for (i in 1:ncell(r)) { > r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, > i)))\$coefficients[2] > } > > The result will be a slope raster, but it really takes a lot of time, so > maybe there is a better solution.. > > > -- > View this message in context: > http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html> Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo>         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 you could try this approach (use calc whenever you can): (supposing your bricks have 12 layers) br3 <- stack(brick1, brick2) lmS <- function(x) lm(x[1:12] ~ x[13:24)\$coefficients[2] r <- calc(br3, lmS) Jacob. --- On Fri, 26/11/10, steven mosher <[hidden email]> wrote: From: steven mosher <[hidden email]> Subject: Re: [R-sig-Geo] gridded time series analysis To: "Martin" <[hidden email]> Cc: [hidden email] Date: Friday, 26 November, 2010, 23:33 that's cool, I'm also interested in a similar problem but just with one brick ending up with a slope raster as the output. It may be possible with stackApply(). have a look. or maybe robert will chime in On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: > > this is what I did to perform a regression between two bricks (each brick > represent a time series): > > r <- raster(brick1) > for (i in 1:ncell(r)) { > r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, > i)))\$coefficients[2] > } > > The result will be a slope raster, but it really takes a lot of time, so > maybe there is a better solution.. > > > -- > View this message in context: > http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html> Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo>     [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo              [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 It seems that 'calc' does not like this (any more; another thing to fix) . If your rasters are not very large you can use apply, which makes it much faster: library(raster) #creating some data r <- raster(nrow=10, ncol=10) s <- list() for (i in 1:25) { s[i] <- setValues(r, rnorm(ncell(r), i, 3) ) } s <- stack(s) # regression time <- 1:nlayers(s) fun <- function(x) { lm(x ~ time)\$coefficients[2] } r[] <- apply(getValues(s), 1, fun) Robert On Fri, Nov 26, 2010 at 2:51 PM, Jacob van Etten <[hidden email]> wrote: > you could try this approach (use calc whenever you can): > > (supposing your bricks have 12 layers) > > br3 <- stack(brick1, brick2) > lmS <- function(x) lm(x[1:12] ~ x[13:24)\$coefficients[2] > r <- calc(br3, lmS) > > Jacob. > > --- On Fri, 26/11/10, steven mosher <[hidden email]> wrote: > > From: steven mosher <[hidden email]> > Subject: Re: [R-sig-Geo] gridded time series analysis > To: "Martin" <[hidden email]> > Cc: [hidden email] > Date: Friday, 26 November, 2010, 23:33 > > that's cool, I'm also interested in a similar problem but just with one > brick ending up with a slope raster as the output. It may be possible with > stackApply(). have a look. or maybe robert will chime in > > > > On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: > >> >> this is what I did to perform a regression between two bricks (each brick >> represent a time series): >> >> r <- raster(brick1) >> for (i in 1:ncell(r)) { >> r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, >> i)))\$coefficients[2] >> } >> >> The result will be a slope raster, but it really takes a lot of time, so >> maybe there is a better solution.. >> >> >> -- >> View this message in context: >> http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html>> Sent from the R-sig-geo mailing list archive at Nabble.com. >> >> _______________________________________________ >> R-sig-Geo mailing list >> [hidden email] >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> > >     [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> > > > >        [[alternative HTML version deleted]] > > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> > _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 There are some difference in the behavior of 'calc' between functions, because of attempts to accommodate different functions & intentions. But in 'raster' 1.7-4 (available from R-Forge in ~ 24 hrs; and from CRAN soon), the below will work: library(raster) #creating some data r <- raster(nrow=10, ncol=10) s1 <- s2<- list() for (i in 1:12) {         s1[i] <- setValues(r, rnorm(ncell(r), i, 3) )         s2[i] <- setValues(r, rnorm(ncell(r), i, 3) ) } s1 <- stack(s1) s2 <- stack(s2) # regression of values in one brick (or stack) with another (Jacob's suggestion) s <- stack(s1, s2) # s1 and s2 have 12 layers fun <- function(x) { lm(x[1:12] ~ x[13:24])\$coefficients[2] } x1 <- calc(s, fun) # regression of values in one brick (or stack) with 'time' time <- 1:nlayers(s) fun <- function(x) { lm(x ~ time)\$coefficients[2] } x2 <- calc(s, fun) # get multiple layers, e.g. the slope _and_ intercept fun <- function(x) { lm(x ~ time)\$coefficients } x3 <- calc(s, fun) If this does not work in your version, you can use apply( ) as in what I send earlier. Robert On Fri, Nov 26, 2010 at 2:56 PM, Robert J. Hijmans <[hidden email]> wrote: > It seems that 'calc' does not like this (any more; another thing to > fix) . If your rasters are not very large you can use apply, which > makes it much faster: > > library(raster) > #creating some data > r <- raster(nrow=10, ncol=10) > s <- list() > for (i in 1:25) { s[i] <- setValues(r, rnorm(ncell(r), i, 3) ) } > s <- stack(s) > > # regression > time <- 1:nlayers(s) > fun <- function(x) { lm(x ~ time)\$coefficients[2] } > r[] <- apply(getValues(s), 1, fun) > > Robert > > > > On Fri, Nov 26, 2010 at 2:51 PM, Jacob van Etten > <[hidden email]> wrote: >> you could try this approach (use calc whenever you can): >> >> (supposing your bricks have 12 layers) >> >> br3 <- stack(brick1, brick2) >> lmS <- function(x) lm(x[1:12] ~ x[13:24)\$coefficients[2] >> r <- calc(br3, lmS) >> >> Jacob. >> >> --- On Fri, 26/11/10, steven mosher <[hidden email]> wrote: >> >> From: steven mosher <[hidden email]> >> Subject: Re: [R-sig-Geo] gridded time series analysis >> To: "Martin" <[hidden email]> >> Cc: [hidden email] >> Date: Friday, 26 November, 2010, 23:33 >> >> that's cool, I'm also interested in a similar problem but just with one >> brick ending up with a slope raster as the output. It may be possible with >> stackApply(). have a look. or maybe robert will chime in >> >> >> >> On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: >> >>> >>> this is what I did to perform a regression between two bricks (each brick >>> represent a time series): >>> >>> r <- raster(brick1) >>> for (i in 1:ncell(r)) { >>> r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, >>> i)))\$coefficients[2] >>> } >>> >>> The result will be a slope raster, but it really takes a lot of time, so >>> maybe there is a better solution.. >>> >>> >>> -- >>> View this message in context: >>> http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html>>> Sent from the R-sig-geo mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> [hidden email] >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>>> >> >>     [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> [hidden email] >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> >> >> >> >>        [[alternative HTML version deleted]] >> >> >> _______________________________________________ >> R-sig-Geo mailing list >> [hidden email] >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> >> > _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 Thanks everyone for these leads..However, I am running into problems with data handling. I used ncdf to extract the two variables (507 x 356 x 120 - lon,lat,time) and converted them into array objects. The suggestions provided all utilize the raster package, but using "brick" on the file returns this error: "rcmraster <- brick("regcm.cumul.hdd.10k.96_05.new.nc") Error in if (e@xmin > -400 & e@xmax < 400 & e@ymin > -90.1 & e@ymax <  : missing value where TRUE/FALSE needed" I have a fair number of NAs (all missing values in the original variables). Is there a way to set a flag for that? Or any other workaround? Thanks much, advait On Fri, Nov 26, 2010 at 6:25 PM, Robert J. Hijmans <[hidden email]>wrote: > There are some difference in the behavior of 'calc' between functions, > because of attempts to accommodate different functions & intentions. > But in 'raster' 1.7-4 (available from R-Forge in ~ 24 hrs; and from > CRAN soon), the below will work: > > library(raster) > #creating some data > r <- raster(nrow=10, ncol=10) > s1 <- s2<- list() > for (i in 1:12) { >        s1[i] <- setValues(r, rnorm(ncell(r), i, 3) ) >        s2[i] <- setValues(r, rnorm(ncell(r), i, 3) ) > } > s1 <- stack(s1) > s2 <- stack(s2) > > # regression of values in one brick (or stack) with another (Jacob's > suggestion) > s <- stack(s1, s2) > # s1 and s2 have 12 layers > fun <- function(x) { lm(x[1:12] ~ x[13:24])\$coefficients[2] } > x1 <- calc(s, fun) > > # regression of values in one brick (or stack) with 'time' > time <- 1:nlayers(s) > fun <- function(x) { lm(x ~ time)\$coefficients[2] } > x2 <- calc(s, fun) > > # get multiple layers, e.g. the slope _and_ intercept > fun <- function(x) { lm(x ~ time)\$coefficients } > x3 <- calc(s, fun) > > If this does not work in your version, you can use apply( ) as in what > I send earlier. > > Robert > > On Fri, Nov 26, 2010 at 2:56 PM, Robert J. Hijmans <[hidden email]> > wrote: > > It seems that 'calc' does not like this (any more; another thing to > > fix) . If your rasters are not very large you can use apply, which > > makes it much faster: > > > > library(raster) > > #creating some data > > r <- raster(nrow=10, ncol=10) > > s <- list() > > for (i in 1:25) { s[i] <- setValues(r, rnorm(ncell(r), i, 3) ) } > > s <- stack(s) > > > > # regression > > time <- 1:nlayers(s) > > fun <- function(x) { lm(x ~ time)\$coefficients[2] } > > r[] <- apply(getValues(s), 1, fun) > > > > Robert > > > > > > > > On Fri, Nov 26, 2010 at 2:51 PM, Jacob van Etten > > <[hidden email]> wrote: > >> you could try this approach (use calc whenever you can): > >> > >> (supposing your bricks have 12 layers) > >> > >> br3 <- stack(brick1, brick2) > >> lmS <- function(x) lm(x[1:12] ~ x[13:24)\$coefficients[2] > >> r <- calc(br3, lmS) > >> > >> Jacob. > >> > >> --- On Fri, 26/11/10, steven mosher <[hidden email]> wrote: > >> > >> From: steven mosher <[hidden email]> > >> Subject: Re: [R-sig-Geo] gridded time series analysis > >> To: "Martin" <[hidden email]> > >> Cc: [hidden email] > >> Date: Friday, 26 November, 2010, 23:33 > >> > >> that's cool, I'm also interested in a similar problem but just with one > >> brick ending up with a slope raster as the output. It may be possible > with > >> stackApply(). have a look. or maybe robert will chime in > >> > >> > >> > >> On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: > >> > >>> > >>> this is what I did to perform a regression between two bricks (each > brick > >>> represent a time series): > >>> > >>> r <- raster(brick1) > >>> for (i in 1:ncell(r)) { > >>> r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, > >>> i)))\$coefficients[2] > >>> } > >>> > >>> The result will be a slope raster, but it really takes a lot of time, > so > >>> maybe there is a better solution.. > >>> > >>> > >>> -- > >>> View this message in context: > >>> > http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html> >>> Sent from the R-sig-geo mailing list archive at Nabble.com. > >>> > >>> _______________________________________________ > >>> R-sig-Geo mailing list > >>> [hidden email] > >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo> >>> > >> > >>     [[alternative HTML version deleted]] > >> > >> _______________________________________________ > >> R-sig-Geo mailing list > >> [hidden email] > >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo> >> > >> > >> > >> > >>        [[alternative HTML version deleted]] > >> > >> > >> _______________________________________________ > >> R-sig-Geo mailing list > >> [hidden email] > >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo> >> > >> > > > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> -- advait godbole         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 Advait, That suggests that you have missing values in the lon or lat dimensions. Is that true? That would be awkward, but perhaps something else is going on. Can you send me your file? If not can you send the results of this: filename <- "regcm.cumul.hdd.10k.96_05.new.nc" nc <- open.ncdf(filename) length(nc\$dim[[1]]\$vals) length(nc\$dim[[2]]\$vals) nc\$dim[[1]]\$vals nc\$dim[[2]]\$vals close.ncdf(nc) Thanks, Robert On Sat, Nov 27, 2010 at 8:36 AM, Advait Godbole <[hidden email]> wrote: > Thanks everyone for these leads..However, I am running into problems with > data handling. I used ncdf to extract the two variables (507 x 356 x 120 - > lon,lat,time) and converted them into array objects. The suggestions > provided all utilize the raster package, but using "brick" on the file > returns this error: "rcmraster <- brick("regcm.cumul.hdd.10k.96_05.new.nc") > Error in if (e@xmin > -400 & e@xmax < 400 & e@ymin > -90.1 & e@ymax <  : > missing value where TRUE/FALSE needed" > > I have a fair number of NAs (all missing values in the original variables). > Is there a way to set a flag for that? Or any other workaround? > Thanks much, > advait > On Fri, Nov 26, 2010 at 6:25 PM, Robert J. Hijmans <[hidden email]> > wrote: >> >> There are some difference in the behavior of 'calc' between functions, >> because of attempts to accommodate different functions & intentions. >> But in 'raster' 1.7-4 (available from R-Forge in ~ 24 hrs; and from >> CRAN soon), the below will work: >> >> library(raster) >> #creating some data >> r <- raster(nrow=10, ncol=10) >> s1 <- s2<- list() >> for (i in 1:12) { >>        s1[i] <- setValues(r, rnorm(ncell(r), i, 3) ) >>        s2[i] <- setValues(r, rnorm(ncell(r), i, 3) ) >> } >> s1 <- stack(s1) >> s2 <- stack(s2) >> >> # regression of values in one brick (or stack) with another (Jacob's >> suggestion) >> s <- stack(s1, s2) >> # s1 and s2 have 12 layers >> fun <- function(x) { lm(x[1:12] ~ x[13:24])\$coefficients[2] } >> x1 <- calc(s, fun) >> >> # regression of values in one brick (or stack) with 'time' >> time <- 1:nlayers(s) >> fun <- function(x) { lm(x ~ time)\$coefficients[2] } >> x2 <- calc(s, fun) >> >> # get multiple layers, e.g. the slope _and_ intercept >> fun <- function(x) { lm(x ~ time)\$coefficients } >> x3 <- calc(s, fun) >> >> If this does not work in your version, you can use apply( ) as in what >> I send earlier. >> >> Robert >> >> On Fri, Nov 26, 2010 at 2:56 PM, Robert J. Hijmans <[hidden email]> >> wrote: >> > It seems that 'calc' does not like this (any more; another thing to >> > fix) . If your rasters are not very large you can use apply, which >> > makes it much faster: >> > >> > library(raster) >> > #creating some data >> > r <- raster(nrow=10, ncol=10) >> > s <- list() >> > for (i in 1:25) { s[i] <- setValues(r, rnorm(ncell(r), i, 3) ) } >> > s <- stack(s) >> > >> > # regression >> > time <- 1:nlayers(s) >> > fun <- function(x) { lm(x ~ time)\$coefficients[2] } >> > r[] <- apply(getValues(s), 1, fun) >> > >> > Robert >> > >> > >> > >> > On Fri, Nov 26, 2010 at 2:51 PM, Jacob van Etten >> > <[hidden email]> wrote: >> >> you could try this approach (use calc whenever you can): >> >> >> >> (supposing your bricks have 12 layers) >> >> >> >> br3 <- stack(brick1, brick2) >> >> lmS <- function(x) lm(x[1:12] ~ x[13:24)\$coefficients[2] >> >> r <- calc(br3, lmS) >> >> >> >> Jacob. >> >> >> >> --- On Fri, 26/11/10, steven mosher <[hidden email]> wrote: >> >> >> >> From: steven mosher <[hidden email]> >> >> Subject: Re: [R-sig-Geo] gridded time series analysis >> >> To: "Martin" <[hidden email]> >> >> Cc: [hidden email] >> >> Date: Friday, 26 November, 2010, 23:33 >> >> >> >> that's cool, I'm also interested in a similar problem but just with one >> >> brick ending up with a slope raster as the output. It may be possible >> >> with >> >> stackApply(). have a look. or maybe robert will chime in >> >> >> >> >> >> >> >> On Fri, Nov 26, 2010 at 1:35 PM, Martin <[hidden email]> wrote: >> >> >> >>> >> >>> this is what I did to perform a regression between two bricks (each >> >>> brick >> >>> represent a time series): >> >>> >> >>> r <- raster(brick1) >> >>> for (i in 1:ncell(r)) { >> >>> r[i] = lm(as.ts(cellValues(brick1, i)) ~ as.ts(cellValues(brick2, >> >>> i)))\$coefficients[2] >> >>> } >> >>> >> >>> The result will be a slope raster, but it really takes a lot of time, >> >>> so >> >>> maybe there is a better solution.. >> >>> >> >>> >> >>> -- >> >>> View this message in context: >> >>> >> >>> http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5778472.html>> >>> Sent from the R-sig-geo mailing list archive at Nabble.com. >> >>> >> >>> _______________________________________________ >> >>> R-sig-Geo mailing list >> >>> [hidden email] >> >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> >>> >> >> >> >>     [[alternative HTML version deleted]] >> >> >> >> _______________________________________________ >> >> R-sig-Geo mailing list >> >> [hidden email] >> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> >> >> >> >> >> >> >> >> >>        [[alternative HTML version deleted]] >> >> >> >> >> >> _______________________________________________ >> >> R-sig-Geo mailing list >> >> [hidden email] >> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>> >> >> >> >> > >> >> _______________________________________________ >> R-sig-Geo mailing list >> [hidden email] >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo> > > > -- > advait godbole > _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 In reply to this post by Robert Hijmans thanks Robert, this works fine. but could it be that the functions have a problem with NA-values? your Regression functions return this error: > x3 <- calc(tt, fun) error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :   0 (non-NA) cases when i use rasters with NA values...it works without problems with rasters without NAs.. cheers, Martin Martin Brandt Department of Geography and Regional Research UZA II, Althanstr. 14 1090 Wien, AUSTRIA http://geooekologie.univie.ac.at
Open this post in threaded view
|

## Re: gridded time series analysis

 Martin, I think the problem is whith the lm function that returns an error rather than NA: > a <- rep(NA,10) > lm(a~a) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :   0 (non-NA) cases #rather than something like this: > fun=function(x) { lm(x[1]~x[2])\$coefficients[2] } > fun(c(NA,NA)) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :   0 (non-NA) cases #you could catch this in your function and do something like: > fun=function(x) { if (is.na(x[1])){ NA } else { lm(x[1]~x[2])\$coefficients[2] }} > fun(c(NA,NA)) [1] NA and then: calc(s, fun=fun) lm and relatives have an na.action argument but I do not think that can come to the rescue here. Roberrt On Sun, Nov 28, 2010 at 4:33 AM, Martin <[hidden email]> wrote: > > thanks Robert, this works fine. > but could it be that the functions have a problem with NA-values? > your Regression functions return this error: > > >> x3 <- calc(tt, fun) > error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : >  0 (non-NA) cases > > when i use rasters with NA values...it works without problems with rasters > without NAs.. > > cheers, > Martin > > > > > -- > View this message in context: http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5781554.html> Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

 that works Robert, thanks a lot! Martin Brandt Department of Geography and Regional Research UZA II, Althanstr. 14 1090 Wien, AUSTRIA http://geooekologie.univie.ac.at
Open this post in threaded view
|

## Re: gridded time series analysis

 another thing which might be interesting: I know I can call the intercept with "coefficients[1]" and the slope with "coefficients[2]". But is it also possible to get a gridded result with the other lm regression results (normaly available via "summary()") , like R², p-value, or residuals? Martin Martin Brandt Department of Geography and Regional Research UZA II, Althanstr. 14 1090 Wien, AUSTRIA http://geooekologie.univie.ac.at
Open this post in threaded view
|

## Re: gridded time series analysis

Open this post in threaded view
|

## Re: gridded time series analysis

Open this post in threaded view
|

## Re: gridded time series analysis

 In reply to this post by Martin You can return anything you like, as long as it is numeric (or a vector of numerics). R^2 should come out like this:  fun=function(x) { if (is.na(x[1])){ NA } else { m <- lm(x[1]~x[2])\$coefficients[2]; summary(m)\$r.squared  }} slope and R^2  fun=function(x) { if (is.na(x[1])){ NA } else { m <- lm(x[1]~x[2])\$coefficients[2]; c(m\$coefficients[2], summary(m)\$r.squared  }} Robert On Mon, Nov 29, 2010 at 1:58 AM, Martin <[hidden email]> wrote: > > another thing which might be interesting: > > I know I can call the intercept with "coefficients[1]" and the slope with > "coefficients[2]". But is it also possible to get a gridded result with the > other lm regression results (normaly available via "summary()") , like R², > p-value, or residuals? > > Martin > > > -- > View this message in context: http://r-sig-geo.2731867.n2.nabble.com/gridded-time-series-analysis-tp5775651p5783798.html> Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: gridded time series analysis

Open this post in threaded view
|

## Re: gridded time series analysis

Open this post in threaded view
|

## Re: gridded time series analysis

Open this post in threaded view
|