MA251 Computer Assessment: "Survival Analysis" Answer Key: The Saylor Foundation Page 1 of 1
MA251 Computer Assessment: "Survival Analysis" Answer Key: The Saylor Foundation Page 1 of 1
3
The Saylor Foundation Saylor.org
Page 1 of 1
MA251
Computer Assessment: Survival Analysis
Answer Key
Instructions: The solution to Task 2 of the assessment is provided in the R code below.
Copy and paste the code to the R command window.
# Task 2: Load the dataset aml, which provides data on survival in patients with Acute
Myelogenous Leukemia.
# Use the Kaplan-Meier estimator to estimate the distributions of lifetimes for patients
who received additional chemotherapy cycles (maintained) and those who did not
(nonmaintained).
#Loading data
library(survival)
data(aml)
attach(aml)
aml
#Use survfit() to construct the K-M estimate for survival time.
# x contains the information on chemotherapy: Maintained versus Nonmaintained
KMfit <- survfit(Surv(time,status)~x)
# Plot the KM fit
plot(KMfit, lty = 2:3)
legend(100, .9, c("Maintenance", "No Maintenance"), lty = 2:3)
title("Kaplan-Meier Curves\nfor AML Maintenance Study")
#Perform a two-sample log-rank test to see whether the survival curves are different for
the two groups of patients.
survdiff(Surv(time, status)~x, data=aml)
#Conduct an exponential regression for the survival data.
survreg(Surv(time, status)~x, dist="exponential")
#Fit a Cox proportional hazard to the data.]
Coxfit <- coxph(Surv(time, status)~x)
summary(Coxfit)
#Obtain the baseline hazard rate
basehaz(Coxfit)