dear Frank,

update() does not update actually.. It just builds a new call which is evaluated. To speed up the procedure you could try to supply starting values via argument 'init'. The first values come from the previous fit, and the last one referring to new coefficients is set to zero (or any other appropriate value).

Something like (untested), for instance

update(Cox[[2]], . ~ . + cos(3 * v), init=c(coef(Cox[[1]]),0), data =  pbc)

Hope this helps,
best,
vito



"Frank S." <f_j_...@hotmail.com> ha scritto:

Hello everybody, I come with a question which I do not know how to conduct in an efficient way. In order to provide a toy example, consider the dataset "pbc" from the package "survival". First, I fit the Cox model "Cox0":

library("survival")
set.seed(1)
v <- runif(nrow(pbc), min = 0, max = 2)
Cox0 <- coxph(Surv(pbc$time,pbc$status == 2) ~ v, data =  pbc)

Then, from the above model, I can fit recursively 10 additional models as:

Cox <- list()

Cox[[1]] <- update(Cox0, . ~ . + cos(1 * v), data =  pbc)
Cox[[2]] <- update(Cox[[1]], . ~ . + cos(2 * v), data =  pbc)
Cox[[3]] <- update(Cox[[2]], . ~ . + cos(3 * v), data =  pbc)
Cox[[4]] <- update(Cox[[3]], . ~ . + cos(4 * v), data =  pbc)
...
Cox[[10]] <- update(Cox[[9]], . ~ . + cos(10* v), data =  pbc)

Since in practice I have to repeat above step until Cox[[100]], say, do you know an efficient way to
wrap this code chunk in a loop or similar?

I had tried:

set.seed(1)
v <- runif(nrow(pbc), min = 0, max = 2)
Cox0 <- coxph(Surv(pbc$time,pbc$status == 2) ~ v, data =  pbc)

Cox <- list()
Cox[[1]] <- update(Cox0, . ~ . + cos(1 * v), data =  pbc)
for (k in 1:10) {
  Cox[[k + 1]] <- update(Cox[[k]], . ~ . + cos((k + 1) * v), data =  pbc)
}

However, from Cox[[3]] onwards, the intermediate values of integer k are not included here (for instance, the model Cox[[10]] would only include the cosinus terms for cos(1*v) and cos(10*v)).

Thanks in advance for any help!

Frank

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to