[R] limited formula length in tsls

John Fox jfox at mcmaster.ca
Thu Aug 23 16:55:30 CEST 2001


Dear Brian,

At 11:34 AM 23/08/2001 +0100, Prof Brian Ripley wrote:


>If you want the rhs, paste(deparse(mod[[3]], 500), collapse="") is what
>you want.  Do using indexing on the object itself, not on some dump of it.

This comment applies to my proposed code as well, so a better version would be:

tsls.formula <- function(model, instruments, data, subset,
     na.action, contrasts=NULL){
     if (missing(na.action))
         na.action <- options()$na.action
     m <- match.call(expand.dots = FALSE)
     if (is.matrix(eval(m$data, sys.frame(sys.parent()))))
         m$data <- as.data.frame(data)
     response.name <- deparse(model[[2]])
     formula <- as.formula(paste(response.name, '~',
         deparse(model[[3]]), '+', deparse(instruments[[2]])))
     m$formula <- formula
     m$instruments <- m$model <- m$contrasts <- NULL
     m[[1]] <- as.name("model.frame")
     mf <- eval(m, sys.frame(sys.parent()))
     na.act <- attr(mf, "na.action")
     Z <- model.matrix(instruments, data = mf, contrasts)
     response <- attr(attr(mf, "terms"), "response")
     y <- mf[,response]
     X <- model.matrix(model, data=mf, contrasts)
     result <- tsls(y, X, Z, colnames(X))
     result$response.name <- response.name
     result$formula <- model
     result$instruments <- instruments
     if (!is.null(na.act))
         result$na.action <- na.act
     class(result) <- "tsls"
     result
     }

Still better, I think, would be to write some utility functions that 
manipulate model formulas more transparently.

Thanks, again, for the help.

John

-----------------------------------------------------
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list