javier palacios
2011-Aug-19 12:55 UTC
[R] AFT model time-dependent with weibull distribution
Dear R-community, I have tried to estimate an accelerated failure time(AFT) and proportional hazard (PH) parametric survival model with time-independent and time-dependent covariates. For that purpose, I have used the eha package. Please, consider this example: weibullph <- phreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", data.frame=Data) weibullaft<-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", data.frame=Data) ## aftreg gives error when I add ID argument... Error in aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, : Overlapping intervals for id 2>From help(aftreg): id If there are more than one spell per individual, it isessential to keep spells together by the id argument. This allows for time-varying covariates. data table: Data S sta time TDC1 total_time TIC1 ID A 1 0 1 48.50 1 1 1 B 0 0 1 65.96 2 1 2 B 1 1 2 65.08 2 1 2 C 0 0 1 0.00 2 4 3 C 1 1 2 0.00 2 4 3 D 0 0 1 72.74 2 5 4 D 1 1 2 72.52 2 5 4 E 0 0 1 61.84 2 3 5 E 0 1 2 60.56 2 3 5 F 0 0 1 35.04 4 2 6 F 0 1 2 36.97 4 2 6 F 0 2 3 37.92 4 2 6 F 1 3 4 39.01 4 2 6 time - time to event sta - starting time TDC - time dependent covariates TIC - time independent covariate total_time - total time at risk ID - ID 1- What happens if the ID is not included? 2- How can I solve this error? 3- Why the phreg function does not need an ID? Thanks, Javier -- View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3755079.html Sent from the R help mailing list archive at Nabble.com.
Göran Broström
2011-Aug-19 21:42 UTC
[R] AFT model time-dependent with weibull distribution
On Fri, Aug 19, 2011 at 2:55 PM, javier palacios <xpfenech at gmail.com> wrote:> Dear R-community, > > I have tried to estimate an accelerated failure time(AFT) and proportional > hazard (PH) parametric survival model with time-independent ?and > time-dependent covariates. For that purpose, I have used the eha package. > > > Please, consider this example: > > weibullph <- phreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", > data.frame=Data) > > weibullaft<-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", > data.frame=Data) > > ## aftreg gives error when I add ID argument... > > Error in aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, ?: > ?Overlapping intervals for id ?2Does not happen to me.> > >From help(aftreg): id If there are more than one spell per individual, it is > essential to keep spells together by the id argument. This allows for > time-varying covariates. > > > data table: > > Data > ? S sta time ?TDC1 total_time TIC1 ? ? ? ? ?ID > A 1 ? 0 ? 1 ?48.50 ? ? ? 1 ? ? ? ? ? ? ?1 ? ? ? ? ? 1 > B 0 ? 0 ? 1 ?65.96 ? ? ? 2 ? ? ? ? ? ? ? 1 ? ? ? ? ? 2 > B 1 ? 1 ? 2 ?65.08 ? ? ? 2 ? ? ? ? ? ? ?1 ? ? ? ? ? ?2 > C 0 ? 0 ? 1 ?0.00 ? ? ? ?2 ? ? ? ? ? ? ? 4 ? ? ? ? ? 3 > C 1 ? 1 ? 2 ?0.00 ? ? ? ?2 ? ? ? ? ? ? ? 4 ? ? ? ? ? 3 > D 0 ? 0 ? 1 72.74 ? ? ? ?2 ? ? ? ? ? ? ? 5 ? ? ? ? ? 4 > D 1 ? 1 ? 2 72.52 ? ? ? ?2 ? ? ? ? ? ? ? 5 ? ? ? ? ? 4 > E 0 ? 0 ? 1 61.84 ? ? ? ? 2 ? ? ? ? ? ? ?3 ? ? ? ? ? ?5 > E 0 ? 1 ? 2 60.56 ? ? ? ?2 ? ? ? ? ? ? ? 3 ? ? ? ? ? ?5 > F 0 ? 0 ? 1 35.04 ? ? ? ?4 ? ? ? ? ? ? ? 2 ? ? ? ? ? ?6 > F 0 ? 1 ? 2 36.97 ? ? ? ?4 ? ? ? ? ? ? ? 2 ? ? ? ? ? ?6 > F 0 ? 2 ? 3 37.92 ? ? ? ?4 ? ? ? ? ? ? ? 2 ? ? ? ? ? ?6 > F 1 ? 3 ? 4 39.01 ? ? ? ?4 ? ? ? ? ? ? ? 2 ? ? ? ? ? ?6Duplicated rownames are no allowed.> > time - time to event > sta - starting time > TDC - time dependent covariates > TIC - time independent covariate > total_time - total time at risk > ID - ID > > 1- What happens if the ID is not included?Read the documentation> 2- How can I solve this error?Read the documentation> 3- Why the phreg function does not need an ID?Read the documentation (and a good text book on survival analysis) And please read the posting guide; the elementary information is missing.> > Thanks, > > Javier > > > -- > View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3755079.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- G?ran Brostr?m
Dear Prof. Brostr?m, I have searched in the reference manual inside the package eha, updated recently. I did not find any description on how to enter id in the aftreg function except the description of the argument. Can you refer to a specific part of the manual? Do you mean another documentation? I had also visited the posting guide before ( I included an example and all the details I could.). What else can I add? And have also read a a book intruducing survival analysis in R, but the doubt that I have is very specific to R computation. I reask the questions: I have a doubt on how to perform a weibull parametric survival anayisis using time-dependent covariates in R using both accelerated failure time(AFT) and proportional hazard (PH). I would highly appreciate a reply to my questions. I provide an example similar to data i use. (Here there are only two covariates one dependent and another independent) Data S sta time TDC1 total_time TIC1 ID A 1 0 1 48.50 1 1 1 B 0 0 1 65.96 2 1 2 B 1 1 2 65.08 2 1 2 C 0 0 1 0.00 2 4 3 C 1 1 2 0.00 2 4 3 D 0 0 1 72.74 2 5 4 D 1 1 2 72.52 2 5 4 E 0 0 1 61.84 2 3 5 E 0 1 2 60.56 2 3 5 F 0 0 1 35.04 4 2 6 F 0 1 2 36.97 4 2 6 F 0 2 3 37.92 4 2 6 F 1 3 4 39.01 4 2 6 time - time to event sta - starting time TDC - time dependent covariates TIC - time independent covariate total_time - total time at risk ID - ID Doubts: -AFT and PH time-dependent Weibull distribution I have tried to estimate an accelerated failure time(AFT) and proportional hazard (PH) parametric survival model with time-independent and time-dependent covariates with a weibull distribution. For that purpose, I have used the eha package. To my knowledge, the survival package does not provide a solution for estimating models with time-dependent models. weibullph <- phreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", data.frame=Data) weibullaft<-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", data.frame=Data) ## aftreg gives an error when I add an ID argument... That should be used for controlling for time-varying variables. Error in aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, : *Overlapping intervals for id 2 *>From help(aftreg): id If there are more than one spell per individual, it isessential to keep spells together by the id argument. This allows for time-varying covariates. Here are the questions I have: 1- How can I solve this error? 2- Does the phreg function need an ID? Can I use it to estimate a model with time-dependent covariates? 3- How can time-dependent covariates be estimated with phreg or aftreg, or other function in R? Thank you very much, J -- View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3756424.html Sent from the R help mailing list archive at Nabble.com.
JPF wrote:> > > > weibullaft<-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", > data.frame=Data) > > ## aftreg gives an error when I add an ID argument... That should be used > for controlling for time-varying variables. > > Error in aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, > : > *Overlapping intervals for id 2 * > > From help(aftreg): id If there are more than one spell per individual, it > is essential to keep spells together by the id argument. This allows for > time-varying covariates. > >This is solved. It gave the overlapping intervals error, but now it is solved: /id=ID/, just as before. -- View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3756502.html Sent from the R help mailing list archive at Nabble.com.
Göran Broström
2011-Aug-20 15:31 UTC
[R] AFT model time-dependent with weibull distribution
On Sat, Aug 20, 2011 at 4:19 AM, JPF <xpfenech at gmail.com> wrote:> > JPF wrote: >> >> >> >> weibullaft<-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1, dist="weibull", >> data.frame=Data) >> >> ## aftreg gives an error when I add an ID argument... That should be used >> for controlling for time-varying variables. >> >> Error in aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, >> : >> ? *Overlapping intervals for id ?2 * >> >> From help(aftreg): id If there are more than one spell per individual, it >> is essential to keep spells together by the id argument. This allows for >> time-varying covariates. >> >> > > This is solved. It gave the overlapping intervals error, but now it is > solved: /id=ID/, just as before. >Good. Do you still need answers to your other questions? G.> -- > View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3756502.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- G?ran Brostr?m
G?ran Brostr?m wrote:> > > Good. Do you still need answers to your other questions? > >Yes. Could answer the following two questions: 1- Can I use phreg function to estimate a model with time-dependent covariates? In case of a positive answer, how? 2- I could not find any example that clearly explains how to interpret aftreg output. Specially, refering to the diference between survreg and aftreg output (intercept and sign of the estimates). I include below an example of output of a regression with coxph, survreg, phreg and aftreg and a time-independent variable. I would appreciate if you could explain it or provide an external example that explains how it works. n=26 events=25 time at risk=45 a/ coxph(Surv(time,s) ~ Z1, data=data.frame(data)) coef exp(coef) se(coef) z p Z1 0.0249 1.03 0.00907 2.75 0.006 b/ phreg(Surv(time,s) ~ Z1, data=data.frame(data), dist="weibull") Covariate W.mean Coef Exp(Coef) se(Coef) Wald p Z1 43.689 0.033 1.033 0.009 0.000 log(scale) 0.641 1.899 0.065 0.000 log(shape) 1.172 3.230 0.158 0.000 Max. log. likelihood -22.135 LR test statistic 13.1 Degrees of freedom 1 Overall p-value 0.000302689 c/ aftreg(Surv(time,s) ~ Z1, data=data.frame(data), dist="weibull") Covariate W.mean Coef Exp(Coef) se(Coef) Wald p mas 43.689 0.010 1.010 0.002 0.000 log(scale) 1.147 3.149 0.141 0.000 log(shape) 1.172 3.230 0.158 0.000 Max. log. likelihood -22.135 LR test statistic 13.1 Degrees of freedom 1 Overall p-value 0.000302692 d/ survreg(Surv(time,s) ~ Z1, data=data.frame(data), dist="weibull") Value Std. Error z p (Intercept) 1.1476 0.13498 8.50 1.87e-17 mas -0.0101 0.00232 -4.34 1.45e-05 Log(scale) -1.1724 0.15787 -7.43 1.11e-13 Scale= 0.310 Weibull distribution Loglik(model)= -22.1 Loglik(intercept only)= -28.7 Chisq= 13.05 on 1 degrees of freedom, p= 3e-04 Number of Newton-Raphson Iterations: 5 Thank you very much, J -- View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3757387.html Sent from the R help mailing list archive at Nabble.com.
question 2 *aftreg vs. survreg* for aftreg = S0 *{t/exp(b-BXi)]^a} a= shape and b= log(scale) for survreg and stata S0 *{t*exp(intercept+BXi)]^1/p} p=shape /intercept, log(scale) and estimates are equivalent with reversed sign./ *PH and AFT* /phreg.Bhat= aftreg.Bhat * shape / -- View this message in context: r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3757871.html Sent from the R help mailing list archive at Nabble.com.