# In this Bayesian network, where does this posterior probability come from?

Cross Validated Asked by Vin on January 13, 2021

I’m reading Building Intelligent Interactive Tutors (Woolf, 2009) on student models for ITSs. On page 261, the author presents an example for a simple Bayesian network ($S rightarrow E$), where $S$ is the unobserved skill variable (with states: $0$ = knows; $1$ = doesn’t know) and $E$ is the observed evidence variable (with states: $0$ = incorrect; $1$ = correct).

The author goes on to compute the posterior probability $P(S|E)$ for $S=1$ through Bayes’ rule, assuming the following probabilities:

• Prior probability $P(S=1)=0.5$
• $P(E=1|S=1)=0.8$
• $P(E=0|S=0)=0.95$

• $P(S=1|E=1)=0.94$
• $P(S=1|E=0)=0.17$

Then, he claims the revised posterior probability for $S=1$ is approximately $0.78$ for the first case and approximately $0.06$ for the second case. Where do these posterior probability values come from? What do they represent?

I’ve coded the example in Python (using the pgmpy library) and got the same values for $P(S=1|E=1)$ and $P(S=1|E=0)$. Here’s the code and its output (NewtonsLaw is $S$ and Problem023 is $E$):

import numpy as np
from pgmpy.models import BayesianModel
from pgmpy.estimators import BayesianEstimator
from pgmpy.inference import VariableElimination
from pgmpy.factors.discrete import TabularCPD

# Bayesian network structure
model = BayesianModel([('NewtonsLaw', 'Problem023')])

# CPDs
cpd_problem_023 = TabularCPD('Problem023', 2, [[0.95, 0.2],
[0.05, 0.8]],
evidence=['NewtonsLaw'], evidence_card=[2])
cpd_newtons_law = TabularCPD('NewtonsLaw', 2, [[0.5, 0.5]])

model.check_model()

# Query
inference = VariableElimination(model)

posterior_newtons_law_right = inference.query(['NewtonsLaw'], evidence={'Problem023': 1})
print(posterior_newtons_law_right['NewtonsLaw'])

posterior_newtons_law_wrong = inference.query(['NewtonsLaw'], evidence={'Problem023': 0})
print(posterior_newtons_law_wrong['NewtonsLaw'])


Output:

+--------------+-------------------+
| NewtonsLaw   |   phi(NewtonsLaw) |
|--------------+-------------------|
| NewtonsLaw_0 |            0.0588 |
| NewtonsLaw_1 |            0.9412 |
+--------------+-------------------+
+--------------+-------------------+
| NewtonsLaw   |   phi(NewtonsLaw) |
|--------------+-------------------|
| NewtonsLaw_0 |            0.8261 |
| NewtonsLaw_1 |            0.1739 |
+--------------+-------------------+


If the answer still matters, I think to update the posterior probabilities (revised posteriors), one must conduct parameter learning as explained here: http://pgmpy.org/models.html

You did good inferencing with pgmpy, but you cannot derive revised posteriors with inferencing, rather use learning with model.fit(...).

Answered by Dyks Vail on January 13, 2021

## Related Questions

### Compare the results of two canonical correlation analyses (CCA)

1  Asked on February 18, 2021 by forlooper

### Why doesn’t the optimizer just look for stationary points of the loss function?

1  Asked on February 18, 2021 by borut-flis

### Statistical analysis for comparing expertise levels between 3 groups

0  Asked on February 17, 2021 by kaaren0111

### Find the prior distribution for the natural parameter of an exponential family

1  Asked on February 17, 2021 by xxtensionxx

### Using decision tree for unsupervised discretization?

1  Asked on February 17, 2021 by aflatoun

### How to conduct a multilevel model/regression for panel data in Python?

1  Asked on February 17, 2021 by exlo

### How to choose resample size when drawing without replacement?

1  Asked on February 17, 2021

### Two-way repeated measures ANOVA vs mixed ANOVA

1  Asked on February 16, 2021 by xe-m

### What is the adjusted R-squared formula in lm in R and how should it be interpreted?

2  Asked on February 16, 2021 by user1272262

### Linear model selection – Subset, Forward

0  Asked on February 16, 2021 by davud-mursalov

### What model to use for analyzing age frequency data? issues with linear model in R

1  Asked on February 16, 2021 by johnny5ish

### Dimensionality reduction of a large covariance matrix

0  Asked on February 15, 2021 by wilmer-e-henao

### How to estimate variance of classifier on test set?

2  Asked on February 15, 2021 by pterojacktyl

### Churn prediction for customers with limited data

0  Asked on February 14, 2021 by ahmet-turul-bayrak

### multiple linear regression vs polynomial regression models

0  Asked on February 14, 2021 by gracetam

### Multiple Regression study design – questionnaires

1  Asked on February 14, 2021

### Which package works for mediation analysis in R when variables are categorical?

0  Asked on February 14, 2021 by fouzia-farooq

### Compare two samples with many zeros

4  Asked on February 14, 2021

### Non-statistically significant effect of the instrument in the reduced form of the 2SLS

1  Asked on February 14, 2021 by fuca26

### What are the different types of averages?

4  Asked on February 14, 2021 by gpuguy