Re: [R] getting the response (dependent) from formula?

About this list Date view Thread view Subject view Author view Attachment view

From: Torsten Hothorn (Torsten.Hothorn@rzmail.uni-erlangen.de)
Date: Wed 16 Jan 2002 - 22:13:59 EST


Message-id: <Pine.LNX.4.21.0201161210360.31727-100000@artemis.imbe.med.uni-erlangen.de>


> I'm trying to build a vector (fitting systems of equations) and I'm having a
> little trouble getting the response variables from a list of formulas...
>
> bdgmodel <- lbdg ~ d1sqr + ld1 + lhg
> hgmodel <- lhg ~ ht2 + lht + whc
> inst <- ~ d1sqr + ld1 + ht2 + lht + whc
> systemeq <- list( bdgmodel, hgmodel )

have a look at (e.g.) wilcox.test.formula:

wilcox.test.formula <-
function(formula, data, subset, na.action, ...)
{
    ...

    m <- match.call(expand.dots = FALSE)
    if(is.matrix(eval(m$data, parent.frame())))
        m$data <- as.data.frame(data)
    m[[1]] <- as.name("model.frame")
    m$... <- NULL
    mf <- eval(m, parent.frame())
   
    ...

    response <- attr(attr(mf, "terms"), "response")

    # And now you can get the response by mf[[-response]]

    myresp <- mf[[-response]]

    ...
}

Torsten

>
> # manually generate the y matrix...
> y <- cbind( matrix( lbdg ),
> matrix( log(hg) ) )
>
> I would like to replace the previous line with something like...
>
> # do the three stage least squares here...
> for(i in 1:length( systemeq ) )
> {
> bigy <- rbind( bigy, attr(terms(systemeq[[i]]),"variables")[2] )
> }
>
> ... then go on to fit the system of equations, etc, etc, etc...
>
> attr(terms(systemeq[[i]]),"variables")[2]
>
> this statement returns
> "lbdg()" - without the quotes, which I can't figure out how to use....
>
> is there an equivalent to model.matrix( systemeq[[1]] )?
>
> Thanks,
> Jeff.
>
>
>
>
> Jeff D. Hamann
> Hamann, Donald & Associates, Inc.
> PO Box 1421
> Corvallis, Oregon USA 97339-1421
> Bus. 541-753-7333
> Cell. 541-740-5988
> jeff_hamann@hamanndonald.com
> www.hamanndonald.com
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 17 Jan 2002 - 11:10:11 EST