[R] limited formula length in tsls
Zsombor Cseres-Gergely
uctpzcs at ucl.ac.uk
Wed Aug 22 19:25:08 CEST 2001
Dear all,
Using the tsls package, I noticed that regression lists longer
than 64 character
are getting truncated. Looking at the original source,
tsls.formula <- function(model, instruments, data, subset, weights,
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)
m$formula <- model
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, contrasts)
response <- attr(attr(mf, "terms"), "response")
y <- model.response(mf)
X <- model.matrix(model, mf, contrasts)
w <- model.weights(mf)
if (missing(weights)) result <- tsls(y, X, Z, colnames(X))
else result <- tsls.weighted(y, X, Z, w, colnames(X))
result$formula <- model
result$instruments <- instruments
if (!is.null(na.act))
result$na.action <- na.act
class(result) <- "tsls"
result
}
I thought that the problem here is to handle the instruments correctly and
being consistent with the convention (?) regarding the single model object
inside the function. Since I could not figure out, why the truncation occurs
(I tried as.character() and paste() in interactive mode, but nothing bad
happened), I modified the source ad follows:
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)
c1 <- as.character(model)
c2 <- as.character(instruments)
formula <- as.formula(paste(c1[2],c1[1],c1[3], '+', c2[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 <- c1[2]
result$formula <- model
result$instruments <- instruments
if (!is.null(na.act))
result$na.action <- na.act
class(result) <- "tsls"
result
}
It works, but I feel that there is something wrong with it (although
it works fine so far). What?
Thank you,
Zsombor Cseres-Gergely
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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