Down by the Bayes, where the Watermelons Grow A Bayesian example using SAS SUAVe: Victoria SAS User Group Meeting November 21, 2017 Peter K. Ott, M.Sc., P.Stat. Strategic Analysis 1
Outline 1. Motivating Example 2. Frequentist Approach 3. Bayes Theorem 4. Bayes Approach 5. SAS Implementation 6. Conclusion 2
Example - Soil Disturbance Study random points are generated within the entire area of a cutblock after logging these points fall in the NAR, RWA and excluded areas (e.g. permanent roads) at each point, a soil sample is taken and assessed for disturbance limits/guidelines are different for the RWA, NAR no more than 25% of the RWA can be disturbed no more than 5% of the NAR can be disturbed 3
Sample data: observe n = 91 points in NAR, x = 16 disturbed (18%) Goal: determine whether the licensee is above or below the 5% limit 4
Frequentist Approach calculate θ = x θ 1 θ, var θ = n n 1 sample 80% CI for θ, and the large a lower CI above 5% is evidence of exceeding the limit equivalent to a one sample t-test, testing against a one-sided alternative at α = 0.10 5
Results: θ = 0.18 Classical Frequentist Approach 80% CI: 0.12, 0.23 since 0.12 > 0.05, we conclude that the licensee has exceeded the allowable disturbance limit t obs = 3.14 with p value = 0.0012 since the p value is less than 0.10, we reject H 0 that the true proportion is 5% 6
Likelihood ratio statistic (Λ) is the ratio of maximum likelihoods: Λ x = Prob x θ 0, H 0 Prob x θ 1, H 1 = sup L θ x : θ Θ 0 sup L θ x : θ Θ 1 2log Λ ~ χ ν 2 as n 2log Λ = 18.93, p = 1.36 10 5 7
Bayes Theorem p A B = p A, B p B p B A p A = p B 8
9
Bayes Theorem (cont.) B 0 1 total A 0 20 65 85 1 5 10 15 total 25 75 100 p A = 1 B = 0 = 5 25 = 1 5 p A = 1 B = 0 = p B = 0 A = 1 p A = 1 p B = 0 = 5/15 15/100 25/100 = 5 25 = 1/5 10
Bayes Theorem and Inference p A B = p A, B p B p B A p A = p B p θ x = p x θ p θ p x posterior prob = likelihood prior prob marginal prob of data 11
Back to the Soil Disturbance Example Likelihood: x θ~bin n, θ = p x θ Prior: θ~beta α, β = p θ 12
13
Approach 1: Proc MCMC proc mcmc data=soil_nar seed=178 outpost=post2 nbi=2000 thin=5 nmc=50000 statistics(alpha=0.10 percent=(5,10,25,50,75,90,95))=all; parms p 0.18; model x ~ binomial(n, p); prior p ~ beta(3.32, 129.48); title; run; 14
Output 1.39% of draws are less than the 5% cutoff 15
Markov Chain Monte Carlo (MCMC) class of simulation techniques for recreating (i.e. drawing samples from) probability distributions first order Markov chain is a process (i.e. sequence of states) where the state at time t depends only the previous state a Markov chain with a probability distribution that does not depend on t is called stationary idea is to construct a MC (using random numbers) that leads to the desired stationary distribution 16
Metropolis-Hastings algorithm MCMC (cont.) users supply two distributions: (i) target, and (ii) generating/proposal/jumping (usually symmetric) at each iteration, a candidate value is either accepted (i.e. new fresh value) or rejected (i.e. previous value retained) a candidate value more probable than the existing value (based on (i)) is always accepted a candidate value less probable than the existing value is sometimes accepted, depending on the relative drop in probability for posterior distributions, p x cancels out in algorithm
MCMC (cont.) Gibbs Sampler special case of M-H algorithm specially suited for multivariate posterior distributions explicit form of joint distribution is not required requires conditional distribution of each variable (parameter), with others held fixed 18
Approach 2: Proc FMM proc fmm data=soil_nar seed=123 plots(only)=trace; model x/n = / dist=bin; bayes mupriorparms=(3.32, 129.48) nbi=2000 thin=5 nmc=50000 summaries(alpha=0.10 percent=(5,10,25,50,75,90,95))=all outpost=post; title; run; 19
Output 1.24% of draws are less than the 5% cutoff 20
I neglected to mention Likelihood: x θ~bin n, θ = p x θ Prior: θ~beta α, β = p θ Posterior: p θ x p x θ p θ = p x p x θ p θ = 1 p x θ p θ dθ 0 = Beta α + x, β + n x 21
Approach 3: DIY Datastep data check_nar; set soil_nar; a=3.32; b=129.48; p=x/n; prob_lt05 = cdf('beta', 0.05, x+a, n-x+b); _05_ = quantile('beta', prob_lt05, x+a, n-x+b); keep n x p prob_lt05 _05_; run; 22
Theoretical Posterior Prob Obs n x p prob_lt05 _05_ 1 91 16 0.17582 0.013891 0.05 1.39% of draws are less than the 5% cutoff 23
24
Conclusions Bayesian inference provides the probability of a hypothesis, given observed data arguably more useful for making decisions than frequentist methods the price is the need to assign prior distributions to parameters computational challenges are capably handled in SAS/STAT via Proc Mcmc (general) or the Bayes statement (specific models) 25
Thanks for staying awake! 26