Re: [R] Referencing to an object within a function

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 19 Feb 2008 14:36:21 -0500

On 2/19/2008 2:22 PM, Benjamin Zuckerberg wrote:
>
> 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

You could use traceback() to find the location of the error, but I would suspect it's a bug in segmented.glm. You should contact the maintainer of that package (Vito Muggeo) to work it out. (I've cc'd him.)

Duncan Murdoch



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:40:20 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