Jennifer Wu, Miss
2016-Mar-29 20:47 UTC
[R] Convergence issues when using ns splines (pkg: spline) in Cox model (coxph) even when changing coxph.control
Hi, I am currently using R v3.2.3 and on Windows 10 OS 64Bit. I am having convergence issues when I use coxph with a interaction term (glarg*bca_py) and interaction term with the restricted cubic spline (glarg*bca_time_ns). I use survival and spline package to create the Cox model and cubic splines respectively. Without the interaction term and/or spline, I have no convergence problem. I read some forums about changing the iterations and I have but it did not work. I was just wondering if I am using the inter.max and outer.max appropriately. I read the survival manual, other R-help and stackoverflow pages and it suggested changing the iterations but it doesn't specify what is the max I can go. I ran something similar in SAS and did not run into a convergence problem. This is my code: bca_time_ns <- ns(ins_ca$bca_py, knots=3, Boundary.knots=range(2,5,10)) test <- ins_ca$glarg*ins_ca$bca_py test1 <- ins_ca$glarg*bca_time_ns coxit <- coxph.control(iter.max=10000, outer.max=10000) bca<-coxph(Surv(bca_py,bca) ~ glarg + test + test1 + age + calyr + diab_dur + hba1c + adm_met + adm_sulfo + adm_tzd + adm_oth + med_statin + med_aspirin + med_nsaids + bmi_cat + ccscat + alc + smk, data=ins_ca, control=coxit, ties=c("breslow")) This is the error message I get: Warning message: In fitter(X, Y, strats, offset, init, control, weights = weights, : Ran out of iterations and did not converge [[alternative HTML version deleted]]
Göran Broström
2016-Mar-30 09:40 UTC
[R] Convergence issues when using ns splines (pkg: spline) in Cox model (coxph) even when changing coxph.control
Hi Jennifer, see below. On 2016-03-29 22:47, Jennifer Wu, Miss wrote:> Hi, > > I am currently using R v3.2.3 and on Windows 10 OS 64Bit. > > I am having convergence issues when I use coxph with a interaction > term (glarg*bca_py) and interaction term with the restricted cubic > spline (glarg*bca_time_ns).Comment on interactions: (i) You should not create interaction terms 'manually' but rather in the formula in the call to coxph ('*' means different things in a formula and on the command line). That assures that you get the main effects included. In your formula, you are missing the main effects 'bca_py' and 'bca_time_ns'. Is that intentional? In a few exceptional cases it may make sense to drop a main affect, but generally not. (ii) Convergence problems may also occur with interactions of variables that are not centered, so try to center involved covariates. Your 'coxph.control' values have nothing to do with your convergence problem. And try to provide reproducible code, in your case, the data set. If it is not possible, maybe you can scale it down to include only the problematic variables (with some fake values, if necessary) and just a few cases, but enough to show your problem. G?ran Brostr?m > I use survival and spline package to> create the Cox model and cubic splines respectively. Without the > interaction term and/or spline, I have no convergence problem. I read > some forums about changing the iterations and I have but it did not > work. I was just wondering if I am using the inter.max and outer.max > appropriately. I read the survival manual, other R-help and > stackoverflow pages and it suggested changing the iterations but it > doesn't specify what is the max I can go. I ran something similar in > SAS and did not run into a convergence problem. > > This is my code: > > bca_time_ns <- ns(ins_ca$bca_py, knots=3, > Boundary.knots=range(2,5,10)) test <- ins_ca$glarg*ins_ca$bca_py > test1 <- ins_ca$glarg*bca_time_ns > > coxit <- coxph.control(iter.max=10000, outer.max=10000) > > bca<-coxph(Surv(bca_py,bca) ~ glarg + test + test1 + age + calyr + > diab_dur + hba1c + adm_met + adm_sulfo + adm_tzd + adm_oth + > med_statin + med_aspirin + med_nsaids + bmi_cat + ccscat + alc + smk, > data=ins_ca, control=coxit, ties=c("breslow")) > > > This is the error message I get: > > Warning message: In fitter(X, Y, strats, offset, init, control, > weights = weights, : Ran out of iterations and did not converge > > > > [[alternative HTML version deleted]] > > ______________________________________________ R-help at 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. >
David Winsemius
2016-Mar-30 21:06 UTC
[R] Convergence issues when using ns splines (pkg: spline) in Cox model (coxph) even when changing coxph.control
> On Mar 29, 2016, at 1:47 PM, Jennifer Wu, Miss <jennifer.wu2 at mail.mcgill.ca> wrote: > > Hi, > > I am currently using R v3.2.3 and on Windows 10 OS 64Bit. > > I am having convergence issues when I use coxph with a interaction term (glarg*bca_py) and interaction term with the restricted cubic spline (glarg*bca_time_ns). I use survival and spline package to create the Cox model and cubic splines respectively. Without the interaction term and/or spline, I have no convergence problem. I read some forums about changing the iterations and I have but it did not work. I was just wondering if I am using the inter.max and outer.max appropriately. I read the survival manual, other R-help and stackoverflow pages and it suggested changing the iterations but it doesn't specify what is the max I can go. I ran something similar in SAS and did not run into a convergence problem. > > This is my code: > > bca_time_ns <- ns(ins_ca$bca_py, knots=3, Boundary.knots=range(2,5,10)) > test <- ins_ca$glarg*ins_ca$bca_py > test1 <- ins_ca$glarg*bca_time_nsIn your `coxph` call the variable 'bca_py' is the survival time and yet here you are constructing not just one but two interactions (one of which is a vector but the other one a matrix) between 'glarg' and your survival times. Is this some sort of effort to identify a violation of proportionality over the course of a study? Brostr?m sagely points out that these interactions are not in the data-object and subsequent efforts to refer to them may be confounded by the multiple environments from which data would be coming into the model. Better to have everything come in from the data-object. The fact that SAS did not have a problem with this rather self-referential or circular model may be a poor reflection on SAS rather than on the survival package. Unlike Therneau or Brostr?m who asked for data, I suggest the problem lies with the model construction and you should be reading what Therneau has written about identification of non-proportionality and identification of time dependence of effects. See Chapter 6 of his "Modeling Survival Data". -- David Winsemius Alameda, CA, USA> > coxit <- coxph.control(iter.max=10000, outer.max=10000) > > bca<-coxph(Surv(bca_py,bca) ~ glarg + test + test1 + age + calyr + diab_dur + hba1c + adm_met + adm_sulfo + adm_tzd + adm_oth + > med_statin + med_aspirin + med_nsaids + bmi_cat + ccscat + alc + smk, data=ins_ca, control=coxit, ties=c("breslow")) > > > This is the error message I get: > > Warning message: > In fitter(X, Y, strats, offset, init, control, weights = weights, : > Ran out of iterations and did not converge > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Göran Broström
2016-Mar-30 22:28 UTC
[R] Convergence issues when using ns splines (pkg: spline) in Cox model (coxph) even when changing coxph.control
On 2016-03-30 23:06, David Winsemius wrote:> >> On Mar 29, 2016, at 1:47 PM, Jennifer Wu, Miss >> <jennifer.wu2 at mail.mcgill.ca> wrote: >> >> Hi, >> >> I am currently using R v3.2.3 and on Windows 10 OS 64Bit. >> >> I am having convergence issues when I use coxph with a interaction >> term (glarg*bca_py) and interaction term with the restricted cubic >> spline (glarg*bca_time_ns). I use survival and spline package to >> create the Cox model and cubic splines respectively. Without the >> interaction term and/or spline, I have no convergence problem. I >> read some forums about changing the iterations and I have but it >> did not work. I was just wondering if I am using the inter.max and >> outer.max appropriately. I read the survival manual, other R-help >> and stackoverflow pages and it suggested changing the iterations >> but it doesn't specify what is the max I can go. I ran something >> similar in SAS and did not run into a convergence problem. >> >> This is my code: >> >> bca_time_ns <- ns(ins_ca$bca_py, knots=3, >> Boundary.knots=range(2,5,10)) test <- ins_ca$glarg*ins_ca$bca_py >> test1 <- ins_ca$glarg*bca_time_ns > > In your `coxph` call the variable 'bca_py' is the survival time andRight David: I didn't notice that the 'missing main effect' in fact was part of the survival object! And as you say: Time to rethink the whole model. G?ran> yet here you are constructing not just one but two interactions (one > of which is a vector but the other one a matrix) between 'glarg' and > your survival times. Is this some sort of effort to identify a > violation of proportionality over the course of a study? > > Brostr?m sagely points out that these interactions are not in the > data-object and subsequent efforts to refer to them may be confounded > by the multiple environments from which data would be coming into the > model. Better to have everything come in from the data-object. > > The fact that SAS did not have a problem with this rather > self-referential or circular model may be a poor reflection on SAS > rather than on the survival package. Unlike Therneau or Brostr?m who > asked for data, I suggest the problem lies with the model > construction and you should be reading what Therneau has written > about identification of non-proportionality and identification of > time dependence of effects. See Chapter 6 of his "Modeling Survival > Data". >