Re: [R] Time dependent Cox model
... interactions between covariables and time. A model such as coxph(Surv(ptime, pstat) ~ age + age*ptime, is invalid -- it is not at all what you think. If cph flags this as an error that is a good thing: I should probably add the same message to coxph. Is is somewhat sensible to use cox.zph() to investigate which variables need time interaction... The cox.zph function is primarily graphical; I would respond to your question with is it good to look at scatterplots before fitting a linear model? My answer to this is emphatically yes. Terry Therneau __ 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.
Re: [R] Time dependent Cox model
... interactions between covariables and time. A model such as coxph(Surv(ptime, pstat) ~ age + age*ptime, is invalid -- it is not at all what you think. Actually what i'm trying to fit is coxph(Surv(start,end,event)~age+age:start) to model a time-varying effect \beta(t)=a+b*t. Conceptually, is not H_0:b=0 the hypothesis tested by cox.zph()? (i know: i have to study more deeply this topic, my copy of your book is on the way to my house) Is is somewhat sensible to use cox.zph() to investigate which variables need time interaction... The cox.zph function is primarily graphical; I would respond to your question with is it good to look at scatterplots before fitting a linear model? My answer to this is emphatically yes. Terry Therneau Thank you, Marco Barbàra. __ 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.
Re: [R] Time Dependent Cox Model
Does anyone have suggestions? Thanks! quaildoc wrote: I am having trouble formatting some survival data to use in a time dependent cox model. My time dep. variable is habitat and I have it recorded for every day (with some NAs). I think it is working properly except for calculating the death.time. This column should be 1s or 0s and as I have it only produces 0s. Any help will be greatly appreciated. http://www.nabble.com/file/p25881478/Survival_master2.csv Survival_master2.csv Here is my code: sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 726 days if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous day) stop - start + 1 # stop time (day) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25893488.html Sent from the R help mailing list archive at Nabble.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.
Re: [R] Time Dependent Cox Model
Well, it might be wise to elaborate a bit more about the variables and what exactly you want e.g. death-time to be. I'd interprete it as time of death, but the fact that it is 0/1, means it is a logical (?) binary variable of some sort. Please ask your question in such a way that somebody who doesn't know the dataset and your research, can still understand what is inside the dataset and what exactly you're trying to obtain. I'd also suggest to add the command to read in the data. I don't have the time to spend looking around how exactly I can read in the dataset in such a way it fits what you have in your workspace. Cheers Joris On Wed, Oct 14, 2009 at 5:37 PM, quaildoc just.strut...@gmail.com wrote: Does anyone have suggestions? Thanks! quaildoc wrote: I am having trouble formatting some survival data to use in a time dependent cox model. My time dep. variable is habitat and I have it recorded for every day (with some NAs). I think it is working properly except for calculating the death.time. This column should be 1s or 0s and as I have it only produces 0s. Any help will be greatly appreciated. http://www.nabble.com/file/p25881478/Survival_master2.csv Survival_master2.csv Here is my code: sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 726 days if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous day) stop - start + 1 # stop time (day) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25893488.html Sent from the R help mailing list archive at Nabble.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. __ 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.
Re: [R] Time Dependent Cox Model
Some suggested that go into more detail on what I wanted to accomplish and the rest of my code. I want to accomplish exactly what Fox did in this article( http://www.nabble.com/file/p25897307/appendix-cox-regression.pdf appendix-cox-regression.pdf ) (starting with page 7), except using habitat instead of employment. I want habitat to be a time dep. covariate and it varys by day. I read in my data as the csv. file, and one major difference in the data set Fox used and min is I have a DaysatRisk column instead of the week the person went back to jail. This I think is the root of my problem calculating the proper death.time. The death.time column should be 1s and 0s that corresponds to the day the animal died. Thanks in advance, surv-read.csv(Survival_master2.csv, header = TRUE) sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 52 weeks if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous week) stop - start + 1 # stop time (current week) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) remove(i,j,row,start,stop,death.time) surv2[1:15,] test-coxph(Surv(start,stop,death.time)~habitat, data=surv2) JorisMeys wrote: Well, it might be wise to elaborate a bit more about the variables and what exactly you want e.g. death-time to be. I'd interprete it as time of death, but the fact that it is 0/1, means it is a logical (?) binary variable of some sort. Please ask your question in such a way that somebody who doesn't know the dataset and your research, can still understand what is inside the dataset and what exactly you're trying to obtain. I'd also suggest to add the command to read in the data. I don't have the time to spend looking around how exactly I can read in the dataset in such a way it fits what you have in your workspace. Cheers Joris On Wed, Oct 14, 2009 at 5:37 PM, quaildoc just.strut...@gmail.com wrote: Does anyone have suggestions? Thanks! quaildoc wrote: I am having trouble formatting some survival data to use in a time dependent cox model. My time dep. variable is habitat and I have it recorded for every day (with some NAs). I think it is working properly except for calculating the death.time. This column should be 1s or 0s and as I have it only produces 0s. Any help will be greatly appreciated. http://www.nabble.com/file/p25881478/Survival_master2.csv Survival_master2.csv Here is my code: sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 726 days if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous day) stop - start + 1 # stop time (day) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25893488.html Sent from the R help mailing list archive at Nabble.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. __ 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. -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25897307.html Sent from the R help mailing list archive at Nabble.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.
Re: [R] Time Dependent Cox Model
On Wed, Oct 14, 2009 at 9:19 PM, quaildoc just.strut...@gmail.com wrote: Some suggested that go into more detail on what I wanted to accomplish and the rest of my code. I want to accomplish exactly what Fox did in this article( http://www.nabble.com/file/p25897307/appendix-cox-regression.pdf appendix-cox-regression.pdf ) (starting with page 7), except using habitat instead of employment. I want habitat to be a time dep. covariate and it varys by day. I read in my data as the csv. file, and one major difference in the data set Fox used and min is I have a DaysatRisk column instead of the week the person went back to jail. This I think is the root of my problem calculating the proper death.time. The death.time column should be 1s and 0s that corresponds to the day the animal died. Thanks in advance, surv-read.csv(Survival_master2.csv, header = TRUE) sum(!is.na(surv[,16:726])) I added a bit in your code : stoptest -c() # seeing what comes out of the test onetest -c() # seeing what comes out of the test surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 52 weeks if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous week) This is the first thing I don't understand. start can be summarized by a vector 5:715. How this indicates start time, is unclear to me. Same goes for stop time (that's a vector 6:716). stop - start + 1 # stop time (current week) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 I modified your code here too : stoptest - c(stoptest,stop==surv[i,4]) onetest - c(onetest,surv[i,5]==1) # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } I ran until here. Now this came out : sum(stoptest) [1] 0 sum(onetest) [1] 0 How comes? Both are factors without a numeric value, so the tests you do make no sense. You check if a factor is equal to a certain number, and that's neither for the first condition, nor for the second condition ever the case. That's why you get all zeros. What you need to do, if figure out what exactly is in the variables week and arrest of the dataset Rossi, and adapt your data frame accordingly. Cheers Joris JorisMeys wrote: Well, it might be wise to elaborate a bit more about the variables and what exactly you want e.g. death-time to be. I'd interprete it as time of death, but the fact that it is 0/1, means it is a logical (?) binary variable of some sort. Please ask your question in such a way that somebody who doesn't know the dataset and your research, can still understand what is inside the dataset and what exactly you're trying to obtain. I'd also suggest to add the command to read in the data. I don't have the time to spend looking around how exactly I can read in the dataset in such a way it fits what you have in your workspace. Cheers Joris On Wed, Oct 14, 2009 at 5:37 PM, quaildoc just.strut...@gmail.com wrote: Does anyone have suggestions? Thanks! quaildoc wrote: I am having trouble formatting some survival data to use in a time dependent cox model. My time dep. variable is habitat and I have it recorded for every day (with some NAs). I think it is working properly except for calculating the death.time. This column should be 1s or 0s and as I have it only produces 0s. Any help will be greatly appreciated. http://www.nabble.com/file/p25881478/Survival_master2.csv Survival_master2.csv Here is my code: sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 726 days if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous day) stop - start + 1 # stop time (day) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25893488.html Sent from the R help mailing list archive at Nabble.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
[R] Time Dependent Cox Model
I am having trouble formatting some survival data to use in a time dependent cox model. My time dep. variable is habitat and I have it recorded for every day (with some NAs). I think it is working properly except for calculating the death.time. This column should be 1s or 0s and as I have it only produces 0s. Any help will be greatly appreciated. http://www.nabble.com/file/p25881478/Survival_master2.csv Survival_master2.csv Here is my code: sum(!is.na(surv[,16:726])) surv2-matrix(0,12329,19) colnames(surv2)-c('start', 'stop', 'death.time', names(surv)[1:15],'habitat') row-0 # set record counter to 0 for (i in 1:nrow(surv)) { # loop over individuals for (j in 16:726) { # loop over 726 days if (is.na(surv[i, j])) next # skip missing data else { row - row + 1 # increment row counter start - j - 11 # start time (previous day) stop - start + 1 # stop time (day) death.time - if (stop == surv[i, 4] surv[i, 5] ==1) 1 else 0 # construct record: surv2[row,] - c(start, stop, death.time, unlist(surv[i, c(1:15, j)])) } } } surv2-as.data.frame(surv2) -- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25881478.html Sent from the R help mailing list archive at Nabble.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.