Fit an exponential distribution to the data set Weibull.csv. Calculate and plot the cumulative hazard function and compare it to the Nelson-Aalen curve. Is the exponential distribution a good fit for this data?

edu<-read.csv("/Users/kunaldolas/Desktop/phc6177/weibull.csv")##  read data 

##calculate lambda
library(survival)
expfit <- survreg(Surv(time, delta) ~1, data=edu, dist="exponential")
summary(expfit)
## 
## Call:
## survreg(formula = Surv(time, delta) ~ 1, data = edu, dist = "exponential")
##               Value Std. Error     z    p
## (Intercept) -0.0307     0.0335 -0.91 0.36
## 
## Scale fixed at 1 
## 
## Exponential distribution
## Loglik(model)= -861.7   Loglik(intercept only)= -861.7
## Number of Newton-Raphson Iterations: 3 
## n= 1000
exp(-coef(expfit))
## (Intercept) 
##    1.031146
# lambda=1.03
exp.s<- function(t, lambda=1.03) exp(-lambda*t)
x<- edu$time
y<-exp.s(x)
plot(x,y, type="l",main="Cumulative hazard function", xlab="Time", ylab="Survival probablity")

t <- seq(0, max(edu$time), .01)

llog.NA <- survfit(Surv(time, delta) ~ 1, data = edu, conf.type = "log-log", type ="fleming-harrington", error = "tsiatis")
plot(llog.NA, mark.time = FALSE, fun = "cumhaz",main = "Nelson-Aalen cumulative hazard curve",xlab = "Time", ylab = "Cumulative hazard")

llog.H <- function(t, lambda, gamma) log(1 + (lambda * t)^gamma) 
lines(t, llog.H(t, 1.03, 1), col = "gray")
legend("bottomright",lty = c("solid", "dashed", "solid"),col = c("black", "black", "gray"),legend = c("Nelson-Aalen estimate", "95% confidence limits","True cumulative hazard function"))

by looking at the graph, the exponential distribution is not a good fit for this data.