survival-analysis

Create a ggplot2 survival curve with censored table

我怕爱的太早我们不能终老 提交于 2019-12-02 11:24:41
I am trying to create a Kaplan-Meier plot with 95% confidence bands plus having the censored data in a table beneath it. I can create the plot, but not the table. I get the error message: Error in grid.draw(both) : object 'both' not found. library(survival) library(ggplot2) library(GGally) library(gtable) data(lung) sf.sex <- survfit(Surv(time, status) ~ sex, data = lung) pl.sex <- ggsurv(sf.sex) + geom_ribbon(aes(ymin=low,ymax=up,fill=group),alpha=0.3) + guides(fill=guide_legend("sex")) pl.sex tbl <- ggplot(df_nums, aes(x = Time, y = factor(variable), colour = variable,+ label=value)) + geom

Coxph predictions don't match the coefficients

社会主义新天地 提交于 2019-12-02 08:03:34
问题 Good afternoon, I could post reproducible code and certainly will if everyone agrees that something is wrong, but right now I think my question is quite simple and someone will point me the right path. I am working in a data set like this: created_as_free_user t c <fctr> <int> <int> 1 true 36 0 2 true 36 0 3 true 0 1 4 true 28 0 5 true 9 0 6 true 0 1 7 true 13 0 8 true 19 0 9 true 9 0 10 true 16 0 I fitted a Cox Regression model like this: fit_train = coxph(Surv(time = t,event = c) ~ created

Coxph predictions don't match the coefficients

早过忘川 提交于 2019-12-02 04:04:12
Good afternoon, I could post reproducible code and certainly will if everyone agrees that something is wrong, but right now I think my question is quite simple and someone will point me the right path. I am working in a data set like this: created_as_free_user t c <fctr> <int> <int> 1 true 36 0 2 true 36 0 3 true 0 1 4 true 28 0 5 true 9 0 6 true 0 1 7 true 13 0 8 true 19 0 9 true 9 0 10 true 16 0 I fitted a Cox Regression model like this: fit_train = coxph(Surv(time = t,event = c) ~ created_as_free_user ,data = teste) summary(fit_train) And received: Call: coxph(formula = Surv(time = t, event

can mice() handle crr()? Fine-Gray model

青春壹個敷衍的年華 提交于 2019-12-01 13:32:05
问题 My doubt is if it is possible to pool multiple imputation data set, from "mice()", on a fit model of Fine-Gray from "crr()", and if it is statistically correct... example library(survival) library(mice) library(cmprsk) test1 <- as.data.frame(list(time=c(4,3,1,1,2,2,3,5,2,4,5,1, 4,3,1,1,2,2,3,5,2,4,5,1), status=c(1,1,1,0,2,2,0,0,1,1,2,0, 1,1,1,0,2,2,0,0,1,1,2,0), x=c(0,2,1,1,NA,NA,0,1,1,2,0,1, 0,2,1,1,NA,NA,0,1,1,2,0,1), sex=c(0,0,0,NA,1,1,1,1,NA,1,0,0, 0,0,0,NA,1,1,1,1,NA,1,0,0))) dat <- mice

How to predict survival probabilities in R?

房东的猫 提交于 2019-11-30 22:36:28
I have data called veteran stored in R. I created a survival model and now wish to predict survival probability predictions. For example, what is the probability that a patient with 80 karno value, 10 diagtime , age 65 and prior=10 and trt = 2 lives longer than 100 days? In this case the design matrix is x = (1,0,1,0,80,10,65,10,2) Here is my code: library(survival) attach(veteran) weibull <- survreg(Surv(time,status)~celltype + karno+diagtime+age+prior+trt ,dist="w") and here is the output: Any idea how to predict the survival probabilities? You can get predict.survreg to produce predicted

Gompertz Aging analysis in R

僤鯓⒐⒋嵵緔 提交于 2019-11-30 15:49:07
问题 I have survival data from an experiment in flies which examines rates of aging in various genotypes. The data is available to me in several layouts so the choice of which is up to you, whichever suits the answer best. One dataframe (wide.df) looks like this, where each genotype (Exp, of which there is ~640) has a row, and the days run in sequence horizontally from day 4 to day 98 with counts of new deaths every two days. Exp Day4 Day6 Day8 Day10 Day12 Day14 ... A 0 0 0 2 3 1 ... I make the

Gompertz Aging analysis in R

ε祈祈猫儿з 提交于 2019-11-30 14:52:01
I have survival data from an experiment in flies which examines rates of aging in various genotypes. The data is available to me in several layouts so the choice of which is up to you, whichever suits the answer best. One dataframe (wide.df) looks like this, where each genotype (Exp, of which there is ~640) has a row, and the days run in sequence horizontally from day 4 to day 98 with counts of new deaths every two days. Exp Day4 Day6 Day8 Day10 Day12 Day14 ... A 0 0 0 2 3 1 ... I make the example using this: wide.df2<-data.frame("A",0,0,0,2,3,1,3,4,5,3,4,7,8,2,10,1,2) colnames(wide.df2)<-c(

Survival analysis in PyMC 3

孤者浪人 提交于 2019-11-30 14:15:34
I tried to port simple survival model from here (the first one in introduction) form PyMC 2 to PyMC 3. However, I didn't find any equivalent to "observed" decorator and my attempt to write a new distribution failed. Could someone provide an example how is this done in PyMC 3? This is a tricky port, and requires three new concepts: Use of the theano tensor Use of the DensityDist Passing a dict as observed This code provides the equivalent model as the PyMC2 version you linked to above: import pymc3 as pm from pymc.examples import melanoma_data as data import theano.tensor as t times = data.t #

coxph() X matrix deemed to be singular;

南楼画角 提交于 2019-11-30 11:36:16
I'm having some trouble using coxph(). I've two categorical variables:"tecnologia" and "pais", and I want to evaluate the possible interaction effect of "pais" on "tecnologia"."tecnologia" is a variable factor with 2 levels: gps and convencional. And "pais" as 2 levels: PT and ES. I have no idea why this warning keeps appearing. Here's the code and the output: cox_AC<-coxph(Surv(dados_temp$dias_seg,dados_temp$status)~tecnologia*pais,data=dados_temp) Warning message: In coxph(Surv(dados_temp$dias_seg, dados_temp$status) ~ tecnologia * : X matrix deemed to be singular; variable 3 > cox_AC Call:

Plotting survival curves in R with ggplot2

家住魔仙堡 提交于 2019-11-29 02:11:43
I've been looking for a solution to plot survival curves using ggplot2. I've found some nice examples, but they do not follow the whole ggplot2 aesthetics (mainly regarding shaded confidence intervals and so on). So finally I've written my own function: ggsurvplot<-function(s, conf.int=T, events=T, shape="|", xlab="Time", ylab="Survival probability", zeroy=F, col=T, linetype=F){ #s: a survfit object. #conf.int: TRUE or FALSE to plot confidence intervals. #events: TRUE or FALSE to draw points when censoring events occur #shape: the shape of these points #zeroy: Force the y axis to reach 0 #col: