[R] Referencing to an object within a function

Benjamin Zuckerberg bzuckerb at syr.edu
Tue Feb 19 20:22:51 CET 2008



I am encountering an error when I attempt to reference a glm model  
within a function.  The function uses the segmented.glm command  
(package = segmented).  Within the segmented.glm command one specifies  
an object, in this case a logistic regression model, and specifies a  
starting threshold term (psi).  I believe this is an environment  
problem, but I do not have a solution.  Any assistance would be  
greatly appreciated.  The function is as follows:

> colonization <- function(x,y){
library(segmented)
	col <- subset(final,final[,x] == 2 | final[,x] == 4)
	col[,x] <- ifelse(col[,x] == 2,1,0)
	glm1 <- glm(col[,x]~col[,"PLAND"],family=binomial)
	glm2 <- segmented.glm(obj = glm1, seg.Z = ~PLAND, psi=y, it.max = 100)
}
> colonization("PIWO",48)

Error in eval(expr, envir, enclos) : object "x" not found


Thank you.



More information about the R-help mailing list