Week-9 (11/06) Total Probability with Baye’s rule.

The idea of “total probability” is a fundamental principle in statistics and probability theory used to determine the likelihood of an occurrence by considering all conceivable ways or scenarios in which the event may occur. It is frequently employed when you have knowledge of the likelihood of an event occurring under various settings or scenarios. The law of total probability, a specific application of this notion, is closely connected to total probability.

According to the law of total probability, if the sample space is divided into mutually exclusive and exhaustive events (i.e., events that cover all possible outcomes and do not overlap), the probability of any event can be expressed as a weighted sum of the conditional probabilities of that event given the various scenarios.

Mathematically, for an event A and a partition of the sample space into events B1, B2, B3,… Bn
the law of total probability is expressed as:

Where:
P(A) is the probability of event (A).
P(A|Bi) is the conditional probability of an event P( given that the event P( has occurred.
is the probability of an event P( (part of the partition).

The basic concept is to analyze all alternative scenarios (represented by the many events in the partition), compute the conditional probabilities for the event of interest within each scenario, and then weight these conditional probabilities by the likelihood of each scenario occurring. The overall probability of the occurrence P(A) is obtained by adding these weighted conditional probabilities.

Bayes rule:
Total probability is connected to Bayes’ Rule and is frequently used in combination with it to update probabilities in the presence of uncertainty or new information. The denominator in Bayes’ Rule is computed using total probability, which is critical for updating the conditional probability of a hypothesis depending on new information.

The rule of total probability is employed in this situation to account for all alternative scenarios or hypotheses P(Hi), allowing you to compute the total probability of the evidence P(E) by summing over all these possibilities. This is significant because P(E) is the normalization factor in Bayes’ Rule, guaranteeing that the posterior probabilities are appropriately scaled.

Week-8 (11/03) Baye’s theorem.

The Bayes’ theorem is a statistical and probability theory that may be used to analyze data in Python. It allows you to adjust probability or draw conclusions about events based on fresh facts or data. Bayes’ theorem is frequently employed in statistical contexts for Bayesian inference, which is a versatile and powerful framework for statistical modeling and parameter estimation.

Bayes’ theorem can be expressed as

Where
– (P(A|B)) is the conditional probability of event A given that event B has occurred.
– (P(B|A)) is the conditional probability of event B given that event A has occurred.
– (P(A)) is the prior probability of event A, which is your initial belief in the probability of A before considering any new evidence.
– (P(B)) is the prior probability of event B, which is your initial belief in the probability of B before considering any new evidence.

In the context of Python data analysis, Bayes’ theorem can be utilized for a variety of tasks, including:
Bayes’ theorem can be used to update your views about the parameters of a statistical model depending on observed data. This is especially handy if you know the settings ahead of time.
Hypothesis Testing: Bayesian hypothesis testing uses the posterior probability to analyze the evidence for or against a hypothesis.
Predictive Modeling: Bayesian approaches, such as Bayesian regression or Bayesian networks, can be utilized to develop predictive models that yield more robust predictions and uncertainty estimates.
The code generates two graphs to visualize the results of the Bayesian parameter estimation using the Metropolis-Hastings sampler.
Mean Estimation:

  • The first graph depicts the estimated values of the normal distribution’s mean during the Markov Chain Monte Carlo (MCMC) sampling procedure.
  • The sample number or iteration is represented on the x-axis, demonstrating how the parameter estimations change over time.
  • The calculated mean values are represented on the y-axis.
  • In this graph, you can see how the sampler investigates various mean values to locate the region with the highest posterior probability, which corresponds to the most likely mean value given the data.

Standard Deviation Estimation:

  • The second graph depicts the estimated values of the normal distribution’s standard deviation over the course of the MCMC sampling procedure.
  • The x-axis shows the sample number or iteration, while the y-axis represents the estimated standard deviation values, as in the first graph.
  • This graph depicts how the sampler investigates various standard deviation values in order to locate the region with the highest posterior probability, showing the most likely value of the standard deviation given the data.

    These graphs depict the parameter estimation process as well as the MCMC sampler’s convergence. The sampled values should stabilize as the number of samples rises, producing more accurate estimations of the parameters.
    This is done using the dummy data for learning purposes
    I’ll implement this in my project

Week-8 (11/01) confidence interval for Age and Race.

95% Confidence Interval

Based on the Washington data from the population, a range of values known as the 95% confidence interval for the population’s mean and variance is created. It offers some ambiguity regarding the actual population mean and variance values.

95% Confidence Interval for the Mean

Formula: Confidence Interval = Sample Mean ± Margin of Error
The sample size, sample standard deviation, and selected confidence level (in this example, 95%), all influence the margin of error.
If the population standard deviation is known (often denoted as σ), we can use the Z-distribution and the formula:
Margin of Error (Z-distribution)

Where:
Z is the critical value corresponding to a 95% confidence level (usually 1.96 for 95% confidence).
σ is the population standard deviation.
n is the sample size.

95% Confidence Interval for the Variance

To construct a 95% confidence interval for the population variance (σ^2), we use the Chi-squared distribution.
The formula for the confidence interval is

Where
n is the sample size.
s^2 is the sample variance.
χ^2_upper and χ^2_lower are the critical values of the Chi-squared distribution corresponding to the upper and lower tail

Moving towards the project

While plotting the graph for all 7 different types of race wrt to age and calculating the 95% CI
This is how it looked like with respect to mean age:

95% CI for mean age of Asian race: (34.102561714042324, 38.17163183434478)
95% CI for mean age of Black race: (32.2672685325096, 33.36063844423459)
95% CI for mean age of Hispanic race: (33.025105503719516, 34.26648662508191)
95% CI for mean age of Native American race: (31.171378988317556, 35.06775144646505)
95% CI for mean age of Other race: (28.60618586384799, 38.69381413615201)
95% CI for mean age of Unknown race: (39.27258057718045, 41.59356115510302)
95% CI for mean age of White race: (39.67225966058736, 40.5853739271989)

with respect to age variance:
95% CI for age variance of Asian race: (-40.85984853099225, 308.09024454462985)
95% CI for age variance of Black race: (-9.30460757975456, 270.24488620549687)
95% CI for age variance of Hispanic race: (-9.912485515846711, 234.15910188380138)
95% CI for age variance of Native American race: (-33.487313303846264, 215.28258325129013)
95% CI for age variance of Other race: (-150.1015458360546, 415.0015458360547)
95% CI for age variance of Unknown race: (-26.69241274796164, 471.92870773790173)
95% CI for age variance of White race: (-8.759132313413176, 349.9572418892791)

And the graph of Q-Q plot wrt to age distribution

These are just random figures posted from the lot and also go the information of stats age wrt to their race
Race: Unknown
Median: 38.00
Mean: 40.43
Standard Deviation: 14.92
Variance: 222.62
Skewness: 0.67
Kurtosis: 2.9363

Race: Native American
Median: 32.00
Mean: 33.12
Standard Deviation: 9.53
Variance: 90.90
Skewness: 0.58
Kurtosis: 2.8620