[R] sequential treatment of a vector for formula

Wu Gong ghowoo at gmail.com
Thu May 27 19:18:47 CEST 2010


Thank you very much David. I'm sorry for this fault , hope it has not
confused Frostygoat.

I was clueless of recursive reference and I didn't meet any error when I
test the code. So I wonder if there are some useful tips to prevent making
this kind of faults:)

The revised code is followed.

### Kaplan-Meier estimate
### Compute surviving proportion of a cohort
## 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 frequency of each death day
tb <- table(example)

## Output
## Interval(Start-End)  "Interval"
## At risk at start of interval "RSI"
## Deaths during interval "Deaths"
## At risk at end of interval "REI"
## Propoition surviving this interval "PSI" = REI/RSI
## Cumulative surviving at end of interval "CSI" = cumprod(PSI)
iC <- data.frame("Interval"=as.numeric(names(tb)),
	"RSI"=sum(tb)-cumsum(tb)+tb[],
	"Deaths"=tb[],
	"REI"=sum(tb)-cumsum(tb),
	"PSI"=(sum(tb)-cumsum(tb))/(sum(tb)-cumsum(tb)+tb[]),
	"CSI"=cumprod((sum(tb)-cumsum(tb))/(sum(tb)-cumsum(tb)+tb[])))

## Plot survival curve	
plot(iC$Interval,iC$CSI,"s")

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/sequential-treatment-of-a-vector-for-formula-tp2232517p2233491.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list