Psych 548, Miyamoto, Win '15 1 Set Up for Students • Your computer should already be turned on and logged in. • Open a browser to the Psych 548 website (you can get it from MyUW) http://faculty.washington.edu/jmiyamot/p548/p548- set.htm • Download the zip file: p548.zip . Unzip the zip file to C:\temp . This process will create a subdirectory, C:\temp\ p548 . The files for today’s class are in this directory or one of its subdirectories.
36
Embed
Psych 548, Miyamoto, Win '15 1 Set Up for Students Your computer should already be turned on and logged in. Open a browser to the Psych 548 website ( you.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1Psych 548, Miyamoto, Win '15
Set Up for Students• Your computer should already be turned on and logged in.
• Open a browser to the Psych 548 website (you can get it from MyUW)
Unzip the zip file to C:\temp . This process will create a
subdirectory, C:\temp\p548 . The files for today’s class are in this
directory or one of its subdirectories.
• Run R. Run Rstudio. Load any pdf handouts for today into
Acrobat.
Bayesian Statistics, Modeling & Reasoning
What is this course about?
Psychology 548
Bayesian Statistics, Modeling & Reasoning
Instructor: John Miyamoto
01/05/2015: Lecture 1-1
This Powerpoint presentation may contain macros that were used to create the slides. The macros aren’t needed to view the slides. If necessary, you can disable the macros without any change to the presentation.
Outline
• What is Bayesian inference?
• Why is Bayesian statistics, modeling & reasoning relevant to psychology?
• What is Psych 548 about?
• Familiarize students with the set up for using MGH 058
• Explain Psych 548 website
• Intro to R
• Intro to RStudio
• Intro to the R to BUGS interface
Psych 548, Miyamoto, Win '15 3
Lecture probably ends here
4
Bayes Rule – What Is It?
• Reverend Thomas Bayes, 1702 – 1761English Protestant minister & mathematician
• Bayes Rule is fundamentally important to:♦ Bayesian statistics♦ Bayesian decision theory♦ Bayesian models in psychology
Psych 548, Miyamoto, Win '15
P Data|Hypothesis P(Hypothesis)P(Hypothesis|Data)
P(Data)=
n
i ii 1
P(Data) P Data | Hypothesis P Hypothesis
Bayes Rule – Why Is It Important?
5Psych 548, Miyamoto, Win '15
Bayes Rule – Why Is It Important?
• Bayes Rule is the optimal way to update the probability of
hypotheses given data.
• The concept of "Bayesian reasoning“: 3 related conceptso Concept 1: Bayesian inference is a model of optimal learning from
experience.
o Concept 2: Bayesian decision theory describes optimal strategies for taking actions in an uncertain environment. Optimal gambling.
o Concept 3: Bayesian reasoning represents the uncertainty of events as probabilities in a mathematical calculus.
• Concepts 1, 2 & 3 are all consistent with the use of the term, "Bayesian", in modern psychology.
Bayesian Issues in Psychology
6Psych 548, Miyamoto, Win '15
Bayesian Issues in Psychological Research
• Does human reasoning about uncertainty conform to Bayes Rule?
Do humans reason about uncertainty as if they are manipulating
probabilities?o These questions are posed with respect to infants & children,
as well as adults.
• Do neural information processing systems (NIPS) incorporate
Bayes Rule? Do NIPS model uncertainties as if they are
probabilities.
Four Roles for Bayesian Reasoning in Psychology Research
7Psych 548, Miyamoto, Win '15
Four Roles for Bayesian Reasoning in Psychology
1. Bayesian statistics: Analyzing datao E.g., is the slope of the regression of grades on IQ the same for boys as for
girls?o E.g., are there group differences in an analysis of variance?
Four Roles …. (Continued)
8Psych 548, Miyamoto, Win '15
Four Roles for Bayesian Reasoning in Psychology
1. Bayesian statistics: Analyzing data
2. Bayesian decision theory – a theory of strategic action.
How to gamble if you must.
3. Bayesian modeling of psychological processes
4. Bayesian reasoning – Do people reason as if they are
Bayesian probability analysts? (At macro & neural levels)o Judgment and decision making – This is a major issue.o Human causal reasoning – is it Bayesian or quasi-Bayesian?o Modeling neural decision making – many proposed models have a strong
Bayesian flavor.
Four Roles …. (Continued)
9Psych 548, Miyamoto, Win '15
Four Roles for Bayesian Reasoning in Psychology
1. Bayesian statistics: Analyzing data
2. Bayesian decision theory – a theory of strategic action.
How to gamble if you must.
3. Bayesian modeling of psychological processes
4. Bayesian reasoning – Do people reason as if they are
Bayesian probability analysts? (At macro & neural levels)
Psych 548:
Focus on Topics (1) and (3).
Includes a little bit of (4).
Graphical Representation of Psych 548 Focus on Stats/Modeling
10Psych 548, Miyamoto, Win '15
Graphical Representation of Psych 548
Bayesian Statistics& Modeling:
R, OpenBUGS,
JAGS
Bayesian Models in Child & Adult Psychology & Neuroscience
Psych 548
Graph & Text Showing the History of S, S-Plus & R
11Psych 548, Miyamoto, Win '15
Brief History of S, S-Plus, & R
• S – open source statistics program created by Bell Labs (1976 – 1988 – 1999)
• S-Plus – commercial statistics program, refinement of S (1988 – present)
• R – free open source statistics
program (1997 – present)
o currently the standard computing framework for statisticians worldwideMany contributors to its development
o Excellent general computation. Powerful & flexible.
o Great graphics.o Multiplatform: Unix, Linux, Windows, Maco User must like programming
BUGS, WinBUGS, OpenBUGS, JAGS
S
S-PlusR
Ancestry of R
12Psych 548, Miyamoto, Win '15
BUGS, WinBUGS, OpenBUGS & JAGS
• Gibbs Sampling & Metropolis-Hastings Algorithm
Two algorithms for sampling from a hard-to-evaluate probability
distribution.
• BUGS – Bayesian inference Under Gibbs Sampling (circa 1995)
• WinBUGS - Open source (circa 1997)o Windows only
• OpenBUGS – Open source (circa 2006) o Mainly Windows. Runs within a virtual Windows machine on a Mac.
• JAGS – Open source (circa 2007)o Multiplatform: Windows, Mac, Linux
• STAN – Open source (circa 2012) Multiplatform: Windows, Mac, Linux
Basic Structure of Bayesian Computation with R & OpenBUGS
“BUGS” includes all of these.
13Psych 548, Miyamoto, Win '15
Basic Structure of Bayesian Computation
R
data preparation
analysis of results
JAGS
Computes approximation to the posterior distribution.Includes diagnostics.
rjags functions
rjags functions
rjagsrunjags
OpenBUGS/WinBUGS/
StanRBRugs functions
Brugs functions
BRugsR2WinBUGS
rstan
Outline of Remainder of the Lecture: Course Outline & General Information
RStudio
• Run RStudio
• Run R from within RStudio
Psych 548, Miyamoto, Win '15 14
15Psych 548, Miyamoto, Win '15
Remainder of This Lecture
• Take 5 minute break
• Introduce selves
• Psych 548: What will we study?
• Briefly view the Psych 548 webpage.
• Introduction to the computer facility in CSSCR.
• Introduction to R, BUGS (OpenBUGS & JAGS), and RStudio
5 Minute Break
5 Minute Break
• Introduce selves upon return
Psych 548, Miyamoto, Win '15 16Course Goals
17Psych 548, Miyamoto, Win '15
Course Goals
• Learn the theoretical framework of Bayesian inference.
• Achieve competence with R, OpenBUGS and JAGS.
• Learn basic Bayesian statisticso Learn how to think about statistical inference from a Bayesian standpoint. o Learn how to interpret the results of a Bayesian analysis. o Learn basic tools of Bayesian statistical inference - testing for convergence,
making standard plots, examing samples from a posterior distribution.
Kruschke, J. K. (2014). Doing bayesian data analysis, second
edition: A tutorial with R, JAGS, and Stan. Academic Press.o Michael Lee: http://www.socsci.uci.edu/~mdlee/bgm.html o E. J. Wagenmaker: http://users.fmg.uva.nl/ewagenmakers/BayesCourse/BayesBook.html
• Equivalent Matlab & R code for book are available at the
Psych 548 website and at Lee or Wagenmaker's website.
• Emphasis is on Bayesian models of psychological processes rather
than on theory. Lots of examples.
Computer Setup in CSSCR
21Psych 548, Miyamoto, Win '15
CSSCR Network & Psych 548 Webpage
• Click on /Start /Computer.
The path & folder name for your Desktop is:
C:\users\NetID\Desktop (where "NetID" refers to your
NetID)
• Double click on MyUW on your Desktop.
Find Psych 548 under your courses and
double click on the Psych 548 website.
• Download files that are needed for today's class.
Save these files to C:\users\NetID\Desktop o Note that Ctrl-D takes you to your Desktop.
• Run R.
• Run RStudio. Psych 548 Website - END
Psych 548 Website
• Point out where to download the material for today’s class
• Point out pdf’s for the textbooks.
Psych 548, Miyamoto, Win '15 22END
Time Permitting: Proceed to Bayes Rule
Psych 548, Miyamoto, Win '15 23
24
Bayes Rule
• Reverend Thomas Bayes, 1702 – 1761British Protestant minister & mathematician
• Bayes Rule is fundamentally important to:♦ Bayesian statistics♦ Bayesian decision theory♦ Bayesian models in psychology
Psych 548, Miyamoto, Win '15
P Data|Hypothesis P(Hypothesis)P(Hypothesis|Data)
P(Data)=
n
i ii 1
P(Data) P Data | Hypothesis P Hypothesis
Next: Explanation of Bayes Rule
25
Bayes Rule – Explanation
Psych 548, Miyamoto, Win '15
P Data|Hypothesis P(Hypothesis)P(Hypothesis|Data)
P(Data)=
Odds Form of Bayes Rule
Posterior Probability
of the Hypothesis
Likelihood of the Data
Prior Probability of
the Hypothesis
NormalizingConstant
26
Bayes Rule – Explanation
Psych 548, Miyamoto, Win '15
P Data|Hypothesis P(Hypothesis)P(Hypothesis|Data)
P(Data)=
Odds Form of Bayes Rule
Posterior Probability
of the Hypothesis
Likelihood of the Data
Prior Probability of
the Hypothesis
NormalizingConstant
27
Bayes Rule – Odds Form
P D | H P(H)P H | D
P D
Psych 548, Miyamoto, Win '15
P D | H P(H)P H | D
P D
P H | D
P(H | D)
P D | H P(H)
P D | H P(H)
Bayes Rule for H given D
Bayes Rule for not-H given D
Odds Form of Bayes Rule
Explanation of Odds form of Bayes Rule
28
Bayes Rule (Odds Form)
H = a hypothesis, e.g.., hypothesis that the patient has cancer
= the negation of the hypothesis, e.g.., the hypothesis that the patient does not have cancer
D = the data, e.g., a + result for a cancer test
Psych 548, Miyamoto, Win '15
P H | D
P(H | D)
P D | H P(H)
P D | H P(H)
Posterior Odds
Likelihood Ratio(diagnosticity)
Prior Odds(base rate)
H
Interpretation of a Medical Test Result
29Psych 548, Miyamoto, Win '15
Bayesian Analysis of a Medical Test Result(Look at Handout)
QUESTION: A physician knows from past experience in his practice
that 1% of his patients have cancer (of a specific type) and 99%
of his patients do not have the cancer. He also knows the
probabilities of a positive test result (+ result) given cancer and
given no cancer. These probabilities are:
P(+ test | Cancer) = .792 and P(+ test | no cancer) = .096
Suppose Mr. X has a positive test result.
What is the probability that Mr. X has cancer?
• Write down your intuitive answer. (Note to JM: Write estimates on board)
Solution to this problem
30Psych 548, Miyamoto, Win '15
Given Information in the Diagnostic Inference from a Medical Test Result
• P(+ test | Cancer) = .792 (true positive rate a.k.a. hit rate)
• P(+ test | no cancer) = .096 (false positive rate a.k.a. false alarm rate)
• P(Cancer) = Prior probability of cancer = .01
• P(No Cancer) = Prior probability of no cancer
= 1 - P(Cancer) = .99
• Mr. X has a + test result.
What is the probability that Mr. X has cancer?
Solution to this problem
31Psych 548, Miyamoto, Win '15
Bayesian Analysis of a Medical Test Result
P(+ test | Cancer) = 0.792 and P(+ test | no cancer) = 0.096
P(Cancer) = Prior probability of cancer = 0.01
P(No Cancer) = Prior probability of no cancer = 0.99
P(Cancer | + test) = 1 / (12 + 1) = 0.077
Digression concerning What Are Odds?
P cancer | test P test | cancer P(cancer)P no cancer | test P test | no cancer P(no cancer)
0.792 0.010.0833 1/12
0.096 0.99
32Psych 548, Miyamoto, Win '15
Digression: Converting Odds to Probabilities
• If X / (1 – X) = Y
• Then X = Y(1 – X) = Y – XY
• So X + XY = Y
• So X(1 + Y) = Y
• So X = Y / (1 + Y)
• Conclusion: If Y are the odds for an event,
then, Y / (1 + Y) is the probability of the event
Return to Slide re Medical Test Inference
33Psych 548, Miyamoto, Win '15
Bayesian Analysis of a Medical Test Result
P(+ test | Cancer) = 0.792 and P(+ test | no cancer) = 0.096
P(Cancer) = Prior probability of cancer = 0.01
P(No Cancer) = Prior probability of no cancer = 0.99