> For the complete documentation index, see [llms.txt](https://zavalab.gitbook.io/statschemebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zavalab.gitbook.io/statschemebook/chapter-3-multivariate-random-variables/03-marginal-pdfs.md).

# Marginal PDFs

* Want probs for $$X\_1$$ *regardless* of what value $$X\_2$$ takes (and other way around).
* Probs are obtained from *marginal pdfs*. For continuous RV:

  $$
  \begin{aligned}
  f\_1(x\_1)&=\int\_{x\_2\in \mathcal{D}\_2}f(x\_1,x\_2)dx\_2,; x\_1\in \mathcal{D}*1\\
  f\_2(x\_2)&=\int*{x\_1\in \mathcal{D}\_1}f(x\_1,x\_2)dx\_1,; x\_2\in \mathcal{D}\_2
  \end{aligned}
  $$
* Marginal pdfs are obtained by “integrating out” effect of the RV that we ignore.
* Consider we want $$\mathbb{P}(X\_1\in \mathcal{A}\_1)$$ regardless of what value $$X\_2$$ takes. This is:

  $$
  \begin{aligned}
  \mathbb{P}(X\_1\in \mathcal{A}*1)&=\int*{x\_1\in \mathcal{A}*1}\overbrace{\int*{x\_2\in \mathcal{D}*2} f(x\_1,x\_2)dx\_2}^{f\_1(x\_1)}dx\_1\\
  &=\int*{x\_1\in \mathcal{A}\_1}f\_1(x\_1)dx\_1
  \end{aligned}
  $$
* Marginal pdfs $$f\_1(x\_1)$$ and $$f\_2(x\_2)$$ have associated marginal cdfs $$F\_1(x\_1),F\_2(x\_2)$$.

## Example: Lifetime of Thermostat

{% hint style="danger" icon="flask" %}

* Marginal pdf for $$X\_1$$ is obtained by integrating $$X\_2$$ out over $$\mathcal{D}\_2=\[0,\infty)$$:

  $$
  \begin{aligned}
  f\_1(x\_1)&=\int\_{0}^{\infty}f(x\_1,x\_2)dx\_2=\int\_{0}^{\infty}\left(\frac{1}{\mu\_1\cdot \mu\_2}e^{-(x\_1/\mu\_1+x\_2/\mu\_2)}\right)dx\_2\\
  &=\frac{1}{\mu\_1\cdot \mu\_2}e^{-x\_1/\mu\_1}\left(\int\_{0}^{\infty}e^{-x\_2/\mu\_2}dx\_2\right)=\frac{1}{\mu\_1}e^{-x\_1/\mu\_1}.
  \end{aligned}
  $$
* Applying a similar procedure we obtain:

  $$
  \begin{aligned}
  f\_2(x\_2)&=\frac{1}{\mu\_2}e^{-x\_2/\mu\_2}.
  \end{aligned}
  $$
  {% endhint %}

{% hint style="info" %}

* Marginal pdf and cdf of component lifetimes $$X\_1,X\_2$$.
* Compute prob that $$X\_1$$ survives after 1 year.
* Compute prob that $$X\_2$$ survives after 1 year.
  {% endhint %}

{% hint style="danger" icon="flask" %}

* Marginals are pdfs of exponential RVs with $$\mu\_1=1$$ and $$\mu\_2=10$$ years and thus:

  $$
  F\_1(x\_1)=1-e^{-x\_1/\mu\_1}; \qquad
  F\_2(x\_2)=1-e^{-x\_2/\mu\_2}.
  $$
* Probabilities that components survive after one year are:

  $$
  \begin{aligned}
  \mathbb{P}(X\_1\geq 1)&=1-F\_1(1)=e^{-1/1}=0.37\\
  \mathbb{P}(X\_2\geq 1)&=1-F\_2(1)=e^{-1/10}=0.90.
  \end{aligned}
  $$
  {% endhint %}

#### Python implementation: Marginal pdfs and survival

Integrating out the other variable, $$f\_1(x\_1)=\int\_0^\infty f(x\_1,x\_2)dx\_2=\frac{1}{\mu\_1}e^{-x\_1/\mu\_1}$$ (and similarly $$f\_2$$), so $$\mathbb{P}(X\_i\geq 1)=1-F\_i(1)=e^{-1/\mu\_i}$$.

```python
def f_1(x1):
    return quad(lambda x2: f(x1, x2), 0, np.inf)[0]

def f_2(x2):
    return quad(lambda x1: f(x1, x2), 0, np.inf)[0]

print(f"f_1(0.5) = {f_1(0.5):.4f}   vs (1/mu_1) e^(-0.5/mu_1) = {np.exp(-0.5/mu_1)/mu_1:.4f}")
F_1 = lambda x1: 1 - np.exp(-x1/mu_1)
F_2 = lambda x2: 1 - np.exp(-x2/mu_2)
print(f"P(X1 >= 1) = 1 - F_1(1) = {1 - F_1(1):.2f}")
print(f"P(X2 >= 1) = 1 - F_2(1) = {1 - F_2(1):.2f}")
```

```
f_1(0.5) = 0.6065   vs (1/mu_1) e^(-0.5/mu_1) = 0.6065
P(X1 >= 1) = 1 - F_1(1) = 0.37
P(X2 >= 1) = 1 - F_2(1) = 0.90
```
