Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Probability-Statistics-Jupy…
GitHub Repository: Probability-Statistics-Jupyter-Notebook/probability-statistics-notebook
Path: blob/master/notebook-for-learning/Chapter-1-Probability-Theory.ipynb
388 views
Kernel: Python 3
''' Import here useful libraries Run this cell first for convenience ''' import numpy as np from scipy import stats import scipy import warnings warnings.simplefilter('ignore', DeprecationWarning)

Chapter 1 - Probability Theory

Probabilities

Introduction

  • Statistics and probability theory constitute a branch of mathematics for dealing with uncertainty. The probability theory provides a basis for the science of statistical inference from data

  • Sample: (of size n) obtained from a mother population assumed to be represented by a probability

  • Descriptive statistics: description of the sample

  • Inferential statistics: making a decision or an inference from a sample of our problem

Sample Spaces

  • Experiment: any process or procedure for which more than one outcome is possible

  • Sample Space: set of all the possible experimental outcomes

Probability Values

A set of probability values for an experiment with sample space S={O1,O2,,On}S = \{ O_1, O_2, \cdots, O_n \} consists of some probabilities that satisfy: 0pi1,i=1,2,,n\begin{equation} 0 \leq p_i \leq 1, \hspace{0.5cm} i= 1,2, \cdots, n \end{equation} and p1+p2++pn=1\begin{equation} p_1 +p_2 + \cdots +p_n = 1 \end{equation} The probability of outcome OiO_i occurring is said to be pip_i and it is written: P(Oi)=pi\begin{equation} P(O_i) = p_i \end{equation} In cases in which the nn outcomes are equally likely, then each probability will have a value of 1/n1/n.

Events

Events and Complements

  • Events: subset of the sample space

  • The probability of an event AA, P(A)P(A), is obtained by the probabilities of the outcomes contained withing the event AA

  • An event is said to occur if one of the outcomes contained within the event occurs

  • Complement of events: event A A' is the event consisting of everything in the sample space SS that is not contained within AA P(A)+P(A)=1\begin{equation} P(A) + P(A ') = 1 \end{equation}

  • Elementary (or simple) event: event consisting of an individual outcome

Combinations of Events

Intersections of Events

  • Intersections of Events: ABA \cap B consists of the outcomes contained within both events AA and BB

  • Probability of the intersection, P(AB)P(A \cap B) , is the probability that both events occur simultaneously

  • Properties:

    • P(AB)+P(AB)=P(A)P(A \cap B) +P(A \cap B') = P(A)

    • Mutually exclusive events: if AB=A \cap B = \emptyset

    • A(BC)=(AB)CA \cap (B \cap C) = (A \cap B) \cap C

Union of Events

  • Union of Events: AB A \cup B consists of the outcomes that are contained within at least one of the events AA and BB

  • The probability of this event, P(AB)P (A \cup B) is the probability that at least one of these events AA and BB occurs

  • Properties

    • P(AB)=P(AB)+P(AB)+P(AB)P( A \cup B) = P(A \cap B') + P(A' \cap B') + P(A \cap B)

    • If the events are mutually exclusive, then P(AB)=P(A)+P(B)P(A \cup B) = P(A) + P(B)

  • Other simple results:

    • (AB)=AB(A \cup B)' = A' \cap B'

    • (AB)=AB(A \cap B)' = A' \cup B'

    • AA=SA \cup A' = S

    • A(BC)=(AB)CA \cup (B \cup C) = (A \cup B) \cup C

Combinations of Three or More Events

  • P(ABC)=P(A)+P(B)+P(C)P(AB)P(BC)P(AC)+P(ABC) P(A \cup B \cup C) = P(A) + P(B) + P(C) - P(A \cap B) - P( B \cap C) - P( A \cap C) + P(A \cap B \cap C)

  • Union of Mutually Exclusive Events: given a sequence A1,A2,,AnA_1, A_2, \cdots , A_n of mutually exclusive events: P(A1A2An)=P(A1)++P(An)\begin{equation} P(A_1 \cup A_2 \cup \cdots \cup A_n) = P(A_1) + \cdots + P(A_n) \end{equation}

  • Partition of sample space S: given a sequence A1,A2,,AnA_1, A_2, \cdots , A_n of mutually exclusive events such that A1A2An=SA_1 \cup A_2 \cup \cdots \cup A_n = S is called a partition of S

Conditional Probability

Definition of Conditional Probability

  • Conditional Probability: of an event AA conditional on an event BB is: P(AB)=P(AB)P(B)for P(B)>0\begin{equation} P(A \mid B) = \frac{P(A \cap B)}{P(B)} \hspace{0.5cm} \text{for } P(B) >0 \end{equation}

Probabilities of Event Intersections

General Multiplication Law

  • P(AB)=P(AB)P(B)P(AB)=P(B)P(AB)P (A \mid B) = \frac{P(A \cap B)}{P(B)} \\ \Longrightarrow P(A \cap B) = P(B)P (A \mid B)

  • P(ABC)=P(ABC)P(BC)P(ABC)=P(BC)P(ABC)P (A \mid B \cap C) = \frac{P(A \cap B \cap C)}{P(B \cap C)} \\ \Longrightarrow P(A \cap B \cap C) = P(B \cap C)P (A \mid B \cap C)

  • In general, for a sequence of events A1,A2,,UntitledAnA_1, A_2, \cdots,Untitled A_n: P(A1,A2,,An)=P(A1)P(A2A1)P(A3A1A2)P(AnA1An1)\begin{equation} P(A_1, A_2, \cdots, A_n) = P(A_1)P(A_2 \mid A_1)P(A_3 \mid A_1 \cap A_2) \cdots P(A_n \mid A_1 \cap \cdots \cap A_{n-1}) \end{equation}

Independent Events

  • Two events AA and BB are independent if:

    1. P(AB)=P(A)P(A \mid B) = P(A)

    2. P(BA)=P(B)P(B \mid A) = P(B)

    3. P(AB)=P(A)P(B)P(A \cap B) = P(A)P(B)

  • These conditions are also equivalent

  • Interpretation: events are independent if the knowledge about one event does not affect the probability of the other event

  • Mutual independence: A1,A2,,AnA_1, A_2, \cdots, A_n are mutually independent if for any subset {j1,j2,,jk},kn,of {1,2,,n} \{ j_1, j_2, \cdots, j_k \}, k \leq n, \text{of } \{ 1, 2, \cdots, n \} : P(Aj1,Aj2,,Ajk=P(Aj1)P(Aj2)P(Ajk)\begin{equation} P(A_{j_1}, A_{j_2}, \cdots, A_{j_k} = P(A_{j_1})P(A_{j_2}) \cdots P(A_{j_k}) \end{equation}

  • Pairwise independence: the events A1,A2,,AnA_1, A_2, \cdots, A_n satisfying: P(AiAj)=P(Ai)P(Aj) for all i,j{1,2,,n} with ij\begin{equation} P(A_i \cap A_j) = P(A_i)P(A_j) \text{ for all } i, j \in \{1, 2, \cdots, n \} \text{ with } i \neq j \end{equation}

Posterior Probabilities

Law of Total Probability

  • Given {A1,A2,,An}\{ A_1, A_2, \cdots, A_n \} a partition of sample space SS, the probability of an event BB, P(B)P(B) can be expressed as: P(B)=i=1nP(Ai)P(BAi)\begin{equation} P(B) = \sum_{i=1}^n P(A_i)P(B \mid A_i) \end{equation}

Bayes' Theorem

  • Given {A1,A2,,An}\{ A_1, A_2, \cdots, A_n \} a partition of a sample space, then the posterior probabilities of the event AiA_i conditional on an event BB can be obtained from the probabilities P(Ai)P(A_i) and P(AiB)P(A_i \mid B) using the formula: P(AiB)=P(Ai)P(BAi)j=1nP(Aj)P(BAj)\begin{equation} P(A_i \mid B) = \frac{P(A_i)P(B \mid A_i)}{\sum_{j=1}^n P(A_j)P(B \mid A_j)} \end{equation}