[R] Referencing to an object within a function

From: Benjamin Zuckerberg <bzuckerb_at_syr.edu>
Date: Tue, 19 Feb 2008 14:22:51 -0500

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){


	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.

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Feb 2008 - 19:25:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 20:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive