[R] Weibull distribution

Terry Therneau therneau at mayo.edu
Wed Oct 1 16:09:49 CEST 2008


>I would like to calculate and plot a Weibull distribution (Weibull best-fit 
>line, accuracy curves left and right beside the best-fit line) for a simple set 
>of data points. I need the shape and the scale parameter for the best-fit and 
>values like B5, B10, B50, B90, B95.

You can use the survreg routine, which fits a Weibull distribution to censored 
data.  You simply don't have censoring.

> library(survival)
> fit <- survreg(Surv(time) ~ 1, data=lung)
> fit
Coefficients:
(Intercept) 
   5.819191 

Scale= 0.681689 

Loglik(model)= -1509.6   Loglik(intercept only)= -1509.6
n= 228 

> predict(fit, type='quantile', p=c(.05, .1, .5, .9, .95))[1,]
[1]  44.45340  72.61274 262.26181 594.51261 711.32731

  There are many ways to parameterize the Weibull.  Assume we have
  	F(x) = 1- exp((-lambda*x)^gamma)
  
  Survreg fits a number of distributions by transforming the problem to a 
location/scale form, for the Weibull intercept = -log(lambda) and scale = 
1/gamma.	
  
  	Terry Therneau



More information about the R-help mailing list