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)
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
It may help you to read Bill Venables' column in R News http://cran.r-project.org/doc/Rnews/Rnews_2002-2.pdf, pages 24-26. Andy> -----Original Message----- > From: Rajarshi Guha [mailto:rxg218 at psu.edu] > Sent: Thursday, October 02, 2003 11:25 AM > To: r-help at stat.math.ethz.ch > Subject: [R] using a string as the formula in rlm > > > 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) > 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 >
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
Have you considered the following:
fmla <- formula(sprintf('V1 ~ V%g + V%g + V%g',2,3,4))
hope this helps. spencer graves
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)
>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
>
>
On Thu, 2003-10-02 at 10:25, 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) > 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? >See ?as.formula You can then construct an expression and use something like: m1 <- rlm(as.formula(expression), data) HTH, Marc Schwartz