[R] Logistic/Cox regression: Parameter estimates directly from model matrix

Kaspar Rufibach kaspar.rufibach at stanford.edu
Fri Apr 6 00:47:28 CEST 2007


Hi out there

Is there a way to get the estimated coefficients in a logistic / Cox
regression without having to specify a 'formula' but by only giving the
model matrix?

Example for Cox regression:

## predictors
n <- 50
q1 <- rnorm(n)
q2 <- rgamma(n, 2, 2)
Z <- cbind(q1, q2)

## response
ttf <- rexp(n)
tf <- round(runif(n))

## compute estimates
res <- coxph(Surv(ttf, tf) ~ q1 + q2)
r <- res$coef

My goal is to have a function

estFromModelMatrix <- function(tf, ttf, Z){

      /* do something meaningful using built-in functions */

      return(r)}

I have written such functions myself using LL - maximization from
scratch, but these are slower than the built-in functions. Since I
intend to do some simulations (where I specify the model matrix, but not
want to give a 'formula' manually for each simulation scenario), it
would be nice to have a function estFromModelMatrix().

I searched the help extensively, but did not find a way to do this.

Hope I was clear enough, any help is appreciated!
Kaspar Rufibach


-- 
______________________________________
Kaspar Rufibach
Department of Statistics -- Sequoia Hall
390 Serra Mall
Stanford University
Stanford, CA 94305-4065

mailto:kaspar.rufibach at stanford.edu
skype:kasparrufibach
http://www.stanford.edu/~kasparr



More information about the R-help mailing list