---
title: "Reliability Growth Analysis"
output:
  html_vignette:
    fig_width: 7
    fig_height: 5
vignette: >
  %\VignetteIndexEntry{Reliability Growth Analysis}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

Reliability Growth Analysis (RGA) is a method to assess the reliability of systems or products during the development and testing phases. RGA tracks the rate at which reliability improves over time, typically as design changes, fixes, or process improvements are implemented. The primary objective is to measure the system or product's failure behavior and predict how it will perform once the product is fully mature or operational.

## The Crow-AMSAA Model

**The Crow-AMSAA** or **Non-Homogeneous Poisson Process (NHPP)** model is a statistical model used to track reliability improvements over time. This model is particularly useful for analyzing failure data in systems where the failure rate changes due to improvements or corrective actions during the development or operational phase.

### The Non-Homogeneous Poisson Process (NHPP):

In a NHPP, the failure rate changes over time, increasing or decreasing depending on actions taken to improve reliability. Failures follow a Poisson process, but the rate at which they occur changes with time, hence "non-homogeneous."

### The Power Law Model:

The failure intensity (rate of failures per time unit) is modeled as a power function of time:

\[
\lambda(t) = \beta \cdot t^{\beta - 1}
\]
 
where:

* \( \lambda(t) \) is the failure intensity at time \( t \),
* \( \beta \) is the shape parameter,
* \( t \) is the time.

The cumulative number of failures up to time \( t \) is given by:

\[
N(t) = \lambda_0 \cdot t^{\beta}
\]

Where:

* \( N(t) \) is the cumulative number of failures,
* \( \lambda_0 \) is the scale parameter.

### Parameters:

The Shape Parameter (\( \beta \)) indicates whether the system is improving or deteriorating:

* If \( \beta \) > 1, failures are increasing over time, indicating that reliability is worsening.

* If \( \beta \) < 1, failures are decreasing, indicating that reliability is improving over time.

* \( \beta \) = 1 implies a constant failure rate (no growth or degradation).

* The Scale Parameter (\( \lambda_0 \)) is related to the initial failure rate.

### Example

First, load the package:
```{r}
library(ReliaGrowR)
```

Next, set up some cumulative time and failure data:
```{r}
times <- c(100, 200, 300, 400, 500)
failures <- c(1, 2, 1, 3, 2)
```

Then run the rga and plot the results:
```{r}
result <- rga(times, failures)
plot_rga(result)
```

## The Piecewise Weibull NHPP Model

The **Piecewise Weibull NHPP** model is an extension of the standard NHPP model that includes different segments or phases of time that follow separate Weibull failure distributions. This model is particularly useful when a system experiences changes in failure behavior over different development phases, such as the initial, interim and final phases of a development process.

### The Weibull Distribution

The Weibull intensity function for each time segment \(i\) is modeled as:

\[
\lambda_i(t) = \frac{\beta_i}{\eta_i} \left( \frac{t - t_{i-1}}{\eta_i} \right)^{\beta_i - 1}
\]

Where:

* \( \lambda_i(t) \) is the failure intensity in time interval \( i \),
* \( \beta_i \) is the shape parameter for interval \( i \),
* \( \eta_i \) is the scale parameter (characteristic life) for interval \( i \),
* \( t_{i-1} \) is the start time of the interval.

### Example

First, set up some cumulative time/failure data and specify the breakpoint:
```{r}
times <- c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
failures <- c(1, 2, 1, 1, 1, 2, 3, 1, 2, 4)
breakpoints <- 400
```

Then run the rga and plot the results:
```{r}
result <- rga(times, failures, model_type = "Piecewise Weibull NHPP", breakpoints = breakpoints)
plot_rga(result)
```

## The Piecewise Weibull NHPP with Change Point Detection

The **Piecewise Weibull NHPP with Change Point Detection** is an advanced model to identify changes in failure behavior and model system reliability. This method builds on the Piecewise Weibull NHPP model by introducing the concept of change points, which represent the time when the underlying failure behavior changes. Detection of change points involves statistical techniques that analyze failure data to automatically identify when the behavior changes, allowing for a more precise segmentation of the model into different Weibull distributions.

### Example

First, set up some cumulative time and failure data:
```{r}
times <- c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
failures <- c(1, 2, 1, 1, 1, 2, 3, 1, 2, 4)
```

Then run the rga and plot the results:
```{r}
result <- rga(times, failures, model_type = "Piecewise Weibull NHPP")
plot_rga(result)
```

## The Duane Model

The **Duane Model** is another graphical method to track and visualize the reliability improvement of a product or system over time. The Duane Plot is a log-log plot that shows the cumulative failure rate or Mean Time Between Failures (MTBF) versus time, helping to assess whether reliability is improving, stabilizing, or worsening over time.

### Example

First, set up some cumulative time and failure data:
```{r}
times <- c(100, 200, 300, 400, 500)
failures <- c(1, 2, 1, 3, 2)
```

Then plot the results:
```{r}
fit <- duane_plot(times, failures)
```

## Summary 

RGA provides a quantitative framework for understanding how a system's reliability changes over time and guides decisions for further improvements based on observed failure patterns.
