Hi Grace, I seem to have sent an empty draft before. Anyway, something like this might be an approach (untested):
require(rms) set.seed(10) dat <- data.frame( age = rnorm(500, 40, 10), race = factor(sample.int(2,500,TRUE), labels = c("a", "b"))) X <- model.matrix(~ age + race, data = dat) b <- c(-2, .1, 3) rates <- exp(X %*% b) # distribution of survival time dat$survtime <- 100 * rexp(500, rate = rates) # indicator for censored/observed dat$cens <- dat$survtime > 10 # new survival time values with censored dat$survtime <- pmin(dat$survtime, 10) test <- survreg(Surv(survtime, cens) ~ age + race, data = dat) summary(test) Cheers, Josh On Thu, May 10, 2012 at 7:41 PM, Grace Ma <grace.yanfe...@gmail.com> wrote: > Hi, > I am trying to simulate a regression on survival data under a few > conditions: > 1. Under different error distributions > 2. Have the error term be dependent on the covariates > > But I'm not sure how to specify either conditions. I am using the Design > package to perform the survival analysis using the survreg, bj, coxph > functions. Any help is greatly appreciated. > > This is what I have so far: > survtime <- 10*rexp(500) #distribution of survival time > cens <- ifelse(survtime > 10, 0, 1) #indicator for censored/observed > survtime <- pmin(survtime, 10) #new survival time values with censored > info > age <- rnorm(200, 40, 10) #age variable > race <- factor(sample(c('a','b'),500,TRUE)) #categorical variable > test <- bj(Surv(survtime, cens) ~ rcs(age,5) + race) > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ ______________________________________________ R-help@r-project.org 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.