I've been examining fitting the Weibull and lognormal distributions with the survreg() function of the survival package. Fitting the Weibull distribution took some transformation for standard parameterization (per R dweibull()) as shown here: How to generate multiple forecast simulation paths for survival analysis?
I'm now moving on to the exponential distribution. [See https://stats.stackexchange.com/questions/616351/how-to-assign-reasonable-scale-parameters-to-randomly-generated-intercepts-for-t for an example of the exponential distribution.] Could someone please confirm if the exponential distribution is being correctly fit in the R code posted at the bottom and as illustrated in the following image? If not, how do I correctly fit exponential? I only use the lung dataset for ease of example even though it doesn't provide good fit: Weibull provides the best fit.
Code:
library(survival)
time <- seq(0, 1000, by = 1)
fit <- survreg(Surv(time, status) ~ 1, data = lung, dist = "exponential")
survival <- 1 - pexp(time, rate = 1 / fit$coef)
plot(time, survival, type = "l", xlab = "Time",ylab = "Survival Probability",col = "red", lwd = 3)
lines(survfit(Surv(time, status) ~ 1, data = lung), col = "blue")
legend("topright",legend = c("Fitted exponential","Kaplan-Meier" ),col = c("red", "blue"),lwd = c(3, 1),bty = "n")

predict.survreg. – whuber May 11 '23 at 14:30predictmethod does when you're learning your way around any regression procedure inR. – whuber May 11 '23 at 19:39