-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkaplan mayer formula_unemployment.R
36 lines (30 loc) · 1.07 KB
/
kaplan mayer formula_unemployment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(survival)
read.table(
'/Users/bqdesy/Desktop/unemployment1.csv',
sep=';',
dec=',',
header=TRUE
) -> data
data
attach(data)
#survival object Surv(time,event) lub Surv(time1,time2,event,type)
my.survival.object<-Surv(duration,failure)
my.survival.object
#kaplan-meier estimator
fit<-survfit(my.survival.object ~ 1) #krzywa przezycia
plot(fit, xlab = "Weeks", ylab="Survival")
summary(fit)
summary(fit)$surv # returns the Kaplan-Meier estimate at each t_i
summary(fit)$time # {t_i}
summary(fit)$n.risk # {Y_i}
summary(fit)$n.event # {d_i}
summary(fit)$std.err # standard error of the K-M estimate at {t_i}
summary(fit)$lower # lower pointwise estimates (alternatively, $upper)
str(fit) # full summary of the fit object
str(summary(fit)) # full summary of the fit object
plot(fit, main="Kaplan-Meier estimate with 95% confidence bounds",
xlab="time", ylab="survival function")
#graph
plot(survfit(my.survival.object ~ 1), xlim=c(0, 6), xlab="weeks",
ylab="Estimated Survival Function",
main="Reproducing Confidence Bands for S(x)")