---
title: "Accelerated Life Testing (ALT)"
output:
  rmarkdown::html_vignette:
    fig_width: 7
    fig_height: 5
    self_contained: false
bibliography: ../inst/REFERENCES.bib
vignette: >
  %\VignetteIndexEntry{Accelerated Life Testing (ALT)}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(ReliaPlotR)
library(WeibullR)
library(WeibullR.ALT)
```

## Statistical Background

**Accelerated Life Testing (ALT)** subjects units to stress levels (temperature, voltage, vibration, etc.) higher than use conditions in order to induce failures faster. Life data collected at multiple stress levels are then extrapolated to the use-condition stress using a physics-motivated life-stress model [@Nelson1990].

**Life distributions.** At each stress level, failure times are modeled with a Weibull or lognormal distribution. The *shape* parameter ($\beta$ for Weibull; $\sigma_{\log}$ for lognormal) is assumed constant across stress levels (the distributions are parallel on probability paper), while the *scale* parameter ($\eta$ for Weibull; $\exp(\mu_{\log})$ for lognormal) varies with stress according to the life-stress model.

**Life-stress models.** Two models are supported:

- **Arrhenius**: $\eta(S) = A \exp(E_a / (k S))$, where $S$ is temperature in Kelvin and $E_a / k$ is the activation energy divided by Boltzmann's constant. The x-axis uses a reciprocal scale so the relationship is linear.
- **Power Law (Inverse Power)**: $\eta(S) = A / S^n$, where $S$ is a non-thermal stress. Both axes are log-transformed so the relationship is linear.

**Fitting.** `alt.parallel()` fits independent Weibull/lognormal models at each stress level; `alt.fit()` then fits the global life-stress relationship by constraining the shape parameter to be equal across stress levels [@Nelson1990; @MeekerEscobar1998].

## Building an ALT Model

The `WeibullR.ALT` package uses a three-step pipeline to create an ALT model.

**Step 1 — Create data sets** for each stress level using `alt.data()`:

```{r data}
d1 <- alt.data(c(248, 456, 528, 731, 813, 537), stress = 300)
d2 <- alt.data(c(164, 176, 289), stress = 350)
d3 <- alt.data(c(88, 112, 152), stress = 400)
```

**Step 2 — Fit parallel models** across stress levels using `alt.make()` and `alt.parallel()`:

```{r parallel, results = "hide"}
obj <- alt.parallel(
  alt.make(list(d1, d2, d3), dist = "weibull", alt.model = "arrhenius", view_dist_fits = FALSE),
  view_parallel_fits = FALSE
)
```

**Step 3 — Fit the life-stress relationship** using `alt.fit()`:

```{r fit, results = "hide"}
obj <- alt.fit(obj)
```

## ALT Probability Plot

`plotly_alt()` overlays one probability-paper fit line per stress level. Data points show empirical plotting positions; lines show the theoretical Weibull (or lognormal) fit. Click a legend entry to toggle a stress level on or off.

```{r prob-plot}
plotly_alt(obj)
```

### Customization

The plot accepts several optional arguments:

```{r prob-custom}
plotly_alt(
  obj,
  main    = "Reliability Test Results",
  xlab    = "Hours to Failure",
  cols    = c("#1f77b4", "#ff7f0e", "#2ca02c"),
  showGrid = FALSE
)
```

## Life-Stress Relationship Plot

`plotly_rel()` displays how characteristic life (eta for Weibull, median life for lognormal) changes with stress level, along with the fitted Arrhenius or Power Law relationship.

```{r rel-plot}
plotly_rel(obj)
```

The plot includes:

- **Points** (×) — characteristic-life estimates from parallel fits at each stress level
- **Red line** — fitted life-stress relationship (Arrhenius or Power Law)
- **Dashed blue lines** — percentile bands (10th and 90th by default)

### Percentile Bands

Use the `percentiles` argument to change which percentile bands are shown:

```{r rel-percentiles}
plotly_rel(obj, percentiles = c(5, 50, 95))
```

### Hiding Percentile Lines

Set `showPerc = FALSE` to show only the fitted relationship line:

```{r rel-no-perc}
plotly_rel(obj, showPerc = FALSE)
```

### Customization

```{r rel-custom}
plotly_rel(
  obj,
  main    = "Arrhenius Life-Stress Relationship",
  fitCol  = "darkgreen",
  percCol = "steelblue",
  signif  = 4
)
```

## References

## See Also

- [Life Data Analysis](weibull.html) — fit Weibull/lognormal models at a single stress level
- [Reliability Growth Analysis](rga.html) — track reliability improvement over time
- [Repairable Systems Analysis](repairable.html) — analyze recurrent events with MCF and NHPP models
