Tuesday, May 6, 2008

frailty/random effects in survreg

library(survival)
rsev <- function(n) log(-log(runif(n)))
x <- rnorm(1000)
v <- rep(1:100, each=10)
q <- rep(rnorm(100, sd=2), each=10)
y <- exp(1.0 + 3.0 * x + q + 5.0 * rsev(1000))
z <- rep(1, 1000)
d <- data.frame(x=x, v=as.factor(v))
f <- survreg(Surv(y, z) ~ x + frailty.gaussian(v), data=d)
f
Call:
survreg(formula = Surv(y, z) ~ x + frailty.gaussian(v), data = d)

coef se(coef) se2 Chisq DF p
(Intercept) 1.20 0.254 0.156 22.3 1.0 2.4e-06
x 2.96 0.166 0.162 319.3 1.0 0.0e+00
frailty.gaussian(v) 176.6 63.2 1.2e-12

Scale= 4.7

Iterations: 7 outer, 23 Newton-Raphson
Variance of random effect= 4
Degrees of freedom for terms= 0.4 1.0 63.2 1.0
Likelihood ratio test=463 on 63.5 df, p=0 n= 1000

No comments: