0% found this document useful (0 votes)
20 views9 pages

Estimation of Survival Function

ok

Uploaded by

Nandini Rachcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Estimation of Survival Function

ok

Uploaded by

Nandini Rachcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Class: T.Y.B.Sc. Practical No.

: 02
BSCST-511T Date: 03/08/224
Practical Name: Estimation of Survival Function.
Name:

install.packages("survival")

Warning: package ‘survival’ is in use and will not be installed


> library(survival)
>
> #Q.1)
> deaths <-c (5, 8, 10, 12)
> population <- 500
> #Function to calaualate the acturial function
> calculate_actuarial_survival <- function(deaths, population) {
+ age <- seq(40, by = 5, length.out = length(deaths))
+ probabilities <- deaths / population
+ survival_probabilities <- cumprod(1 - probabilities)
+
+ result <- data.frame(Age = age, Deaths = deaths, Population = population, Probability =
probabilities, Actuarial_Survival = survival_probabilities)
+ return(result)
+}
> #Calculate actuarial survival function
> actuarial_data <- calculate_actuarial_survival(deaths,population)
> actuarial_data
Age Deaths Population Probability Actuarial_Survival
1 40 5 500 0.010 0.9900000
2 45 8 500 0.016 0.9741600
3 50 10 500 0.020 0.9546768 4 55 12 500 0.024 0.9317646
>
> #Q.2)
> deaths <- c(2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10)
> initial_population <- 1000
> # Function to calculate the actuarial survival function
> calculate_actuarial_survival_tem_life <- function(deaths,initial_population) {
+ age <- seq(30, by = 1, length.out = length(deaths))
+ probabilities <- deaths / initial_population
+ survival_probabilities <- cumprod(1 - probabilities)
+
+ result <- data.frame(Age = age, Deaths = deaths, Initial_Population = initial_population,
Probability = probabilities, Actuarial_Survival = survival_probabilities)
+ return(result)
+}
> # Calculate the actuarial survival function for the term life insurance policy
> acturial_data_term_life <- calculate_actuarial_survival_tem_life(deaths, initial_population)
> acturial_data_term_life
Age Deaths Initial_Population Probability Actuarial_Survival
1 30 2 1000 0.002 0.9980000
2 31 0 1000 0.000 0.9980000
3 32 0 1000 0.000 0.9980000
4 33 0 1000 0.000 0.9980000
5 34 3 1000 0.003 0.9950060
6 35 0 1000 0.000 0.9950060
7 36 0 1000 0.000 0.9950060
8 37 0 1000 0.000 0.9950060
9 38 0 1000 0.000 0.9950060
10 39 0 1000 0.000 0.9950060
11 40 5 1000 0.005 0.9900310
12 41 0 1000 0.000 0.9900310
13 42 0 1000 0.000 0.9900310
14 43 0 1000 0.000 0.9900310
15 44 0 1000 0.000 0.9900310
16 45 0 1000 0.000 0.9900310
17 46 0 1000 0.000 0.9900310
18 47 0 1000 0.000 0.9900310
19 48 0 1000 0.000 0.9900310
20 49 7 1000 0.007 0.9831008
21 50 0 1000 0.000 0.9831008
22 51 0 1000 0.000 0.9831008
23 52 0 1000 0.000 0.9831008
24 53 0 1000 0.000 0.9831008
25 54 0 1000 0.000 0.9831008
26 55 0 1000 0.000 0.9831008
27 56 0 1000 0.000 0.9831008
28 57 0 1000 0.000 0.9831008
29 58 0 1000 0.000 0.9831008
30 59 0 1000 0.000 0.9831008
31 60 10 1000 0.010 0.9732697
>

> #Q.3)
>
> event_times <- c(8, 12, 16, 20, 24)
> number_of_deaths <- c(2, 1, 3, 1, 2)
>
> #Create a survival object
>
> surv_obj <- Surv (time = event_times, event = number_of_deaths) Warning
message:
In Surv(time = event_times, event = number_of_deaths) :
Invalid status value, converted to NA
>
> # Fit the Kaplan-Meier estimator
> km_fit <- survfit(surv_obj ~ 1)
> km_fit
Call: survfit(formula = surv_obj ~ 1)

3 observations deleted due to missingness


n events median 0.95LCL 0.95UCL
[1,] 2 2 16 12 NA
>
> summary(km_fit)
Call: survfit(formula = surv_obj ~ 1)

3 observations deleted due to missingness


time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 2 1 0.5 0.354 0.125 1
20 1 1 0.0 NaN NA NA
>
> #Plot the Kaplan-Meier survival curve
>
> plot(km_fit, main = "Kaplan-Meier Survival Curve", xlab = "Time", ylab =
"Survival Probability")
>
> #Q.4)
> event_times <- c(10, 151, 25, 30)
>
> number_of_deaths <- c(3, 2, 4, 1)
>
> censored_individuals <- c(5, 12, 18, 22, 28)
>
> # Create a survival object
>
> surv_obj <- Surv (time = c(event_times, rep (Inf, length (censored_individuals))),event
= c(rep(1, length(event_times)), rep(0, length(censored_individuals))))
>
> # Fit the Kaplan-Meier estimator
>
> km_fit1 <- survfit (surv_obj ~ 1)
>
> km_fit1
Call: survfit(formula = surv_obj ~ 1)

n events median 0.95LCL 0.95UCL


[1,] 9 4 NA 30 NA
>
> summary(km_fit1)
Call: survfit(formula = surv_obj ~ 1)

time n.risk n.event survival std.err lower 95% CI


10 9 1 0.889 0.105 0.706
25 8 1 0.778 0.139 0.549
30 7 1 0.667 0.157 0.420
151 6 1 0.556 0.166 0.310
upper 95% CI
1.000
1.000
1.000
0.997
>
> plot(km_fit1, main = "Kaplan-Meier Survival Curve", xlab = "Time", ylab =
"Survival Probability")
>
> # Install and load the survival package if not already installed
>
> #install.packages("survival")
> library (survival)
>
> # Create the data
> event_times <- c(8, 12, 16, 20, 24)
> number_of_deaths <- c(2, 1, 3, 1, 2)
>
> # Create a survival object
> surv_obj <- Surv(time = event_times, event = number_of_deaths)
Warning message:
In Surv(time = event_times, event = number_of_deaths) :
Invalid status value, converted to NA
>
> # Fit the Kaplan-Meier estimator
> km_fit <- survfit(surv_obj~ 1)
>
> print(km_fit)
Call: survfit(formula = surv_obj ~ 1)

3 observations deleted due to missingness


n events median 0.95LCL 0.95UCL
[1,] 2 2 16 12 NA
>
> #Plot the Kaplan-Meier survival curve
> plot(km_fit, main = "Kaplan-Meier Survival Curve", xlab = "Time", ylab =
"Survival Probability")
>

You might also like