---
title: "An Efficient eM-Algorithm for One-Shot Device Data Analysis"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{An Efficient eM-Algorithm for One-Shot Device Data Analysis}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo = TRUE,
  warning = FALSE,
  message = FALSE
)
library(OneShotEM)
```

## 1. Introduction

One-shot devices (e.g., electro-explosive devices, automotive airbags, fire extinguishers, and missiles) can be tested only once. Upon testing, the device is either destroyed or rendered unusable, yielding binary status data: whether the device was functional or failed at the inspection time.

To evaluate device reliability under operating conditions in a reasonable timeframe, Accelerated Life Testing (ALT) is commonly used. The **`OneShotEM`** package implements the simple and efficient Expectation-Maximization (eM) algorithm proposed by **Zhu, Li, Li, and Balakrishnan (2026)** (*Communications in Statistics - Simulation and Computation*, doi:10.1080/03610918.2025.2515193).

### Key Innovation of the New eM-Algorithm
Traditional EM algorithms for one-shot device data treat exact failure times as missing data. In contrast, the new eM-algorithm proposed by Zhu et al. (2026) treats **the counts of failures occurring between successive inspection intervals** as missing data. This structural shift provides:
- **Faster Convergence**: Reduces iteration counts by 30% to 70%.
- **Guaranteed Convergence**: Avoids numerical divergence because all interval probabilities remain bounded between 0 and 1.
- **Robust Estimation**: Provides lower standard errors and consistent maximum likelihood estimation.

---

## 2. Example: Electro-Explosive Device Analysis

We illustrate the package using the electro-explosive device ALT dataset reported by Fan et al. (2009) and analyzed in Zhu et al. (2026).

```{r data-example}
data(electro_explosive)
print(electro_explosive)
```

The dataset contains testing results across 3 temperature levels (35°C, 45°C, 55°C) and 3 inspection times (10, 20, 30 hours), with 10 devices tested per condition (total $N = 90$).

---

## 3. Exponential Lifetime Model

We fit an exponential lifetime distribution where the scale parameter follows a log-linear model: $\log(\beta_j) = \theta_0 + \theta_1 \cdot \text{temp}_j$.

```{r exp-fit}
fit_exp <- oneshot_em(
  formula = cbind(r, n) ~ temp,
  data = electro_explosive,
  it = "it",
  dist = "exponential"
)

summary(fit_exp)
```

---

## 4. Weibull Lifetime Model

We fit a Weibull model with shape parameter $a$ and scale parameter $\beta_j = \exp(\theta_0 + \theta_1 \cdot \text{temp}_j)$.

```{r weibull-fit}
fit_weibull <- oneshot_em(
  formula = cbind(r, n) ~ temp,
  data = electro_explosive,
  it = "it",
  dist = "weibull"
)

summary(fit_weibull)
```

---

## 5. Comparison: New eM-Algorithm vs Traditional EM

We compare the convergence speed of the new eM-algorithm (`npm`) against the traditional EM approach (`tm`).

```{r compare-fit}
fit_npm <- oneshot_fit(cbind(r, n) ~ temp, data = electro_explosive, it = "it", dist = "weibull", method = "npm")
fit_tm  <- oneshot_fit(cbind(r, n) ~ temp, data = electro_explosive, it = "it", dist = "weibull", method = "tm")

cat("New eM-Algorithm Iterations: ", fit_npm$iterations, "\n")
cat("Traditional EM Iterations:   ", fit_tm$iterations, "\n")
```

As demonstrated in Zhu et al. (2026), the new eM-algorithm converges in significantly fewer iterations.

---

## 6. Visualization and Residual Diagnostics

Fitted survival probabilities and model diagnostics can be visualized easily:

```{r plotting, fig.width = 6, fig.height = 4}
plot(fit_weibull, type = "fitted")
plot(fit_weibull, type = "survival")
```

---

## 7. References

1. Zhu, X., Li, Y., Li, T., & Balakrishnan, N. (2026). A simple and efficient eM-algorithm for one-shot device data analysis. *Communications in Statistics - Simulation and Computation*, 55(3), 959–970. doi:10.1080/03610918.2025.2515193
2. Balakrishnan, N., & Ling, M. (2012). EM algorithm for one-shot device testing under the exponential distribution. *Computational Statistics & Data Analysis*, 56(3), 502–509.
3. Fan, T., Balakrishnan, N., & Chang, C. (2009). The Bayesian approach for highly reliable electro-explosive devices using one-shot device testing. *Journal of Statistical Computation and Simulation*, 79(9), 1143–1154.
