[R] using a string as the formula in rlm

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Oct 2 17:43:01 CEST 2003


Rajarshi Guha wrote:

> Hi,
>  I am trying to build a series of rlm models. I have my data frame and
> the models will be built using various coulmns of the data frame.
> 
> Thus a series of models would be
> 
> m1 <- rlm(V1 ~ V2 + V3 + V4, data)
> m2 <- rlm(V1 ~ V2 + V5 + V7, data)
> m3 <- rlm(V1 ~ V2 + V8 + V9, data)
> 
> I would like to automate this. Is it possible to use a string in place
> of the formula?
> 
> I tried doing:
> 
> fmla <- sprintf('V1 ~ V%g + V%g + V%g',2,3,4)

See ?as.formula

Uwe Ligges


> m1 <-rlm(fmla,data)
> 
> I get:
> 
> Error in qr(x) : NA/NaN/Inf in foreign function call (arg 1)
> In addition: Warning message:
> NAs introduced by coercion
> 
> I can understand why this method results in the error but is there any
> way to get around this?
> 
> Thanks,
> 
> -------------------------------------------------------------------
> Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> -------------------------------------------------------------------
> Gods are fragile things; they may be killed by a whiff of
> science or a dose of common sense.
> -- Chapman Cohen
> 
> ______________________________________________
> 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