function - Gompertz Aging analysis in R -


i have survival data experiment in flies examines rates of aging in various genotypes. data available me in several layouts choice of you, whichever suits answer best.

one dataframe (wide.df) looks this, each genotype (exp, of there ~640) has row, , days run in sequence horizontally day 4 day 98 counts of new deaths every 2 days.

exp      day4   day6    day8    day10   day12   day14    ...        0      0       0       2       3       1        ... 

i make 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("exp","day4","day6","day8","day10","day12","day14","day16","day18","day20","day22","day24","day26","day28","day30","day32","day34","day36") 

another version this, each day has row each 'exp' , number of deaths on day recorded.

exp     deaths  day            0       4           0       6       0       8       2       10       3       12 ..      ..      .. 

to make example:

df2<-data.frame(c("a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"),c(0,0,0,2,3,1,3,4,5,3,4,7,8,2,10,1,2),c(4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36))     colnames(df2)<-c("exp","deaths","day") 

what perform gompertz analysis (see second paragraph of "the life table" here). equation is:

μx = α*e β*x

where μx probability of death @ given time, α initial mortality rate, , β rate of aging.

i able dataframe has α , β estimates each of ~640 genotypes further analysis later.

i need going above dataframes output of these values each of genotypes in r.

i have looked through package flexsurv may house answer have failed in attempts find , implement it.

this should started...

firstly, flexsurvreg function work, need specify input data surv object (from package:survival). means 1 row per observation.

the first thing re-create 'raw' data summary tables provide. (i know rbind not efficient, can switch data.table large sets).

### rows >1 death df3 <- df2[df2$deaths>1, 2:3] ### expand give 1 row per death per time df3 <- sapply(df3, fun=function(x) rep(df3[, 2], df3[, 1])) ### each death 1 (occurs once) df3[, 1] <- 1 ### add rows <=1 death df3 <- rbind(df3, df2[!df2$deaths>1, 2:3]) ### convert surv object library(survival) s1 <- with(df3, surv(day, deaths)) ### parameters gompertz distribution library(flexsurv)  f1 <- flexsurvreg(s1 ~ 1, dist="gompertz") 

giving

> f1$res               est         l95%        u95% shape 0.165351912 0.1281016481 0.202602176 rate  0.001767956 0.0006902161 0.004528537 

note intercept-only model genotypes a. can loop on multiple survival objects once have re-created per-observation data above.

from flexsurv docs:

gompertz distribution shape parameter a , rate parameter b has hazard function

h(x: a, b) = b.e^{ax}

so appears alpha b, rate, , beta a, shape.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -