Skip to main content

Weibull and Accelerated Failure Time Models: How Long Will a Motor Last?

Parametric survival regression in R with survival::survreg(), on the classic accelerated life test of motor insulation (Nelson and Hahn, 1972): the Weibull distribution and its hazard, the accelerated failure time model by hand with censored data, the Arrhenius relation, Weibull against log-normal, log-logistic and exponential, extrapolation to working temperature with intervals, proportional hazards and time ratios from one model next to Cox, checks and APA reporting.

The question: five years in a few months

The insulation of an electric motor ages with heat, and one day the motor fails. A motor is meant to run at 130 °C for years. Nobody wants to wait for years to know how long. So engineers test motors at higher temperatures, where they fail sooner, and calculate back. This is an accelerated life test.

Nelson and Hahn (1972) published a famous one: 40 motors at 150, 170, 190 and 220 °C. When the test was stopped, many had not failed, and at 150 °C none had. The question has three parts. How does life depend on the temperature? What is the distribution of the lifetimes? And what does it say about 130 °C, where nothing was measured?

The answer needs a model with a full distribution. The Cox model leaves the baseline open, and so it cannot say anything about times or temperatures outside the data. A parametric survival model can, at the price of an assumption. The accelerated failure time (AFT) model got its name here: the predictors make time itself run faster or slower.

Code
library(survival)   # survreg(): parametric survival regression (comes with R, as do the data)
library(ggplot2)

dist_colours <- c(
  weibull = "#2a78d6",
  lognormal = "#eb6834",
  loglogistic = "#1baf7a",
  exponential = "#eda100"
)

# number formats for the text
f0   <- function(x) formatC(x, format = "f", digits = 0, big.mark = ",")
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
pct  <- function(x, d = 0) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

The data come with R, in the package survival:

Code
motors <- as.data.frame(imotor)
# 1000 divided by the absolute temperature (Kelvin): see step 3
motors$x <- 1000 / (motors$temp + 273.16)
table(temperature = motors$temp, failed = motors$status)
           failed
temperature  0  1
        150 10  0
        170  3  7
        190  5  5
        220  5  5
Code
aggregate(time ~ temp, data = motors, FUN = max) # when the test of each group was stopped (hours)
  temp time
1  150 8064
2  170 5448
3  190 1680
4  220  528

time is in hours, status is 1 for a failure and 0 for a motor that was still running when the test of its group ended (censored). Of 40 motors 17 failed. (Failures were found at inspections, so several have the same time. We take the times as they are.)


2. Look at the data

Code
ggplot(motors, aes(temp, time, colour = factor(status), shape = factor(status))) +
  geom_point(position = position_jitter(width = 1.5, height = 0, seed = 1), size = 2.6) +
  scale_y_log10(breaks = c(300, 1000, 3000, 10000, 30000, 100000)) +
  scale_colour_manual(
    values = c(`0` = "grey55", `1` = "#eb6834"),
    labels = c("still running", "failed"),
    name = NULL
  ) +
  scale_shape_manual(
    values = c(`0` = 2, `1` = 16),
    labels = c("still running", "failed"),
    name = NULL
  ) +
  coord_cartesian(xlim = c(125, 225), ylim = c(300, 100000)) +
  labs(title = "40 motors", x = "temperature (°C)", y = "hours (log scale)") +
  theme_bw() +
  theme(legend.position = "bottom")

Plot: 2. Look at the data

The hotter, the sooner. At 220 °C half of the motors failed within 504 hours; at 150 °C all were running after 8,064. On the log scale the relation looks like a line, and the spread looks similar at each temperature. Both are assumptions of the model that follows.


3. The model step by step, with formulas

Step 1: the Weibull distribution

Weibull (1951) proposed a distribution for the strength of materials that has been used for lifetimes ever since. Its survival function and hazard are

\[S(t) = \exp\!\left[-\left(\frac{t}{\eta}\right)^{k}\right], \qquad h(t) = \frac{k}{\eta}\left(\frac{t}{\eta}\right)^{k-1}\]

\(\eta\) is the scale, the time at which 63% have failed. \(k\) is the shape: with \(k > 1\) the hazard rises (wear), with \(k < 1\) it falls (the weak ones go first), and with \(k = 1\) it is constant (the exponential distribution: no memory).

Code
grid <- seq(0.02, 3, by = 0.02)
shapes <- do.call(
  rbind,
  lapply(c(0.7, 1, 1.5, 3), function(k) {
    data.frame(t = grid, h = k * grid^(k - 1), shape = paste("k =", k))
  })
)
ggplot(shapes, aes(t, h, colour = shape)) +
  geom_line(linewidth = 1) +
  coord_cartesian(ylim = c(0, 5)) +
  scale_colour_viridis_d(end = 0.9, name = NULL) +
  labs(title = "The hazard of the Weibull distribution (η = 1)", x = "time", y = "hazard") +
  theme_bw() +
  theme(legend.position = "bottom")

Shapes – Step 1: the Weibull distribution

Step 2: predictors stretch time

\[\log T = \beta_0 + \beta_1 x + \sigma W\]

\(\log T\) is a line plus an error. If \(T\) is Weibull, \(W\) has the smallest extreme value distribution, and \(\sigma = 1/k\). With a normal \(W\), \(T\) is log-normal; with a logistic \(W\), log-logistic. In all of them, one unit more of \(x\) multiplies every quantile of the lifetime by \(e^{\beta_1}\), the time ratio. Life at 190 °C is life at 170 °C in fast motion.

Step 3: why \(1/T\)? The Arrhenius relation

Chemistry says that the speed of a reaction depends on the absolute temperature as \(e^{-E/(kT)}\). If aging is such a reaction, the log of the lifetime is a straight line in 1 / absolute temperature. This is knowledge from outside the data, and the only thing that makes an extrapolation to 130 °C reasonable. (We use 1000/K, so the numbers are easy to read.)

Step 4: maximum likelihood with censoring

A failure at time \(t\) contributes the density \(f(t)\), a motor still running at time \(t\) contributes the survival probability \(S(t)\):

\[\log L = \sum_{\text{failed}} \log f(t_i) + \sum_{\text{running}} \log S(t_i)\]

By hand, with R’s Weibull functions (dweibull, pweibull):

Code
minus_loglik <- function(par) {
  # intercept, slope, log(sigma)
  eta <- exp(par[1] + par[2] * motors$x)
  k <- 1 / exp(par[3])
  -sum(ifelse(
    motors$status == 1,
    dweibull(motors$time, k, eta, log = TRUE),
    pweibull(motors$time, k, eta, lower.tail = FALSE, log.p = TRUE)
  ))
}
hand <- optim(c(-12, 9, -1), minus_loglik, control = list(maxit = 5000, reltol = 1e-14))
hand <- optim(hand$par, minus_loglik, control = list(maxit = 5000, reltol = 1e-14))
fit  <- survreg(Surv(time, status) ~ x, data = motors, dist = "weibull")
rbind(
  by_hand = c(`(Intercept)` = hand$par[1], x = hand$par[2], sigma = exp(hand$par[3]), logLik = -hand$value),
  survreg = c(coef(fit), fit$scale, logLik(fit))
)
        (Intercept)        x     sigma    logLik
by_hand   -13.35346 9.724300 0.3254444 -146.2543
survreg   -13.35346 9.724299 0.3254444 -146.2543

4. Fitting the model and reading the output

Code
summary(fit)

Call:
survreg(formula = Surv(time, status) ~ x, data = motors, dist = "weibull")
              Value Std. Error     z       p
(Intercept) -13.353      1.501 -8.90 < 2e-16
x             9.724      0.696 13.97 < 2e-16
Log(scale)   -1.123      0.210 -5.34 9.1e-08

Scale= 0.325 

Weibull distribution
Loglik(model)= -146.3   Loglik(intercept only)= -169.5
    Chisq= 46.54 on 1 degrees of freedom, p= 9e-12 
Number of Newton-Raphson Iterations: 8 
n= 40 
Code
b <- coef(fit); s <- summary(fit)$table; k <- 1 / fit$scale
ratio10 <- exp(b[["x"]] * (1000 / (150 + 273.16) - 1000 / (160 + 273.16))) # from 160 to 150 degrees
  • x = 9.72: the slope of the Arrhenius line. Easier to say: going from 160 to 150 °C multiplies the lifetime by 1.70. An old rule of engineers says that 10 degrees less double the life.
  • Scale = 0.33 is \(\sigma\), so the shape is \(k = 1/\sigma\) = 3.07: well above 1. The hazard rises steeply: the insulation wears out.
  • Log(scale): its test asks whether \(\sigma = 1\), that is whether the exponential distribution would do. p < .001: it would not.
  • Loglik, Chisq: the likelihood-ratio test of all the predictors.
  • Do not confuse the scale of survreg (\(\sigma\)) with the scale of the Weibull distribution (\(\eta = e^{\beta_0 + \beta_1 x}\)).

Quantiles

The time by which a share \(p\) of the motors has failed:

\[t_p = \exp\big(\beta_0 + \beta_1 x + \sigma\, w_p\big), \qquad w_p = \log[-\log(1 - p)]\]

Code
at <- data.frame(temp = c(130, 150, 170, 190, 220)); at$x <- 1000 / (at$temp + 273.16)
q <- predict(fit, at, type = "quantile", p = c(0.1, 0.5, 0.9))
colnames(q) <- c("10%", "50%", "90%")
round(cbind(temp = at$temp, q))
     temp   10%   50%   90%
[1,]  130 22797 42086 62204
[2,]  150  7291 13460 19894
[3,]  170  2584  4771  7052
[4,]  190  1002  1850  2734
[5,]  220   279   516   762

5. Which distribution?

Code
dists <- names(dist_colours)
fits <- lapply(dists, function(d) survreg(Surv(time, status) ~ x, data = motors, dist = d))
names(fits) <- dists
at130 <- data.frame(x = 1000 / (130 + 273.16))
interval <- function(m, p) {
  r <- predict(m, at130, type = "uquantile", p = p, se.fit = TRUE)
  est <- r$fit[[1]]; se <- r$se.fit[[1]]
  exp(c(estimate = est, low = est - 1.96 * se, high = est + 1.96 * se))
}
compare <- t(sapply(fits, function(m) {
  c(
    AIC = AIC(m),
    median_130 = interval(m, 0.5)[[1]],
    q10_130 = interval(m, 0.1)[[1]],
    q0.1_130 = interval(m, 0.001)[[1]]
  )
}))
round(compare)
            AIC median_130 q10_130 q0.1_130
weibull     299      42086   22797     5008
lognormal   303      47135   21937     7454
loglogistic 300      41805   22400     5880
exponential 315      88892   13512      128

By the AIC the Weibull (298.5) and the log-logistic (300.1) are best, the log-normal close, and the exponential is out. With 17 failures the data cannot say more. Now look at the predictions for 130 °C.

  • The median life is 42,086, 47,135 and 41,805 hours. These agree: about five years of running day and night.
  • The time when one in a thousand has failed, which matters for a guarantee, is 5,008, 7,454 and 5,880 hours. Here the distributions disagree by a factor of 1.5. Nothing in the data can decide, because there is no data in that tail. (The exponential distribution, which the data reject, would say 128 hours.)
Code
line <- data.frame(temp = seq(125, 225, by = 1)); line$x <- 1000 / (line$temp + 273.16)
qs <- do.call(
  rbind,
  lapply(c(0.1, 0.5, 0.9), function(p) {
    r <- predict(fit, line, type = "uquantile", p = p, se.fit = TRUE)
    data.frame(
      temp = line$temp,
      est = exp(r$fit),
      low = exp(r$fit - 1.96 * r$se.fit),
      high = exp(r$fit + 1.96 * r$se.fit),
      q = paste0(100 * p, "% have failed")
    )
  })
)
qs$q <- factor(qs$q, levels = unique(qs$q))
ggplot(qs, aes(temp, est, colour = q)) +
  geom_ribbon(
    data = subset(qs, q == "50% have failed"),
    aes(ymin = low, ymax = high),
    fill = "#2a78d6",
    alpha = 0.15,
    colour = NA
  ) +
  geom_line(linewidth = 0.9) +
  geom_point(
    data = motors,
    aes(temp, time, shape = factor(status)),
    inherit.aes = FALSE,
    size = 1.8,
    colour = "grey30"
  ) +
  geom_vline(xintercept = 130, linetype = "dashed") +
  scale_shape_manual(
    values = c(`0` = 2, `1` = 16),
    labels = c("still running", "failed"),
    name = NULL
  ) +
  scale_colour_manual(values = c("#eda100", "#2a78d6", "#1baf7a"), name = NULL) +
  scale_y_log10(breaks = c(300, 1000, 3000, 10000, 30000, 100000)) +
  guides(colour = guide_legend(order = 1), shape = guide_legend(order = 2)) +
  labs(
    title = "Weibull model: quantiles of the lifetime",
    subtitle = "Band: 95% interval of the median. Dashed line: the working temperature",
    x = "temperature (°C)",
    y = "hours (log scale)"
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.box = "vertical")

Extrapolation – 5. Which distribution?

Code
med130 <- interval(fit, 0.5); q10 <- interval(fit, 0.1)

The median at 130 °C is 42,086 hours, 95% CI [26,347, 67,226]. The interval is wide, and it contains only the uncertainty of the estimates. It does not contain the uncertainty about the Weibull, about the Arrhenius line, and about whether the same kind of failure happens at 130 °C at all. Meeker and Escobar (1998) list the ways in which such extrapolations go wrong.


6. Checking the model

Is the spread the same at all temperatures?

The AFT model assumes one \(\sigma\). Let each temperature have its own (strata):

Code
# at 150 degrees nothing failed: no information about sigma
with_failures <- subset(motors, temp > 150)
one  <- survreg(Surv(time, status) ~ x, data = with_failures, dist = "weibull")
many <- survreg(Surv(time, status) ~ x + strata(temp), data = with_failures, dist = "weibull")
lr   <- 2 * (as.numeric(logLik(many)) - as.numeric(logLik(one)))
many$scale
 temp=170  temp=190  temp=220 
0.3483426 0.5717329 0.1115813 
Code
c(LR = lr, df = 2, p = pchisq(lr, 2, lower.tail = FALSE))
        LR         df          p 
7.44462238 2.00000000 0.02417802 

The scales are 0.35, 0.57, 0.11 at 170, 190 and 220 °C, and the test of equality gives p = .024. The spread is probably not the same: at 220 °C the failures were all found at two neighboring inspections. With five to seven failures per group no estimate of a spread is reliable, but the assumption of one \(\sigma\) is doubtful, and again it is the highest temperature that stands out.

Is the line straight?

Code
curve <- survreg(Surv(time, status) ~ x + I(x^2), data = motors, dist = "weibull")
free  <- survreg(Surv(time, status) ~ factor(temp), data = with_failures, dist = "weibull")
c(AIC_line = AIC(fit), AIC_curve = AIC(curve))
 AIC_line AIC_curve 
 298.5086  297.3267 
Code
c(AIC_line = AIC(one), AIC_each_temperature_free = AIC(free))
                 AIC_line AIC_each_temperature_free 
                 294.6898                  296.3326 
Code
lr_line <- 2 * (as.numeric(logLik(free)) - as.numeric(logLik(one)))
c(LR = lr_line, df = 1, p = pchisq(lr_line, 1, lower.tail = FALSE))
       LR        df         p 
0.3571972 1.0000000 0.5500670 

A bend (a squared term) lowers the AIC by only 1.2. Against a model where each of the three temperatures with failures has its own level, the Arrhenius line loses \(\chi^2\)(1) = 0.36, p = .550. The line is compatible with the data.

Code
no220 <- survreg(Surv(time, status) ~ x, data = subset(motors, temp < 220), dist = "weibull")
m2 <- interval(no220, 0.5)
m2
 estimate       low      high 
 75516.69  26382.81 216154.80 

Without the motors tested at 220 °C the median at 130 °C becomes 75,517 hours, [26,383, 216,155], instead of 42,086. This is the size of the problem with extrapolation.

Residuals

Code
# standardized log times, censored like the times
z <- (log(motors$time) - predict(fit, type = "lp")) / fit$scale
km <- survfit(Surv(exp(z), motors$status) ~ 1)
resid_data <- data.frame(z = log(km$time), S = km$surv)
resid_data <- subset(resid_data, S > 0 & S < 1)
ggplot(resid_data, aes(z, log(-log(S)))) +
  geom_abline(colour = "grey60") +
  geom_point(size = 2.2, colour = "#2a78d6") +
  labs(
    title = "Standardised residuals on Weibull paper",
    subtitle = "A straight line with slope 1 if the Weibull model is right",
    x = "residual",
    y = "log(-log(share not failed))"
  ) +
  theme_bw()

Residuals


7. The Weibull model is also a proportional hazards model

The Weibull is special. It is the only distribution that is both an AFT and a PH model. A time ratio of \(e^{\beta}\) is a hazard ratio of \(e^{-\beta/\sigma}\):

\[\text{HR} = e^{-\beta / \sigma} = e^{-\beta k}\]

We check it on the experiment of the Cox page, with 432 men released from prison, half of whom received money, and the weeks until the first arrest:

Code
rossi <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/carData/Rossi.csv")
rossi$money <- as.integer(rossi$fin == "yes")
aft <- survreg(Surv(week, arrest) ~ money + age + prio, data = rossi, dist = "weibull")
cox <- coxph(Surv(week, arrest) ~ money + age + prio, data = rossi)
tr  <- exp(coef(aft)[["money"]]); tr_ci <- exp(confint(aft)["money", ])
hr_weibull <- exp(-coef(aft) / aft$scale)[-1]
round(
  rbind(
    time_ratio = exp(coef(aft))[-1],
    hazard_ratio_Weibull = hr_weibull,
    hazard_ratio_Cox = exp(coef(cox))
  ),
  3
)
                     money   age  prio
time_ratio           1.283 1.049 0.933
hazard_ratio_Weibull 0.705 0.935 1.103
hazard_ratio_Cox     0.707 0.935 1.102
Code
c(shape = 1 / aft$scale)
  shape 
1.40037 
  • The hazard ratio of the payment is 0.71 by the Weibull model and 0.71 by Cox. They agree, without Cox assuming any shape.
  • The time ratio is 1.28, 95% CI [0.98, 1.68]: the payment stretches the time to the arrest by 28%. Many find this easier to understand than a ratio of hazards (Wei, 1992).
Cox Weibull Log-normal, log-logistic
Baseline free \(k\) and \(\eta\) two parameters
Effects hazard ratios hazard ratios and time ratios time ratios only
Hazard over time any rising or falling can rise and then fall
Prediction beyond the data no yes yes
Assumption proportional hazards both, and the shape time ratios, and the shape

8. Things to keep in mind

  • Extrapolation is the purpose and the danger. Say what it rests on: the distribution, the physical law, the same cause of failure.
  • Choose the distribution by theory and tradition as well as by AIC. The generalized gamma contains the exponential, Weibull and log-normal as special cases (flexsurv::flexsurvreg(dist = "gengamma")), and splines are more flexible still (Jackson, 2016).
  • Look at the hazard. If it falls after a peak (illness, infant mortality), the Weibull cannot follow it.
  • Censoring must be independent of the lifetime. Here it was fixed in advance.
  • Interval censoring. Failures found at inspections happened some time before. Surv(time1, time2, type = "interval2") does it properly.
  • Time that varies for predictors is harder in AFT models than in Cox.
  • A time ratio is an average stretch. If the effect is different for early and late events, use censored quantile regression, which has no such restriction.
  • Parameter names differ between programs. Check 1/scale, signs, and whether the coefficients are for log time or log hazard.

9. Reporting the results in APA style

A report (APA 7th edition) needs the number of events and of censored cases, the distribution and why, the transformation of the predictors, time ratios or quantiles with intervals, and the basis of any extrapolation. The numbers come from the R objects:

Code
apa_table <- data.frame(
  Term = c("Intercept", "1000 / temperature (K)", "log σ"),
  b = f2(s[, 1]),
  SE = f2(s[, 2]),
  z = f2(s[, 3]),
  p = sapply(s[, 4], function(p) sub("^= ", "", pval(p)))
)
pred_table <- data.frame(temp = c(130, 150, 170, 190, 220))
pred_table <- cbind(
  pred_table,
  t(sapply(pred_table$temp, function(tt) {
    r <- predict(
      fit,
      data.frame(x = 1000 / (tt + 273.16)),
      type = "uquantile",
      p = 0.5,
      se.fit = TRUE
    )
    exp(c(r$fit, r$fit - 1.96 * r$se.fit, r$fit + 1.96 * r$se.fit))
  }))
)
names(pred_table) <- c("temp", "med", "low", "high")

Method (data analysis):

The lifetimes of 40 motors tested at 150, 170, 190 and 220 °C (Nelson & Hahn, 1972) were analyzed with a Weibull accelerated failure time model; 23 motors had not failed at the end of the test and were right-censored. The predictor was 1000 divided by the absolute temperature (Arrhenius relation). The Weibull distribution was compared with the exponential, log-normal and log-logistic distributions by the AIC, and the equality of the scale and the linearity of the relation were tested with likelihood-ratio tests. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026) with the package survival (Therneau, 2026).

Results:

Lifetimes were longer at lower temperatures, b = 9.72, SE = 0.70, z = 13.97, p < .001; 10 degrees less, from 160 to 150 °C, multiplied the lifetime by 1.70. The shape parameter was 3.07, an increasing hazard. The Weibull model had an AIC of 298.5 (log-logistic 300.1, log-normal 303.1, exponential 314.7). The extrapolated median lifetime at 130 °C was 42,086 hours, 95% CI [26,347, 67,226] (Table 1); without the tests at 220 °C it was 75,517 hours. These values rest on the Weibull distribution and the Arrhenius relation, which cannot be checked at 130 °C.

Table 1

Estimated Median Lifetime by Temperature (Weibull Model)

Temperature (°C) Median (hours) 95% CI
130 42,086 [26,347, 67,226]
150 13,460 [9,752, 18,576]
170 4,771 [3,876, 5,873]
190 1,850 [1,580, 2,165]
220 516 [407, 653]

Note. N = 40, 17 failures. σ = 0.33. No motor was tested at 130 °C, and none failed at 150 °C.

Points to remember:

  • Give the numbers of events and of censored cases at each condition.
  • Name the distribution and the parameterization.
  • Report quantiles in real units, with intervals.
  • Mark extrapolations, and show how they change with other distributions.

10. Summary

When Times to an event, with censoring, and a need for full distributions, predictions or time ratios
The model \(\log T = x^\top\beta + \sigma W\); Weibull: hazard \(\propto t^{k-1}\), \(k = 1/\sigma\)
How (R) survreg(Surv(time, event) ~ x, data, dist = "weibull")
Reading it \(e^\beta\): time ratio; for the Weibull also \(e^{-\beta/\sigma}\): hazard ratio
Quantiles predict(fit, newdata, type = "quantile", p = c(.1, .5, .9))
Choosing AIC, residual plots, theory of the hazard
Danger Extrapolation in time and in the predictors
Related pages Cox, censored quantile regression, Tobit (a survival model in disguise)

References

Jackson, C. (2016). flexsurv: A platform for parametric survival modeling in R. Journal of Statistical Software, 70(8), 1–33. https://doi.org/10.18637/jss.v070.i08

Meeker, W. Q., & Escobar, L. A. (1998). Pitfalls of accelerated testing. IEEE Transactions on Reliability, 47(2), 114–118. https://doi.org/10.1109/24.722271

Nelson, W., & Hahn, G. J. (1972). Linear estimation of a regression relationship from censored data: Part I. Simple methods and their application. Technometrics, 14(2), 247–269. https://doi.org/10.1080/00401706.1972.10488912

Therneau, T. (2026). A package for survival analysis in R [R package]. https://CRAN.R-project.org/package=survival

Wei, L. J. (1992). The accelerated failure time model: A useful alternative to the Cox regression model in survival analysis. Statistics in Medicine, 11(14–15), 1871–1879. https://doi.org/10.1002/sim.4780111409

Weibull, W. (1951). A statistical distribution function of wide applicability. Journal of Applied Mechanics, 18(3), 293–297. https://doi.org/10.1115/1.4010337