[R-sig-Geo] Breakpoint analysis with two variables
nate_m
Nathaniel.L.Mikle-1 at ou.edu
Fri Feb 7 19:46:08 CET 2014
Hi Robert,
I have gotten the script to work on real data. Segmented was adding an extra
value to the vector after they went through lm. Defining the variables
inside the function side-steps this. Also, some data does not converge so
the try() function allows us to skip those. Thanks for your help! Here is
the basic script if anybody needs help in the future.
fun <- function(z) {
x <- (z[1:11])
b <- (z[12:22])
min_x <- min(z[1:11])
if ( all(is.na(z)) ) {
return( c(NA,NA,NA) )
} else {
coef <- lm(b ~ x)
coef1 <- try(segmented(coef, ~x, psi=min_x), silent = TRUE)
if(class(coef1)=="segmented") {
y <- confint(coef1)$x
} else {
return( c(NA,NA,NA) )
}
y
}
}
ex1 <- calc(z, fun)
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Breakpoint-analysis-with-two-variables-tp7585607p7585725.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list