Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Basic Bayes
December 2010
T. A. Louis: Basic Bayes
1
December 2010
T. A. Louis: Basic Bayes
2
December 2010
T. A. Louis: Basic Bayes
3
December 2010
T. A. Louis: Basic Bayes
4
December 2010
T. A. Louis: Basic Bayes
5
December 2010
T. A. Louis: Basic Bayes
6
December 2010
T. A. Louis: Basic Bayes
7
December 2010
T. A. Louis: Basic Bayes
8
December 2010
T. A. Louis: Basic Bayes
9
Reverent Thomas Bayes
To find a method for:
“… the probability that an
event has to happen, in
given circumstances…”
Bayes Rule:
Pr(|Y) Pr(Y|) Pr()
Reverend Thomas Bayes
December 2010
T. A. Louis: Basic Bayes
© http://www-history.mcs.st-andrews.ac.uk/PictDisplay/Bayes.html
10
December 2010
T. A. Louis: Basic Bayes
11
December 2010
T. A. Louis: Basic Bayes
12
December 2010
T. A. Louis: Basic Bayes
13
December 2010
T. A. Louis: Basic Bayes
14
1.0
Example: N=50
0.0
0.2
0.4
0.6
0.8
Prior
Likelihood
Posterior
-4
-2
0
2
4
Beta2
December 2010
T. A. Louis: Basic Bayes
15
1.0
Example: N=100 (50 more)
0.0
0.2
0.4
0.6
0.8
Prior
Likelihood
Posterior
-4
-2
0
2
4
Beta2
December 2010
T. A. Louis: Basic Bayes
16
1.0
Example: N=150 (50 more)
0.0
0.2
0.4
0.6
0.8
Prior
Likelihood
Posterior
-4
-2
0
2
4
Beta2
December 2010
T. A. Louis: Basic Bayes
17
December 2010
T. A. Louis: Basic Bayes
18
December 2010
T. A. Louis: Basic Bayes
19
December 2010
T. A. Louis: Basic Bayes
20
CABAG DEATH RATE
December 2010
T. A. Louis: Basic Bayes
21
TOXOPLASMOSIS RATES
(centered)
December 2010
T. A. Louis: Basic Bayes
22
December 2010
T. A. Louis: Basic Bayes
23
December 2010
T. A. Louis: Basic Bayes
24
V(b)
December 2010
T. A. Louis: Basic Bayes
25
December 2010
T. A. Louis: Basic Bayes
26
45o line
regression
line
Pop line
December 2010
T. A. Louis: Basic Bayes
27
December 2010
T. A. Louis: Basic Bayes
28
December 2010
T. A. Louis: Basic Bayes
29
December 2010
T. A. Louis: Basic Bayes
30
December 2010
T. A. Louis: Basic Bayes
31
December 2010
T. A. Louis: Basic Bayes
32
Improving regression estimates
Similar to the BUGS rat data
• Dependent variable (Yij) is weight for rat “i” at age Xij
i = 1, ..., I (=10); j = 1, ..., J (=5)
Xij = Xj = (-14, -7, 0, 7, 14)
= (8-22, 15-22, 22-22, 29-22 36-22)
Yij = bi0 + bi1 Xj + ij
– As usual, the intercept depends on the centering
• Analyses
– Each rat has its own line
– All rats follow the same line: bi0 = 0 , bi1 = 1
– A compromise between these two
December 2010
T. A. Louis: Basic Bayes
33
Each rat has its own (LSE, MLE) line
(with the population line)
Pop line
December 2010
T. A. Louis: Basic Bayes
34
A multi-level model:
Each rat has its own line,
but the lines come from the same distribution
• The bi0 are independent Normal(0, 02)
• The bi1 are independent N(1, 12)
Overdispersion
• Sample variance of the OLS estimated intercepts:
345 = SEint2 + 02 = 320 + 02 02 = 25, 0 = 5
• Sample variance of the OLS estimated slopes
4.25 = SEslope2 + 12 = 3.25 + 12 12 = 1.00, 1 = 1.00
December 2010
T. A. Louis: Basic Bayes
35
A compromise: each rat has its own line,
but the lines come from the same distribution
Pop line
December 2010
T. A. Louis: Basic Bayes
36
Observed & Predicted Deviations of Annual Charges (in dollars)
for Specialist Services vs. Primary Care Services
Deviation, Specialists’ Charges
40
30
Dot (red) = Posterior Mean of
Observed Deviation
40
Square (blue) = Posterior Mean
of Predicted Deviation
30
20
20
10
10
0
0
-10
-10
-20
-20
-30
-60
-30
December 2010
-40
-20
0
20
40
Dev iation, Primary Care Charges
T. A. Louis: Basic Bayes
60
37
Mean Deviation of Log(Charges >$0)
Observed and Predicted Deviations for Specialist Services:
Log(Charges>$0) and Probability of Any Use of Service
0.4
0.3
0.2
0.1
0.0
-0.1
-0.2
-0.3
-0.4
-0.5
-0.6
-0.7
-0.16
December 2010
0.4
0.3
0.2
0.1
0.0
-0.1
-0.2
-0.3
Dot (red) = Posterior Mean of
Observed Deviation
-0.4
-0.5
Square (blue) = Posterior
-0.6
Mean of Predicted Deviation
-0.7
-0.06
0.04
0.14
0.24
Mean Dev iation of P(Any Use)
T. A. Louis: Basic Bayes
38
December 2010
T. A. Louis: Basic Bayes
39
December 2010
T. A. Louis: Basic Bayes
40
December 2010
T. A. Louis: Basic Bayes
41
December 2010
T. A. Louis: Basic Bayes
42
BACK TO
HISTORICAL CONTROLS
December 2010
T. A. Louis: Basic Bayes
43
December 2010
T. A. Louis: Basic Bayes
44
December 2010
T. A. Louis: Basic Bayes
45
December 2010
T. A. Louis: Basic Bayes
46
December 2010
T. A. Louis: Basic Bayes
47
December 2010
T. A. Louis: Basic Bayes
48
December 2010
T. A. Louis: Basic Bayes
49
Bayes for Frequentist Goals
December 2010
T. A. Louis: Basic Bayes
50
December 2010
T. A. Louis: Basic Bayes
51
Summary
December 2010
T. A. Louis: Basic Bayes
52
Hospital
A [1]
B
C
D
E
F
G
H
I
J
K
L
December 2010
SURGICAL
# of ops
47
148
119
810
211
196
148
215
207
97
256
360
# of deaths
0
18
8
46
8
13
9
31
14
8
29
24
T. A. Louis: Basic Bayes
53
“Surgical” Beta-Binomial Model
(no combining; stand alone)
model
{
for( i in 1 : N ) {
p[i] ~ dbeta(1.0, 1.0) #need to specify the prior
r[i] ~ dbin(p[i], n[i])
}
righttail<-step(p[1]-3/n[1])
}
# Also run with p[i] ~ dbeta(0.25,0.25)
December 2010
T. A. Louis: Basic Bayes
54
“Surgical” Results for p[1]
(no combining; stand alone)
Beta
(1,1)
(.25,.25)
MLE
mean
0.020
0.005
0
sd
2.5%
median
0.019 0.0003
0.0006
0.010 0.0002 0.0010
97.5%
0.014
0.034
0.078
p[1] sample: 1000
p[1] sample: 2000
300.0
40.0
200.0
20.0
100.0
0.0
0.0
-0.05
0.0
0.05
0.1
-0.05
0.05
Beta(.25, .25)
Beta(1,1)
December 2010
0.0
T. A. Louis: Basic Bayes
55
“Surgical” Beta-binomial model
(combine evidence; “estimate” the prior)
model
{for( i in 1 : N ) {
b[i] ~ dnorm(mu,tau) # tau = 1/var
r[i] ~ dbin(p[i],n[i])
logit(p[i]) <- b[i]
}
popmn <- exp(mu) / (1 + exp(mu))
mu ~ dnorm(0.0,1.0E-6)
sigma <- 1 / sqrt(tau)
tau ~ dgamma(alphatau, betatau)
mutau<-1
alphatau<-.001
betatau<-alphatau/mutau
}
December 2010
T. A. Louis: Basic Bayes
56
“Surgical” Results
(combine evidence)
node mean
popmn 0.073
p[1]
0.053
sd
0.010
0.020
2.5%
0.053
0.018
median
0.073
0.052
97.5%
0.095
0.094
p[1] sample: 6000
20.0
15.0
10.0
5.0
0.0
-0.05
December 2010
0.0
0.05
0.1
0.15
T. A. Louis: Basic Bayes
57
“Surgical” Results for p[1]
(stand alone & combine)
Beta
Comb
(1,1)
(.25,.25)
MLE
mean
0.053
0.020
0.005
0
sd
2.5%
median
0.020 0.0180 0.0520
0.019 0.0003 0.0006
0.010 0.0002 0.0010
p[1] sample: 1000
p[1] sample: 2000
p[1] sample: 6000
300.0
40.0
20.0
15.0
10.0
5.0
0.0
97.5%
0.094
0.014
0.034
0.078
200.0
20.0
100.0
0.0
0.0
-0.05
0.0
0.05
0.1
Comb
December 2010
0.15
-0.05
0.0
0.05
0.1
1,1
T. A. Louis: Basic Bayes
-0.05
0.0
0.05
.25, .25
58
Summary
Carefully specified and applied,
the Bayesian approach is very effective in
• Structuring designs, analyses, complicated models and
goals (e.g., ranking)
• Incorporating all relevant uncertainties
• Improving estimates
• Communicating in a more “scientific” manner
• Combining evidence and opinions
• Making assumptions explicit
However,
• The Bayesian approach is no panacea and makes
additional demands on the analyst
• Traditional values still apply
Space-age methods will not rescue stone-age data
December 2010
T. A. Louis: Basic Bayes
59
GRACIAS!
December 2010
T. A. Louis: Basic Bayes
60
TEACHER EXPECTANCY
(data are in “Datasets” )
Data are from a Raudenbush & Bryk meta-analysis of
19 studies (see Cooper and Hedges,1994)
Effect sizek = distance between treatment and control group
means measured in population standard
deviation units
SEk = the standard error of the effect size
Weeksk = estimated weeks of teacher-student contact
prior to expectancy induction
December 2010
T. A. Louis: Basic Bayes
61
TEACHER EXPECTANCY (continued)
• Each study consisted of either telling teachers
that a student had great potential or not
• All students received a pre-test and a post-test
• Teachers evaluated progress
• A positive effect size indicates that the teachers
rated students who were “likely to improve” as
having improved more than the control group
• A negative slope on “Weeks” indicates that the
more a teacher got to know a student before the
experiment,the less the influence of the
expectancy intervention
December 2010
T. A. Louis: Basic Bayes
62
December 2010
T. A. Louis: Basic Bayes
63
December 2010
T. A. Louis: Basic Bayes
64
ACCOUNTING FOR
(explaining)
UNEXPLAINED VARIABILITY
• Including regressors can explain (account for) some
of unexplained variability
• Doing so is always a trade-off in that you need to use
degrees of freedom to do the explaining
• Going too far--adding too many regressors-- inflates
residual variability
• In MLMs there is variance at various levels that can
potentially be taken into account
December 2010
T. A. Louis: Basic Bayes
65