1

I have a survival object (S) for which I am doing a weibull fit using the survreg function and weibull distribution in R.

S = Surv(data$ValueX, data$ValueY)
W = Survreg(S ~ 1, data=data, dist="weibull") 

How do I extract the R-square value of the Weibull fit which is essentially a linear line? Or is there a function to calculate the correlation coefficient value Rho?

Basically, I want to calculate the goodness of fit.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Nim
  • 21
  • 2
  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. But what do you want the r-squared value for? What two sets of values are you comparing? – MrFlick Jul 02 '18 at 18:30
  • Sure, Will do next time! Thanks for the suggestion. – Nim Jul 06 '18 at 01:50

1 Answers1

2

Look at pam.censor in the PAmeasures package which produces an R^2 like statistic. Using the ovarian dataset from the survival package:

library(PAmeasures)
library(survival)

fit.s <- survreg(Surv(futime, fustat) ~ age, data = ovarian, dist="weibull" )
p <- predict(fit.s, type = "response")
with(ovarian, pam.censor(futime, p, fustat))

For the ovarian data with an age regressor we get a value of only 0.0915 .

Another idea is that for a Weibull model with no covariates we have S(t) = exp(- (lambda * t)^p) so log(-log(S(t))) is linear in log(t) hence we could use the R squared of the corresponding regression to measure how well the model fits to a Weibull.

library(survival)

fit1 <- survfit(Surv(futime, fustat) ~ 1, data = ovarian)
sum1 <- summary(fit1, times = ovarian$futime)
fo <- log(-log(surv)) ~ log(time)
d <- as.data.frame(sum1[c("time", "surv")])
fit.lm <- lm(fo, d)
summary(fit.lm)$r.sq

plot(fo, d)
abline(fit.lm)

For the ovarian data without covariates the R^2 at 93% is high but the plot does suggest systematic departures from linearity so it may not really be Weibull.

Other

Not sure if this is of interest but the eha package has the check.dist function which can be used for a visual comparison of a parametric baseline hazard model to a cox proportional hazard model. See the documentation as well as: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5233524/

Using the ovarian dataset from survival:

library(eha)
library(surival)

fit.c <- coxreg(Surv(futime, fustat) ~ age, data = ovarian)
fit.p <- phreg(Surv(futime, fustat) ~ age, data = ovarian, dist = "weibull")
check.dist(fit.c, fit.p)

The survAUC package has three functions that provide r squared type statistics for cox proportional hazard models (OXS, Nagelk and XO).

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • The method to use corresponding regression model worked very well! Thank you. Like you mentioned in your comment, the PAMeasures package didn't really reflect the right fit. I also tried the eha package but I wanted a numeric measure more than visual. But it is useful to know! Thanks again. – Nim Jul 06 '18 at 01:49