---
title: "Reliability, Availability, and Maintainability (RAM)"
output: 
  learnr::tutorial:
    progressive: true
    allow_skip: true
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
library(WeibullR.learnr)
```

## Introduction

Welcome to the tutorial on **Reliability, Availability, and Maintainability (RAM)**! In this tutorial, you will learn about these fundamental concepts and their applications.

## Learning Objectives

By the end of this module, learners will be able to:

* Define key reliability metrics, including reliability, availability, and failure rate.
* Describe the significance of MTTR, MTTF, and MTBF in reliability engineering.
* Calculate probability of failure using given reliability data.
* Interpret $B_n$ or $L_n$ life values in the context of product reliability.
* Differentiate between different reliability measures.

## What is RAM?

The terms Reliability, Availability, and Maintainability are related but distinct concepts.

**Reliability**: The ability of an item to perform its intended function without failure over a specified period.

**Availability**: The proportion of time an item is in a functioning condition.

**Maintainability**: The ease and speed with which an item can be restored to operational status after a failure.

These concepts are interrelated in the sense that a highly reliable item is likely to be available more often, and an item that is easy to maintain can be restored to service quickly, thus improving availability.

## Reliability

Reliability is the probability that an item will not fail under defined conditions for a specified period. Specifically, reliability is defined as:

$$ Reliability = (1 - (Failed Time/Total Time))*100 $$
Where Failed Time is the time that the item was not functioning, and Total Time is the total time that the item was in operation.

For example, suppose a motor ran for 5 years total and was failed for 10 of those days. The reliability of the motor is: 

$$ Reliability = (1 - (10/(5*365)))*100 = 94.5% $$
So, the motor has a reliability of 94.5% over the 5-year period.

Unreliability is the opposite of reliability, that is, the probability that an item _will_ fail under defined conditions for a specified period. Unreliability is defined as:

$$ Unreliability = 1 - Reliability = (Failed Time/Total Time)*100 $$
Take the previous example, the unreliability of the motor is:

$$ Unreliability = 1 - 0.945 = 0.055 = (10/(5*365))*100 = 5.5% $$
The motor has an unreliability of 5.5% over the 5-year period.

```{r quiz1, echo=FALSE}
quiz(caption = "Exercise: Reliability", 
  question("A machine has run for 3 years total and was failed for 5 of those days. What is the reliability of the machine?",
    answer("90%", message = "Not quite, try again."),
    answer("0.5%", message = "0.5% is the unreliability, not the reliability."),
    answer("99.5%", correct = TRUE),
    answer("75%", message = "Not quite, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("What is the unreliability of the machine?",
    answer("0.5%", correct = TRUE),
    answer("90%", message = "Not quite, try again."),
    answer("99.5%", message = "99.5% is the reliability, not the unreliability."),
    answer("75%", message = "Not quite, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  )
)
```

## Availability

Availability is the probability that an item will be available for service. Unavailable time includes failed time and scheduled maintenance. Specifically, availability is defined as:

$$ Availability = (1 - (Unavailable Time/Total Time))*100 $$
Where Unavailable Time is the time that the item was not available for service, and Total Time is the total time that the item was in operation.

Unavailable time is different than standby time, where standby time is when the item is available for service, but is not being used. 

Suppose a motor ran for 5 years total, was failed for 10 days, and had scheduled maintenance for 15 days. The availability of the motor is:

$$ Availability = (1 - ((10+15)/(5*365)))*100 = 93.2% $$
So the motor has an availability of 93.2% over the 5-year period.

```{r availability, echo=FALSE}
quiz(caption = "Exercise: Availability",
     question("What is the difference between reliability and availability?",
       answer("Reliability includes scheduled maintenance, availability does not.", message = "Not quite, try again."),
       answer("Availability includes scheduled maintenance, reliability does not.", correct = TRUE),
       answer("There is no difference, they are the same.", message = "There is a slight difference, try again."),
       answer("Reliability is always larger than availability.", message = "Not always, try again."),
       random_answer_order = TRUE,
       allow_retry = TRUE
     ),
  question("A machine has run for 3 years total, was failed for 5 days, and had scheduled maintenance for 14 days. What is the availability of the machine?",
    answer("95%", message = "Not quite, try again."),
    answer("1.7%", message = "1.7% is too low, try again."),
    answer("98.3%", correct = TRUE),
    answer("50%", message = "50% is too low, try again."),
    random_answer_order = TRUE,
  allow_retry = TRUE
  )
)
```

## Mean Time to Repair

The Mean Time to Repair (MTTR) is a measure of maintainability and is defined as the average time required to repair a failed item. The MTTR is the ratio of total repair time by the number of repairs for a given item.

$$ MTTR = \sum_{i=1}^n RepairTime_i/RepairCount $$
Where $RepairTime_i$ is the time to repair for the *i*th repair, and $RepairCount$ is the total number of repairs.

Suppose 100 motors run for 5 years total. During that time, 5 failures occur with repair times in days of 5, 10, 15, 8, and 12. The MTTR is:

$$ MTTR = (5+10+15+8+12)/5 = 10 days $$

```{r quiz3, echo=FALSE}
quiz(caption = "Exercise: MTTR",
  question("What does MTTR stand for?",
    answer("Mean Time to Recovery", message = "Not quite, try again."),
    answer("Mean Time to Repair", correct = TRUE),
    answer("Mean Time to Reliability", message = "Not quite, try again."),
    answer("Mean Time to Reboot", message = "Not quite, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("1000 motors run for 3 years total. During that time, 5 failures occur with repair times in days of 5, 10, 15, 8, and 12. What is the MTTR?",
    answer("15 days", message = "15 days is too high, try again."),
    answer("5 days", message = "5 days is too low, try again."),
    answer("10 days", correct = TRUE),
    answer("8 days", message = "8 days is too low, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  )
)
```

## Mean Time to Failure

The Mean Time to Failure (MTTF) is a measure of the reliability for *non-repairable* items, meaning that once the item fails, it is not repaired, but replaced. The MTTF is the ratio of total time by the number of failures for a given item.

$$ MTTF = Total Time/FailureCount $$
Where *Total Time* is the total time that the item was in operation, and *FailureCount* is the total number of failures.

For example, suppose 100 motors run for 5 years total. During that time, 5 failures occur. The MTTF is:

$$ MTTF = (5*100)/5 = 100 years $$
An MTTF of 100 years means that, on average, a single motor is expected to run for 100 years before failing. This may seem high, but remember that this is an average across all motors, and some motors may fail much sooner while others may last much longer. 

## Mean Time Between Failures

Mean Time Between Failures (MTBF) is a measure of the reliability for *repairable systems*, meaning that once the item fails, it is repaired and put back into service. In this way, the item can fail multiple times. The MTBF is the ratio of total time by the number of failures for a given item.

The calculation is similar to the MTTF, just with a slightly different interpretation. 

Take an example where a motor fails 5 times during a total time of 10,000 hours. The MTBF is:

$$ MTBF = 10000/5 = 2000 hours $$
An MTBF of 2000 hours means that, on average, the motor is expected to run for 2000 hours between failures.

```{r quiz4, echo=FALSE}
quiz(caption = "Exercise: MTTF and MTBF",
  question("What is the difference between MTTF and MTBF?",
    answer("MTTF is for repairable systems, MTBF is for non-repairable systems.", message = "Not quite, try again."),
    answer("MTTF is for non-repairable items, MTBF is for repairable systems.", correct = TRUE),
    answer("There is no difference, they are the same.", message = "There is a slight difference, try again."),
    answer("MTTF is always larger than MTBF.", message = "Not always, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("1000 motors run for 3 years total. During that time, 5 failures occur. What is the MTTF?",
    answer("200 years", message = "200 years is too low, try again."),
    answer("0.6 years", message = "0.6 years is too low, try again."),
    answer("600 years", correct = TRUE),
    answer("500 years", message = "500 years is slightly too low, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("A machine fails 5 times during a total time of 45,000 hours. What is the MTBF of the machine?",
    answer("0.0001 hours", message = "0.0001 hours is the failure rate, not the MTBF."),
    answer("10000 hours", message = "10000 hours is too low, try again."),
    answer("9000 hours", correct = TRUE),
    answer("225,000 hours", message = "225,000 hours is too high, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  )
)
```

## Failure Rate

The failure rate is the ratio of the number of failures by the total operational time for a given item and a specified period. Since the MTBF is the ratio of total time by the number of failures, the failure rate is the inverse of the MTBF. Specifically, the failure rate is defined as:

$$ \lambda = 1/MTBF $$
Where $\lambda$ is the failure rate.

The failure rate can also be calculated directly as the number of failures divided by the total operational time.

$$ \lambda = FailureCount/Total Time $$
Where *Total Time* is the total time that the item was in operation, and *FailureCount* is the total number of failures.

A key assumption of MTBF is that the failure rate is constant, meaning that the item has the same probability of failing at any time during its operation. In practice, this is not always true, as items may have higher failure rates at the beginning or end of their life. However, for many items, the constant failure rate assumption is a reasonable approximation.

To illustrate, suppose 100 motors run for 10 years total. During that time, 20 failures occur. The failure rate is:

$$ \lambda = 20/(10*100) = 0.0055 \text{ failures per year} $$
A failure rate of 0.0055 failures per year means that, on average, there are 0.0055 failures for every motor per year of operation.

## Probability of Failure

Failures do not often occur at predictable times and often occur randomly according to a probability distribution. A common assumption is that failures occur according to a Poisson process, meaning that the number of failures in a given time period follows a Poisson distribution. When failures follow a Poisson process, the time between failures follows an Exponential distribution.

For an exponential distribution, the probability of failure prior to time *t* can be calculated using the cumulative distribution function (CDF) of the exponential distribution. Specifically, the cumulative probability of *failure* prior to time *t*, ***F(t)***, is given by:

$$ F(t) = 1 - e^{-t\lambda} $$
Where $\lambda$ is the failure rate.

The cumulative probability of *survival* prior to time *t*, ***R(t)***, is the opposite of ***F(t)***, that is

$$ R(t) = 1 - F(t) $$
$$ R(t) = e^{-t\lambda} $$

For example, suppose a motor has a failure rate of 0.1 failures per year. The probability of survival at time 10 is:

$$ R(10) = e^{-10*0.1} = 0.3679 = 36.79% $$
So, there is a 36.79% chance that the motor will survive for 10 years without failing or a 63.21% chance that it will fail before 10 years.

## $B_n$ or $L_n$ Life

The $B_n$ life is defined as the time at which *n* % of a population are expected to fail (or 1-*n* % are expected to survive). For example, the B10 life is the time at which 10% of a population are expected to fail, B90 is when 90% are expected to fail, and so on. Some industries use the term $L_n$ life instead of $B_n$ life, but they are the same concept.

To calculate the $B_n$ life, we can solve for time *t* in the cumulative distribution function (CDF) of the exponential distribution. Specifically, we set ***F(t)*** equal to *n* % and solve for *t*.


$$ t = -ln(1-F(t))/\lambda $$

For example, suppose a factor motor has a failure rate of 0.2 failures per year. The B10 life is:

$$ B10 = -ln(1-0.1)/0.2 = 0.526 years $$
So at the B10 life of 0.526 years, 10% of the motors are expected to have failed.

```{r quiz5, echo=FALSE}
quiz(caption = "Exercise: Failure Rate, Probability of Failure, and Bn Life",
  question("What is the relationship between failure rate and MTBF?",
    answer("Failure rate is the square of MTBF.", message = "Not quite, try again."),
    answer("Failure rate is the inverse of MTBF.", correct = TRUE),
    answer("Failure rate is the same as MTBF.", message = "Not quite, try again."),
    answer("Failure rate is the logarithm of MTBF.", message = "Not quite, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("100 motors run for a total time of 5000 hours in a year. Out of these motors, 75 have failures. What is the failure rate in hours?",
    answer("0.75", message = "0.75 is too high, try again."),
    answer("6667", message = "6667 is too high, try again."),
    answer("0.00015", correct = TRUE),
    answer("0.015", message = "0.015 is too high, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("A machine has a failure probability that follows the exponential distribution with a failure rate of 0.1. What is the probability of survival at time 5?",
    answer("39.3%", message = "39.3% is the failure probability, not the survival probability."),
    answer("60.7%", correct = TRUE),
    answer("6.1%", message = "6.1% is too low, try again."),
    answer("93.9%", message = "93.9% is too high, try again."),
    random_answer_order = TRUE,
    allow_retry = TRUE
  ),
  question("A machine has a failure probability that follows the exponential distribution with a failure rate of 0.1. What is the B10?",
    answer("0.105", message = "0.105 is too low, try again."),
    answer("1.05", correct = TRUE),
    answer("60.7%", message = "60.7% is a probability, not a time."),
    answer("39.3%", message = "39.3% is a probability, not a time."),
    random_answer_order = TRUE
  )
)
```

## Summary

Congratulations on completing the Reliability, Availability, and Maintainability (RAM) tutorial!

In this tutorial, we've introduced the concepts of Reliability, Availability, and Maintainability. You have learned to calculate reliability using different assumptions and explored the importance of these concepts in system design.

## References

- Abernethy, R.B. (2004) The New Weibull Handbook. Fifth Edition.

- Aden-Buie G, Schloerke B, Allaire J, Rossell Hayes A (2023). learnr: Interactive Tutorials for R. https://rstudio.github.io/learnr/, https://github.com/rstudio/learnr.

