Kaspar Rufibach
2007-Apr-05 22:47 UTC
[R] Logistic/Cox regression: Parameter estimates directly from model matrix
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
Göran Broström
2007-Apr-06 07:47 UTC
[R] Logistic/Cox regression: Parameter estimates directly from model matrix
On 4/6/07, Kaspar Rufibach <kaspar.rufibach at stanford.edu> wrote:> 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?See 'coxreg.fit' in package 'eha'. Or 'glm.fit' for logistic regression. hth, G?ran> > 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- G?ran Brostr?m