I'm trying to build a flexible OLS/SUR/2SLS/3SLS package and I'm having trouble getting some information out of a formula. For example.... # set up the system of equations demand <- q ~ p + d supply <- q ~ p + f + a inst <- ~ d + f + a systemeq <- list( demand, supply ) ...blah, blah, blah... # get the number if instruments... # or build the "bigX"... #I need to get a print of the variables to build a large matrix... print( attr( systemeq[[1]], "variables" ) ) I've tried all kinds of variants... names( systemeq[[1]] ) names( systemeq[[1]]$formula ) 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 at 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 8 Jan 2002, Jeff D. Hamann wrote:> I'm trying to build a flexible OLS/SUR/2SLS/3SLS package and I'm having > trouble getting some information out of a formula. For example.... > > # set up the system of equations > demand <- q ~ p + d > supply <- q ~ p + f + a > inst <- ~ d + f + a > systemeq <- list( demand, supply ) > > ...blah, blah, blah... > > # get the number if instruments... > # or build the "bigX"... > #I need to get a print of the variables to build a large matrix... > print( attr( systemeq[[1]], "variables" ) ) > > I've tried all kinds of variants... > names( systemeq[[1]] ) > names( systemeq[[1]]$formula ) >The complicated answer is that these things are attributes of a terms object, not a formula. You would need attr(terms(supply),"variables") and attr(terms(inst),"variables"). The simpler answer is that you want to use model.frame() (and probably model.matrix() as well.) model.frame() constructs a dataframe with all the required variables for a formula, model.matrix takes this dataframe and produces a design matrix. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Jeff, The tsls function in the SEM package does 2SLS estimation using a formula interface for both the structural equation and the instruments. It only estimates one equation at a time, but perhaps you can use it as a model. I hope that this helps, John At 11:54 AM 1/8/2002 -0800, Jeff D. Hamann wrote:>I'm trying to build a flexible OLS/SUR/2SLS/3SLS package and I'm having >trouble getting some information out of a formula. For example.... > ># set up the system of equations >demand <- q ~ p + d >supply <- q ~ p + f + a >inst <- ~ d + f + a >systemeq <- list( demand, supply ) > >...blah, blah, blah... > ># get the number if instruments... ># or build the "bigX"... >#I need to get a print of the variables to build a large matrix... >print( attr( systemeq[[1]], "variables" ) ) > >I've tried all kinds of variants... >names( systemeq[[1]] ) >names( systemeq[[1]]$formula )----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._