O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Doing Bayesian Data Analysis, 2nd Edition

Book Description

Doing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan, Second Edition provides an accessible approach for conducting Bayesian data analysis, as material is explained clearly with concrete examples. Included are step-by-step instructions on how to carry out Bayesian data analyses in the popular and free software R and WinBugs, as well as new programs in JAGS and Stan. The new programs are designed to be much easier to use than the scripts in the first edition. In particular, there are now compact high-level scripts that make it easy to run the programs on your own data sets.

The book is divided into three parts and begins with the basics: models, probability, Bayes’ rule, and the R programming language. The discussion then moves to the fundamentals applied to inferring a binomial probability, before concluding with chapters on the generalized linear model. Topics include metric-predicted variable on one or two groups; metric-predicted variable with one metric predictor; metric-predicted variable with multiple metric predictors; metric-predicted variable with one nominal predictor; and metric-predicted variable with multiple nominal predictors. The exercises found in the text have explicit purposes and guidelines for accomplishment.

This book is intended for first-year graduate students or advanced undergraduates in statistics, data analysis, psychology, cognitive science, social sciences, clinical sciences, and consumer sciences in business.

  • Accessible, including the basics of essential concepts of probability and random sampling
  • Examples with R programming language and JAGS software
  • Comprehensive coverage of all scenarios addressed by non-Bayesian textbooks: t-tests, analysis of variance (ANOVA) and comparisons in ANOVA, multiple regression, and chi-square (contingency table analysis)
  • Coverage of experiment planning
  • R and JAGS computer programming code on website
  • Exercises have explicit purposes and guidelines for accomplishment
  • Provides step-by-step instructions on how to conduct Bayesian data analyses in the popular and free software R and WinBugs

Table of Contents

  1. Cover image
  2. Title page
  3. Table of Contents
  4. Copyright
  5. Dedication
  6. Chapter 1: What's in This Book (Read This First!)
    1. 1.1 Real people can read this book
    2. 1.2 What's in this book
    3. 1.3 What's new in the second edition?
    4. 1.4 Gimme feedback (Be polite)
    5. 1.5 Thank you!
  7. Part I: The Basics: Models, Probability, Bayes’ Rule, and R
    1. Introduction
    2. Chapter 2: Introduction: Credibility, Models, and Parameters
      1. 2.1 Bayesian inference is reallocation of credibility across possibilities
      2. 2.2 Possibilities are parameter values in descriptive models
      3. 2.3 The steps of bayesian data analysis
      4. 2.4 Exercises
    3. Chapter 3: The R Programming Language
      1. 3.1 Get the software
      2. 3.2 A simple example of R in action
      3. 3.3 Basic commands and operators in R
      4. 3.4 Variable types
      5. 3.5 Loading and saving data
      6. 3.6 Some utility functions
      7. 3.7 Programming in R
      8. 3.8 Graphical plots: Opening and saving
      9. 3.9 Conclusion
      10. 3.10 Exercises
    4. Chapter 4: What is This Stuff Called Probability?
      1. 4.1 The set of all possible events
      2. 4.2 Probability: Outside or inside the head
      3. 4.3 Probability distributions
      4. 4.4 Two-way distributions
      5. 4.5 Appendix: R code for figure 4.1
      6. 4.6 Exercises
    5. Chapter 5: Bayes' Rule
      1. 5.1 Bayes' rule
      2. 5.2 Applied to parameters and data
      3. 5.3 Complete examples: Estimating bias in a coin
      4. 5.4 Why bayesian inference can be difficult
      5. 5.5 Appendix: R code for figures 5.1, 5.2, etc.
      6. 5.6 Exercises
  8. Part II: All the Fundamentals Applied to Inferring a Binomial Probability
    1. Introduction
    2. Chapter 6: Inferring a Binomial Probability via Exact Mathematical Analysis
      1. 6.1 The likelihood function: Bernoulli distribution
      2. 6.2 A description of credibilities: The beta distribution
      3. 6.3 The posterior beta
      4. 6.4 Examples
      5. 6.5 Summary
      6. 6.6 Appendix: R code for figure 6.4
      7. 6.7 Exercises
    3. Chapter 7: Markov Chain Monte Carlo
      1. 7.1 Approximating a distribution with a large sample
      2. 7.2 A simple case of the metropolis algorithm
      3. 7.3 The metropolis algorithm more generally
      4. 7.4 Toward gibbs sampling: Estimating two coin biases
      5. 7.5 Mcmc representativeness, accuracy, and efficiency
      6. 7.6 Summary
      7. 7.7 Exercises
    4. Chapter 8: JAGS
      1. 8.1 Jags and its relation to R
      2. 8.2 A complete example
      3. 8.3 Simplified scripts for frequently used analyses
      4. 8.4 Example: difference of biases
      5. 8.5 Sampling from the prior distribution in jags
      6. 8.6 Probability distributions available in jags
      7. 8.7 Faster sampling with parallel processing in runjags
      8. 8.8 Tips for expanding jags models
      9. 8.9 Exercises
    5. Chapter 9: Hierarchical Models
      1. 9.1 A single coin from a single mint
      2. 9.2 Multiple coins from a single mint
      3. 9.3 Shrinkage in hierarchical models
      4. 9.4 Speeding up jags
      5. 9.5 Extending the hierarchy: Subjects within categories
      6. 9.6 Exercises
    6. Chapter 10: Model Comparison and Hierarchical Modeling
      1. 10.1 General formula and the bayes factor
      2. 10.2 Example: two factories of coins
      3. 10.3 Solution by MCMC
      4. 10.4 Prediction: Model averaging
      5. 10.5 Model complexity naturally accounted for
      6. 10.6 Extreme sensitivity to prior distribution
      7. 10.7 Exercises
    7. Chapter 11: Null Hypothesis Significance Testing
      1. 11.1 Paved with good intentions
      2. 11.2 Prior knowledge
      3. 11.3 Confidence interval and highest density interval
      4. 11.4 Multiple comparisons
      5. 11.5 What a sampling distribution is good for
      6. 11.6 Exercises
    8. Chapter 12: Bayesian Approaches to Testing a Point (“Null”) Hypothesis
      1. 12.1 The estimation approach
      2. 12.2 The model-comparison approach
      3. 12.3 Relations of parameter estimation and model comparison
      4. 12.4. Estimation or model comparison?
      5. 12.5. Exercises
    9. Chapter 13: Goals, Power, and Sample Size
      1. 13.1 The will to power
      2. 13.2 Computing power and sample size
      3. 13.3 Sequential testing and the goal of precision
      4. 13.4 Discussion
      5. 13.5 Exercises
    10. Chapter 14: Stan
      1. 14.1 HMC sampling
      2. 14.2 Installing stan
      3. 14.3 A complete example
      4. 14.4 Specify models top-down in stan
      5. 14.5 Limitations and extras
      6. 14.6 Exercises
  9. Part III: The Generalized Linear Model
    1. Introduction
    2. Chapter 15: Overview of the Generalized Linear Model
      1. 15.1 Types of variables
      2. 15.2 Linear combination of predictors
      3. 15.3 Linking from combined predictors to noisy predicted data
      4. 15.4 Formal expression of the GLM
      5. 15.5 Exercises
    3. Chapter 16: Metric-Predicted Variable on One or Two Groups
      1. 16.1 Estimating the mean and standard deviation of a normal distribution
      2. 16.2 Outliers and robust estimation: The t distribution
      3. 16.3 Two groups
      4. 16.4 Other noise distributions and transforming data
      5. 16.5 Exercises
    4. Chapter 17: Metric Predicted Variable with One Metric Predictor
      1. 17.1 Simple linear regression
      2. 17.2 Robust linear regression
      3. 17.3 Hierarchical regression on individuals within groups
      4. 17.4 Quadratic trend and weighted data
      5. 17.5 Procedure and perils for expanding a model
      6. 17.6 Exercises
    5. Chapter 18: Metric Predicted Variable with Multiple Metric Predictors
      1. 18.1 Multiple linear regression
      2. 18.2 Multiplicative interaction of metric predictors
      3. 18.3 Shrinkage of regression coefficients
      4. 18.4 Variable selection
      5. 18.5 Exercises
    6. Chapter 19: Metric Predicted Variable with One Nominal Predictor
      1. 19.1 Describing multiple groups of metric data
      2. 19.2 Traditional analysis of variance
      3. 19.3 Hierarchical bayesian approach
      4. 19.4 Including a metric predictor
      5. 19.5 Heterogeneous variances and robustness against outliers
      6. 19.6 Exercises
    7. Chapter 20: Metric Predicted Variable with Multiple Nominal Predictors
      1. 20.1 Describing groups of metric data with multiple nominal predictors
      2. 20.2 Hierarchical bayesian approach
      3. 20.3 Rescaling can change interactions, homogeneity, and normality
      4. 20.4 Heterogeneous variances and robustness against outliers
      5. 20.5 Within-subject designs
      6. 20.6 Model comparison approach
      7. 20.7 Exercises
    8. Chapter 21: Dichotomous Predicted Variable
      1. 21.1 Multiple metric predictors
      2. 21.2 Interpreting the regression coefficients
      3. 21.3 Robust logistic regression
      4. 21.4 Nominal predictors
      5. 21.5 Exercises
    9. Chapter 22: Nominal Predicted Variable
      1. 22.1 Softmax regression
      2. 22.2 Conditional logistic regression
      3. 22.3 Implementation in jags
      4. 22.4 Generalizations and variations of the models
      5. 22.5 Exercises
    10. Chapter 23: Ordinal Predicted Variable
      1. 23.1 Modeling ordinal data with an underlying metric variable
      2. 23.2 The case of a single group
      3. 23.3 The case of two groups
      4. 23.4 The case of metric predictors
      5. 23.5 Posterior prediction
      6. 23.6 Generalizations and extensions
      7. 23.7 Exercises
    11. Chapter 24: Count Predicted Variable
      1. 24.1 Poisson exponential model
      2. 24.2 Example: hair eye go again
      3. 24.3 Example: interaction contrasts, shrinkage, and omnibus test
      4. 24.4 Log-linear models for contingency tables
      5. 24.5 Exercises
    12. Chapter 25: Tools in the Trunk
      1. 25.1 Reporting a bayesian analysis
      2. 25.2 Functions for computing highest density intervals
      3. 25.3 Reparameterization
      4. 25.4 Censored data in JAGS
      5. 25.5 What next?
  10. Bibliography
  11. Index