[R-sig-Geo] Breakpoint analysis with two variables

nate_m Nathaniel.L.Mikle-1 at ou.edu
Wed Jan 22 21:48:58 CET 2014


Hi all,

I am a beginner, so bear with me please. My goal is to perform breakpoint
analysis (package 'segmented') on each cell of two raster stacks (11 files
thick each). Some cells throughout both bricks are NA, so I have to skip
these as well. My goal is to output breakpoints with confidence intervals
based on the two variables for each cell. Here is my code and the error, I
think I am doing something incorrectly with data types;

library(raster)
#each stack is 11 rasters thick
y1 <- stack(y2)
x1 <- stack(x2)

#testing on small region
y <- crop(y1, extent(-103,-102,37,38))
x <- crop(x1, extent(-103,-102,37,38))

fun1 <- function(x) {
  m <- NA
  try(m <- lm(x ~ y), silent=T)
  m
}

library(segmented)

fun2 <- function(x) {
  m <- NA
  try(m <- segmented(x, ~y, psi=150), silent=T)
  m
}

fun3 <- function(x) {
  m <- NA
  try(m <- confint(x), silent=T)
  m
}

e1 <- calc(y, fun1)
os <- calc(e1, fun2)
results <- calc(os, fun3)

This is the error I receive after running the first function with e1;

Error in model.frame.default(formula = x ~ y, drop.unused.levels = TRUE) : 
  invalid type (S4) for variable 'y'

If anybody has a thought as to what I am doing wrong, it would be of great
help! Additionally, I would like to set "psi" from the segmented package
with values from a raster- is this possible?

Thanks in advance,
Nate



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Breakpoint-analysis-with-two-variables-tp7585607.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list