[R] using update( ) in a function?

Roger Peng rpeng at stat.ucla.edu
Mon Apr 21 19:46:52 CEST 2003


I believe this is bug PR#1861.  Not sure what the workaround is.

-roger
_______________________________
UCLA Department of Statistics
http://www.stat.ucla.edu/~rpeng

On Mon, 21 Apr 2003, Mahmood ARAI wrote:

> Hello, 
> 
> using the function "update()" in the following function
> does not work. 
> 
> # a function for running a model:  x1 ~ x2
> # by updating the original model: fm1 <- lm(y ~ x1 + x2,data=df)
> # update(fm1, x1 ~ . -x1, data=df) works at the command line
> # but not in the function below. 
> 
> 
> R>   foo <- function(fm,x,df)
> +     {
> +     update(fm, x ~ . -x,data=df)
> +     }
> R>
> R>
> R>  df1 <- data.frame(y= 1:10, x1=(1:10)^2, x2=sqrt(1:10)^3)
> R>  fm1 <- lm(y ~ x1+x2, data=df1)
> R>
> R>  foo(fm1, x1, df1)
> Error in eval(expr, envir, enclos) : Object "x" not found
> R>  update(fm1, x1 ~ . -x1,data=df1) 
> 
> Call:
> lm(formula = x1 ~ x2, data = df1) 
> 
> Coefficients:
> (Intercept)           x2
>     -7.753        3.242 
> 
> any idea? 
> 
> thanks!
> mahmood arai
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>



More information about the R-help mailing list