[R] sequential treatment of a vector for formula
David Winsemius
dwinsemius at comcast.net
Thu May 27 16:09:58 CEST 2010
On May 27, 2010, at 12:42 AM, Wu Gong wrote:
>
> I don't know if my understanding of P is right.
>
> P ?= (the number of lives at the end of the interval)/(the number of
> lives
> at the beginning of the interval)
In standard actuarial parlance one would use lower case p_x for that
quantity and would reserve upper case P_x for the cumulative survival
fraction. The cumulative product of the p_x', P_x, with appropriate
corrections for censoring, was rebranded in biostatistical circles as
the Kaplan-Meier estimator.
>
> ### Compute proportion of a cohort that survives through the interval
> ### The formula is P0=L1/LO
> ## Original data is a vector of death days
> example=as.vector(c(8,2,1,5,6,7,7,0,8,10,13,8,11,11,11,2,7,1,5,6,8,6))
>
> ## Count the frenquency of each death day
> ## Add more levels to fulfill days range
> tb <- table(factor(example,levels=seq(0, max(example))))
>
> ## Output
> iC <- data.frame("x"=names(tb),
> "Kx"=sum(tb)-cumsum(tb),
> "Dx"=tb[],
> "Lx"=iC$Kx/sum(tb),
> "Px"=iC$Kx/(iC$Kx+tb[]))
In a fresh session that R code does not succeed, since the data.frame
function does not handle recursive references.
>
> -----
> A R learner.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list