> 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/05-independence.md).

# Independence

Conditional pdfs tell us how knowledge in one RV resolves uncertainty in another (i.e., how much knowledge of one is embedded in the other).

{% hint style="info" %}
So what if knowledge of one does not resolve uncertainty of the other?

This gives rise to concept of *independence*.
{% endhint %}

* RVs $$X\_1$$ and $$X\_2$$ are said to be independent if:

  $$
  \begin{aligned}
  f(x\_1|x\_2)&=f\_1(x\_1),; x\_1\in \mathcal{D}\_1\\
  f(x\_2|x\_1)&=f\_2(x\_2),; x\_2\in \mathcal{D}\_2
  \end{aligned}
  $$
* This implies that:

  $$
  {f(x\_1,x\_2)}={f\_2(x\_2)}f\_1(x\_1),\quad (x\_1,x\_2)\in \mathcal{D}
  $$
* For discrete $$X$$ this is equivalent to:

  $$
  \begin{aligned}
  \mathbb{P}(X\_1=x\_1,&,X\_2=x\_2)=\mathbb{P}(X\_1=x\_1)\mathbb{P}(X\_2=x\_2)
  \end{aligned}
  $$
* For continuous $$X$$ this is interpreted in infinitesimal sense.

## Example: Lifetime of Thermostat

Consider the thermostat example and address the following:

{% hint style="info" %}

* Prove that lifetimes $$X\_1$$ and $$X\_2$$ are independent and provide a physical explanation.

* Prove that joint cdf is the product of marginal cdfs.
  {% endhint %}

* Condition for independence is $$f(x\_1,x\_2)=f\_1(x\_1)f\_2(x\_2)$$.

* From previous examples we have that:

  $$
  \begin{aligned}
  f(x\_1,x\_2)&=\frac{1}{\mu\_1\cdot \mu\_2}e^{-(x\_1/\mu\_1+x\_2/\mu\_2)}=\left(\frac{1}{\mu\_1}e^{-x\_1/\mu\_1}\right)\left(\frac{1}{\mu\_2}e^{-x\_2/\mu\_2}\right),
  \end{aligned}
  $$

  and,

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

* Failure of components might be independent if they do not interact physically.

* Joint cdf is $$F(x\_1,x\_2)=(1-e^{-x\_1/\mu\_1})(1-e^{-x\_2/\mu\_2})$$ and marginals are $$F\_1(x\_1)=1-e^{-x\_1/\mu\_1}$$ and $$F\_2(x\_2)=1-e^{-x\_2/\mu\_2}$$.

* We thus have $$F(x\_1,x\_2)=F\_1(x\_1)\cdot F\_2(x\_2)$$ and this implies $$\mathbb{P}(X\_1\leq x\_1; & ;X\_2\leq x\_2)=\mathbb{P}(X\_1\leq x\_1)\cdot \mathbb{P}(X\_2\leq x\_2)$$.

#### Python implementation: Independence

$$X\_1,X\_2$$ are independent if $$f(x\_1,x\_2)=f\_1(x\_1)f\_2(x\_2)$$; then $$F(x\_1,x\_2)=F\_1(x\_1)F\_2(x\_2)$$.

```python
x1_grid, x2_grid = np.meshgrid(np.linspace(0, 5, 6), np.linspace(0, 30, 7))
gap_pdf = np.max(np.abs(f(x1_grid, x2_grid) - np.exp(-x1_grid/mu_1)/mu_1 * np.exp(-x2_grid/mu_2)/mu_2))
gap_cdf = np.max(np.abs(F(x1_grid, x2_grid) - F_1(x1_grid) * F_2(x2_grid)))
print(f"max |f - f_1 f_2| = {gap_pdf:.1e},   max |F - F_1 F_2| = {gap_cdf:.1e}")
```

```
max |f - f_1 f_2| = 3.5e-18,   max |F - F_1 F_2| = 0.0e+00
```
