Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Statistical Rethinking - Lecture 17

Statistical Rethinking - Lecture 17

Lecture 17 - Multilevel models (2) - Statistical Rethinking: A Bayesian Course with R Examples

Richard McElreath

March 03, 2015
Tweet

More Decks by Richard McElreath

Other Decks in Education

Transcript

  1. GVODUJPO PG JUT PXO QBSBNFUFST )FSF JT UIF NVMUJMFWFM NPEFM

    JO NBUIFNBU TJ ∼ #JOPNJBM(OJ, QJ) MPHJU(QJ) = αŁĮĻĸ[J] >ORJRG αŁĮĻĸ ∼ /PSNBM(α, σ) >YDU\ α ∼ /PSNBM(, ) >SU σ ∼ )BMG$BVDIZ(, ) >SULRUIRUVWDQGDU /PUJDF UIBU UIF QSJPS GPS UIF αŁĮĻĸ JOUFSDFQUT JT OPX B GVODUJPO PG UXP QBSB ćJT JT XIFSF UIF iNVMUJw JO NVMUJMFWFM BSJTFT ćF (BVTTJBO EJTUSJCVUJPO X TUBOEBSE EFWJBUJPO σ JT UIF QSJPS GPS FBDI UBOLT JOUFSDFQU #VU UIBU QSJPS JUT α BOE σ 4P UIFSF BSF UXP MFWFMT JO UIF NPEFM FBDI SFTFNCMJOH B TJNQMFS N MFWFM UIF PVUDPNF JT T UIF QBSBNFUFST BSF αŁĮĻĸ BOE UIF QSJPS JT αŁĮĻĸ ∼ *O UIF TFDPOE MFWFM UIF iPVUDPNFw WBSJBCMF JT UIF WFDUPS PG JOUFSDFQU QBSBN QBSBNFUFST BSF α BOE σ BOE UIFJS QSJPST BSF α ∼ /PSNBM(, ) BOE σ ∼ ) 4P JG ZPV IBWF B HPPE SFBTPO UP VTF BOPUIFS EJTUSJCVUJPO UIFO EP TP ćF QSBDUJDF QSPCMFNT BU UIF FOE PG UIF DIBQUFS QSPWJEF BO FYBNQMF 'JUUJOH UIF NPEFM UP EBUB FTUJNBUFT CPUI MFWFMT TJNVMUBOFPVTMZ JO UIF TBNF XBZ UIBU PVS SPCPU BU UIF TUBSU PG UIF DIBQUFS MFBSOFE CPUI BCPVU FBDI DBGÏ BOE UIF WBSJBUJPO BNPOH DBGÏT #VU ZPV DBOOPU ĕU UIJT NPEFM XJUI (+ 8IZ #FDBVTF UIF MJLFMJIPPE NVTU OPX BWFSBHF PWFS UIF MFWFM  QBSBNFUFST α BOE σ BOE (+ KVTU IJMM DMJNCT VTJOH TUBUJD WBMVFT GPS BMM PG UIF QBSBNFUFST *U DBOU TFF UIF MFWFMT 'PS NPSF FYQMBOBUJPO TFF UIF 0WFSUIJOLJOH CPY GVSUIFS EPXO :PV DBO IPXFWFS ĕU UIJT NPEFM XJUI (+Ǐ./) 3 DPEF  (ǎǏǡǏ ʚǶ (+Ǐ./)ǿ '$./ǿ .0-1 ʡ $)*(ǿ  ).$/4 Ǣ + Ȁ Ǣ '*"$/ǿ+Ȁ ʚǶ Ǿ/)&ȁ/)&Ȃ Ǣ Ǿ/)&ȁ/)&Ȃ ʡ )*-(ǿ  Ǣ .$"( Ȁ Ǣ  ʡ )*-(ǿǍǢǎȀ Ǣ .$"( ʡ 0#4ǿǍǢǎȀ ȀǢ /ʙ Ǣ $/ -ʙǑǍǍǍ Ǣ #$).ʙǑ Ȁ ćJT NPEFM ĕU QSPWJEFT FTUJNBUFT GPS  QBSBNFUFST POF PWFSBMM TBNQMF JOUFSDFQU α UIF WBSJ BODF BNPOH UBOLT σ BOE UIFO  QFSUBOL JOUFSDFQUT -FUT DIFDL 8"*$ UIPVHI UP TFF UIF FČFDUJWF OVNCFS PG QBSBNFUFST 3 DPEF   ǿ(ǎǏǡǏȀ
  2. 0.0 0.2 0.4 0.6 0.8 1.0 tank proportion survival 1

    16 32 48 small tanks medium tanks large tanks 'ĶĴłĿIJ ƉƊƉ &NQJSJDBM QSPQPSUJPOT PG TVSWJWPST JO FBDI UBEQPMF UBOL TIPXO CZ UIF ĕMMFE CMVF QPJOUT QMPUUFE XJUI UIF  QFSUBOL FTUJNBUFT GSPN UIF NVMUJMFWFM NPEFM TIPXO CZ UIF CMBDL DJSDMFT ćF EBTIFE MJOF MPDBUFT UIF PWFSBMM BWFSBHF QSPQPSUJPO PG TVSWJWPST BDSPTT BMM UBOLT ćF WFSUJDBM Don’t expect predictions to match observations exactly. Instead expect shrinkage. Fixed estimate Multilevel estimate
  3. 0.0 0.2 0.4 0.6 0.8 1.0 tank proportion survival 1

    16 32 48 small tanks medium tanks large tanks 'ĶĴłĿIJ ƉƊƉ &NQJSJDBM QSPQPSUJPOT PG TVSWJWPST JO FBDI UBEQPMF UBOL TIPXO CZ UIF ĕMMFE CMVF QPJOUT QMPUUFE XJUI UIF  QFSUBOL FTUJNBUFT GSPN UIF NVMUJMFWFM NPEFM TIPXO CZ UIF CMBDL DJSDMFT ćF EBTIFE MJOF MPDBUFT UIF PWFSBMM BWFSBHF QSPQPSUJPO PG TVSWJWPST BDSPTT BMM UBOLT ćF WFSUJDBM Population mean not equal to raw empirical mean. Why? Imbalance in amount of evidence across tanks. Fixed estimate Multilevel estimate raw mean pop mean
  4. 0.0 0.2 0.4 0.6 0.8 1.0 tank proportion survival 1

    16 32 48 small tanks medium tanks large tanks 'ĶĴłĿIJ ƉƊƉ &NQJSJDBM QSPQPSUJPOT PG TVSWJWPST JO FBDI UBEQPMF UBOL TIPXO CZ UIF ĕMMFE CMVF QPJOUT QMPUUFE XJUI UIF  QFSUBOL FTUJNBUFT GSPN UIF NVMUJMFWFM NPEFM TIPXO CZ UIF CMBDL DJSDMFT ćF EBTIFE MJOF MPDBUFT UIF PWFSBMM BWFSBHF QSPQPSUJPO PG TVSWJWPST BDSPTT BMM UBOLT ćF WFSUJDBM Small tanks => high sampling variation. More shrinkage towards mean. Further from mean => more shrinkage. Fixed estimate Multilevel estimate
  5. 0.0 0.2 0.4 0.6 0.8 1.0 tank proportion survival 1

    16 32 48 small tanks medium tanks large tanks 'ĶĴłĿIJ ƉƊƉ &NQJSJDBM QSPQPSUJPOT PG TVSWJWPST JO FBDI UBEQPMF UBOL TIPXO CZ UIF ĕMMFE CMVF QPJOUT QMPUUFE XJUI UIF  QFSUBOL FTUJNBUFT GSPN UIF NVMUJMFWFM NPEFM TIPXO CZ UIF CMBDL DJSDMFT ćF EBTIFE MJOF MPDBUFT UIF PWFSBMM BWFSBHF QSPQPSUJPO PG TVSWJWPST BDSPTT BMM UBOLT ćF WFSUJDBM Large tanks => low sampling variation. Less shrinkage towards mean at all distances from mean. Fixed estimate Multilevel estimate
  6. Careful comparing estimates • Typical for intercept (“fixed effect”) to

    change and become more uncertain • Meaning of parameter changes: no longer mean of data, but rather mean of distribution of intercepts • Uncertainty larger, because many combinations of alpha, sigma, a[tank]’s can produce same empirical mean of data 0.5 1.0 1.5 2.0 2.5 0 1 2 3 4 5 6 estimate Density alpha in fixed model alpha in vary intercept model
  7. Shrinkage • Varying effect estimates shrink towards mean (alpha) •

    Further from mean, more shrinkage • Fewer data in cluster, more shrinkage • Same as regression to the mean, really 0.2 0.4 0.6 0.8 1.0 tank probability of survival in tank 1 16 32 10 25 25
  8. Pooling • Shrinkage arises from pooling • Each tank informs

    estimates of other tanks • The model doesn’t have amnesia! • Effect of pooling influenced by • amount of data in cluster • amount of variation among clusters (sigma) Pool, or the terrorists win
  9. Stein’s paradox • Stein 1956 derived superiority of pooling estimator

    • Result struck many as paradoxical • Proof was non-Bayesian • Suggested estimator similar to Bayes’ suggestion (Bayes’ is better) • Following in Wald’s footsteps INADMISSIBILITY OF THE USUAL ESTI- MATOR FOR THE MEAN OF A MULTI- VARIATE NORMAL DISTRIBUTION CHARLES STEIN STANFORD UNIVERSITY 1. Introduction If one observes the real random variables Xi, X,, independently normally dis- tributed with unknown means ti, *, {n and variance 1, it is customary to estimate (i by Xi. If the loss is the sum of squares of the errors, this estimator is admissible for n < 2, but inadmissible for n _ 3. Since the usual estimator is best among those which transform correctly under translation, any admissible estimator for n _ 3 involves an arbitrary choice. While the results of this paper are not in a form suitable for immediate practical application, the possible improvement over the usual estimator seems to be large enough to be of practical importance if n is large. Let X be a random n-vector whose expected value is the completely unknown vec- tor t and whose components are independently normally distributed with variance 1. We consider the problem of estimating t with the loss function L given by (1) L(t, d) = ( -d)I = 2(ti-dj2 where d is the vector of estimates. In section 2 we give a short proof of the inadmissi- bility of the usual estimator (2) d =t(X) = X, for n 2 3. For n = 2, the admissibility of 4, is proved in section 4. For n = 1 the ad- missibility of t, is well known (see, for example, [1], [2], [3]) and also follows from the result for n = 2. Of course, all of the results concerning this problem apply with obvious modifications if the assumption that the components of X are independently distributed with variance 1 is replaced by the condition that the covariance matrix 2 of X is known and nonsingular and the loss function (1) is replaced by (3) L (, d) = ( -d)'2-' ( -d). Charles Stein (1920–)
  10. Ulysses’ Compass again • Why are varying effects (partial pooling)

    more accurate than fixed effects (no pooling)? • Grand mean: maximum underfitting • Fixed effects: maximum overfitting • Varying effects: adaptive regularization
  11. • Simulate to demonstrate accuracy advantage • 60 ponds •

    5, 10, 25, 35 tadpoles each of 15 pond n true.a s p.nopool p.partpool p.true 1 1 5 -3.089936132 1 0.2000000 0.32173203 0.04352429 2 2 5 0.267290817 5 1.0000000 0.91305884 0.56642768 3 3 5 0.896554101 4 0.8000000 0.79164823 0.71024085 4 4 5 1.934806220 5 1.0000000 0.91276066 0.87378044 5 5 5 -0.758682067 0 0.0000000 0.17692527 0.31893247 6 6 5 3.904836388 5 1.0000000 0.91337140 0.98025353 7 7 5 2.271914139 4 0.8000000 0.79349508 0.90652411 8 8 5 2.886101619 4 0.8000000 0.79557800 0.94715510 9 9 5 1.436457877 3 0.6000000 0.64219989 0.80790553 10 10 5 1.156079068 3 0.6000000 0.64414477 0.76061953 Ulysses’ Compass again
  12. Raw proportion Multilevel estimate   .6-5*-&7&- .0%&-4 0.00 0.10

    0.20 0.30 pond absolute error 1 10 20 30 40 50 60 tiny (5) small (10) medium (25) large (35) 'ĶĴłĿIJ ƉƊƋ &SSPS PG OPQPPMJOH BOE QBSUJBM QPPMJOH FTUJNBUFT GPS UIF TJN VMBUFE UBEQPMF QPOET ćF IPSJ[POUBM BYJT EJTQMBZT QPOE OVNCFS ćF WFSUJ DBM BYJT NFBTVSFT UIF BCTPMVUF FSSPS JO UIF QSFEJDUFE QSPQPSUJPO PG TVSWJWPST DPNQBSFE UP UIF USVF WBMVF VTFE JO UIF TJNVMBUJPO ćF IJHIFS UIF QPJOU avg raw error avg multilevel error
  13. Raw proportion Multilevel estimate   .6-5*-&7&- .0%&-4 0.00 0.10

    0.20 0.30 pond absolute error 1 10 20 30 40 50 60 tiny (5) small (10) medium (25) large (35) 'ĶĴłĿIJ ƉƊƋ &SSPS PG OPQPPMJOH BOE QBSUJBM QPPMJOH FTUJNBUFT GPS UIF TJN VMBUFE UBEQPMF QPOET ćF IPSJ[POUBM BYJT EJTQMBZT QPOE OVNCFS ćF WFSUJ DBM BYJT NFBTVSFT UIF BCTPMVUF FSSPS JO UIF QSFEJDUFE QSPQPSUJPO PG TVSWJWPST DPNQBSFE UP UIF USVF WBMVF VTFE JO UIF TJNVMBUJPO ćF IJHIFS UIF QPJOU When can raw estimate be more accurate than multilevel estimate? Sometimes outliers are really outliers. Can use student-t or Cauchy (fat tails) to reduce shrinkage
  14. Cross-classification • Can use more than one cluster type •

    Recall chimpanzees data • Pulls in chimpanzees • Pulls in blocks • Each chimp in each block • Not nested 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 1 2 3 4 5 6 block row in data 504 400 300 200 100 1
  15. Multilevel chimpanzees JOUFSDFQUT UP UIJT NPEFM XF KVTU SFQMBDF UIF

    ĕYFE SFHVMBSJ[JOH QSJPS XJUI BO #VU UIJT UJNF *MM QVU UIF NFBO α VQ JO UIF MJOFBS NPEFM SBUIFS UIBO EPXO JO UI #FDBVTF JU XJMM QBWF UIF XBZ UP BEEJOH NPSF WBSZJOH FČFDUT MBUFS :PVMM TFF X QVTIFE GPSXBSE B MJUUMF )FSF JT UIF NVMUJMFWFM DIJNQBO[FFT NPEFM JO NBUIFNBUJDBM GPSN XJUI UIF DFQU DPNQPOFOUT IJHIMJHIUFE JO CMVF -J ∼ #JOPNJBM(, QJ) MPHJU(QJ) = α + αĮİŁļĿ[J] + (β1 + β1$ $J)1J αĮİŁļĿ ∼ /PSNBM(, σĮİŁļĿ) α ∼ /PSNBM(, ) β1 ∼ /PSNBM(, ) β1$ ∼ /PSNBM(, ) σĮİŁļĿ ∼ )BMG$BVDIZ(, ) /PUJDF UIBU α JT JOTJEF UIF MJOFBS NPEFM OPU JOTJEF UIF (BVTTJBO QSJPS GPS α NBUIFNBUJDBMMZ FRVJWBMFOU UP XIBU ZPV EJE XJUI UIF UBEQPMFT FBSMJFS JO UIF DI BMXBZT UBLF UIF NFBO PVU PG B (BVTTJBO EJTUSJCVUJPO BOE USFBU UIF EJTUSJCVUJP QMVT B (BVTTJBO EJTUSJCVUJPO DFOUFSFE PO [FSP ćJT NJHIU TFFN B MJUUMF XFJS NJHIU IFMQ USBJO ZPVS JOUVJUJPO CZ FYQFSJNFOUJOH JO 3 ćFTF UXP MJOFT PG DPE varying intercepts on actor Mean alpha in linear model now. Is equivalent.
  16. Multilevel chimpanzees  .VMUJMFWFM DIJNQBO[FFT -FUT QSPDFFE CZ UBLJOH UIF

    GVMM DI $IBQUFS  (ǎǍǡǑ QBHF  BOE ĕSTU BEEJOH WBSZJOH JOUFSDFQUT PO JOUFSDFQUT UP UIJT NPEFM XF KVTU SFQMBDF UIF ĕYFE SFHVMBSJ[JOH QSJPS #VU UIJT UJNF *MM QVU UIF NFBO α VQ JO UIF MJOFBS NPEFM SBUIFS UIBO E #FDBVTF JU XJMM QBWF UIF XBZ UP BEEJOH NPSF WBSZJOH FČFDUT MBUFS :P QVTIFE GPSXBSE B MJUUMF )FSF JT UIF NVMUJMFWFM DIJNQBO[FFT NPEFM JO NBUIFNBUJDBM GPSN DFQU DPNQPOFOUT IJHIMJHIUFE JO CMVF -J ∼ #JOPNJBM(, QJ) MPHJU(QJ) = α + αĮİŁļĿ[J] + (β1 + β1$ $J)1J αĮİŁļĿ ∼ /PSNBM(, σĮİŁļĿ) α ∼ /PSNBM(, ) β1 ∼ /PSNBM(, ) β1$ ∼ /PSNBM(, ) σĮİŁļĿ ∼ )BMG$BVDIZ(, ) /PUJDF UIBU α JT JOTJEF UIF MJOFBS NPEFM OPU JOTJEF UIF (BVTTJBO Q NBUIFNBUJDBMMZ FRVJWBMFOU UP XIBU ZPV EJE XJUI UIF UBEQPMFT FBSMJFS BMXBZT UBLF UIF NFBO PVU PG B (BVTTJBO EJTUSJCVUJPO BOE USFBU UIF EJ QMVT B (BVTTJBO EJTUSJCVUJPO DFOUFSFE PO [FSP ćJT NJHIU TFFN B M NJHIU IFMQ USBJO ZPVS JOUVJUJPO CZ FYQFSJNFOUJOH JO 3 ćFTF UXP MJO EPN WBMVFT GSPN UXP JEFOUJDBM (BVTTJBO EJTUSJCVUJPOT XJUI NFBO   3 DPEF  4ǎ ʚǶ -)*-(ǿ ǎ Ǒ Ǣ ǎǍ Ǣ ǎ Ȁ 4Ǐ ʚǶ ǎǍ ʔ -)*-(ǿ ǎ Ǒ Ǣ Ǎ Ǣ ǎ Ȁ m12.4 <- map2stan( alist( pulled_left ~ dbinom( 1 , p ) , logit(p) <- a + a_actor[actor] + (bp + bpC*condition)*prosoc_left , a_actor[actor] ~ dnorm( 0 , sigma_actor ), a ~ dnorm(0,10), bp ~ dnorm(0,10), bpC ~ dnorm(0,10), sigma_actor ~ dcauchy(0,1) ) , data=d )
  17. Cross-classified chimpanzees varying intercepts on actor varying intercepts on block

    joint mean  5XP UZQFT PG DMVTUFS 5P BEE UIF TFDPOE DMVTUFS UZQF '*& X UIF TUSVDUVSF GPS UIF /*- DMVTUFS ćJT NFBOT UIF MJOFBS NPEFM HFUT ZF JOUFSDFQU αįĹļİĸ[J]  )FSF JT UIF NBUIFNBUJDBM GPSN PG UIF NPEFM XJUI UIF NBDIJOF IJHIMJHIUFE JO CMVF -J ∼ #JOPNJBM(, QJ) MPHJU(QJ) = α + αĮİŁļĿ[J] + αįĹļİĸ[J] + (β1 + β1$ $J)1J αĮİŁļĿ ∼ /PSNBM(, σĮİŁļĿ) αįĹļİĸ ∼ /PSNBM(, σįĹļİĸ) α ∼ /PSNBM(, ) β1 ∼ /PSNBM(, ) β1$ ∼ /PSNBM(, ) σĮİŁļĿ ∼ )BMG$BVDIZ(, ) σįĹļİĸ ∼ )BMG$BVDIZ(, ) Just one “alpha” for both cluster types. Otherwise unidentified parameters.
  18. Cross-classified chimpanzees (ǎǏǡǑ ʚǶ - .(+' ǿ (ǎǏǡǑ Ǣ *-

    .ʙǐ Ǣ #$).ʙǑ Ǣ 2-(0+ʙǎǍǍǍ (P BIFBE BOEJOTQFDU UIFUSBDF QMPU +'*/ǿ(ǎǏǡǑȀ BOEUIFQPTUFSJPS E *UT JNQPSUBOU UP OPUJDF OPX UIBU UIF Ǿ/*- QBSBNFUFST BSF EF BOZ HJWFO SPX J UIF UPUBM JOUFSDFQU JT α + αĮİŁļĿ[J]  ćF QBSU UIBU WBS UIF EFWJBUJPO GSPN UIF HSBOE NFBO α  5XP UZQFT PG DMVTUFS 5P BEE UIF TFDPOE DMVTUFS UZQF '* UIF TUSVDUVSF GPS UIF /*- DMVTUFS ćJT NFBOT UIF MJOFBS NPEFM HF JOUFSDFQU αįĹļİĸ[J]  )FSF JT UIF NBUIFNBUJDBM GPSN PG UIF NPEFM XJUI NBDIJOF IJHIMJHIUFE JO CMVF -J ∼ #JOPNJBM(, QJ) MPHJU(QJ) = α + αĮİŁļĿ[J] + αįĹļİĸ[J] + (β1 + β1$ $ αĮİŁļĿ ∼ /PSNBM(, σĮİŁļĿ) αįĹļİĸ ∼ /PSNBM(, σįĹļİĸ) α ∼ /PSNBM(, ) β1 ∼ /PSNBM(, ) β1$ ∼ /PSNBM(, ) σĮİŁļĿ ∼ )BMG$BVDIZ(, ) σįĹļİĸ ∼ )BMG$BVDIZ(, ) m12.5 <- map2stan( alist( pulled_left ~ dbinom( 1 , p ), logit(p) <- a + a_actor[actor] + a_block[block_num] + (bp + bpc*condition)*prosoc_left, a_actor[actor] ~ dnorm( 0 , sigma_actor ), a_block[block_num] ~ dnorm( 0 , sigma_block ), c(a,bp,bpc) ~ dnorm(0,10), sigma_actor ~ dcauchy(0,1), sigma_block ~ dcauchy(0,1) ) , data=d )
  19. Cross-classified chimpanzees (ǎǏǡǑ ʚǶ - .(+' ǿ (ǎǏǡǑ Ǣ *-

    .ʙǐ Ǣ #$).ʙǑ Ǣ 2-(0+ʙǎǍǍǍ (P BIFBE BOEJOTQFDU UIFUSBDF QMPU +'*/ǿ(ǎǏǡǑȀ BOEUIFQPTUFSJPS E *UT JNQPSUBOU UP OPUJDF OPX UIBU UIF Ǿ/*- QBSBNFUFST BSF EF BOZ HJWFO SPX J UIF UPUBM JOUFSDFQU JT α + αĮİŁļĿ[J]  ćF QBSU UIBU WBS UIF EFWJBUJPO GSPN UIF HSBOE NFBO α  5XP UZQFT PG DMVTUFS 5P BEE UIF TFDPOE DMVTUFS UZQF '* UIF TUSVDUVSF GPS UIF /*- DMVTUFS ćJT NFBOT UIF MJOFBS NPEFM HF JOUFSDFQU αįĹļİĸ[J]  )FSF JT UIF NBUIFNBUJDBM GPSN PG UIF NPEFM XJUI NBDIJOF IJHIMJHIUFE JO CMVF -J ∼ #JOPNJBM(, QJ) MPHJU(QJ) = α + αĮİŁļĿ[J] + αįĹļİĸ[J] + (β1 + β1$ $ αĮİŁļĿ ∼ /PSNBM(, σĮİŁļĿ) αįĹļİĸ ∼ /PSNBM(, σįĹļİĸ) α ∼ /PSNBM(, ) β1 ∼ /PSNBM(, ) β1$ ∼ /PSNBM(, ) σĮİŁļĿ ∼ )BMG$BVDIZ(, ) σįĹļİĸ ∼ )BMG$BVDIZ(, ) m12.5 <- map2stan( alist( pulled_left ~ dbinom( 1 , p ), logit(p) <- a + a_actor[actor] + a_block[block_num] + (bp + bpc*condition)*prosoc_left, a_actor[actor] ~ dnorm( 0 , sigma_actor ), a_block[block_num] ~ dnorm( 0 , sigma_block ), c(a,bp,bpc) ~ dnorm(0,10), sigma_actor ~ dcauchy(0,1), sigma_block ~ dcauchy(0,1) ) , data=d )
  20. Cross-classified chimpanzees • Lots of variation among actors • Little

    variation among blocks • a_actor’s vary a lot • a_block’s vary hardly at all 0 1 2 3 4 5 6 7 0.0 1.0 2.0 3.0 sigma value Density blocks actors   .6-5*-& sigma_block sigma_actor bpc bp a a_block[6] a_block[5] a_block[4] a_block[3] a_block[2] a_block[1] a_actor[7] a_actor[6] a_actor[5] a_actor[4] a_actor[3] a_actor[2] a_actor[1] -2 0 2 4 6 Value 'ĶĴłĿIJ ƉƊƌ -Fę 1PTUFSJPS NFBOT
  21. Cross-classified chimpanzees • Incorporating block: no anticipated benefits; little cost

    Vary Parameters Effective parameters WAIC weight actor, block 18 11 533 0.35 actor 11 8 532 0.65 ćF +- $. QMPU JT TIPXO JO UIF MFęIBOE QBSU PG 'ĶĴłĿIJ ƉƊƌ 'JSTU OPUJDF UIBU UIF OVNCFS PG FČFDUJWF TBNQMFT )Ǿ !! WBSJFT RVJUF B MPU BDSPTT QBSBN FUFST ćJT JT DPNNPO JO DPNQMFY NPEFMT XIFSF TPNF QBSBNFUFST BSF FBTJFS UP FďDJFOUMZ TBNQMF UIBO PUIFST 8IZ ćFSF BSF NBOZ SFBTPOT GPS UIJT #VU JO UIJT TPSU PG NPEFM UIF NPTU DPNNPO SFBTPO JT UIBU TPNF QBSBNFUFS TQFOET B MPU PG UJNF OFBS B CPVOEBSZ )FSF UIBU QBSBNFUFS JT .$"(Ǿ'*& *U TQFOET B MPU PG UJNF OFBS JUT NJOJNVN PG [FSP 4FDPOE DPNQBSF .$"(Ǿ/*- UP .$"(Ǿ'*& BOE OPUJDF UIBU UIF FTUJNBUFE WBSJB UJPO BNPOH BDUPST JT B MPU MBSHFS UIBO UIF FTUJNBUFE WBSJBUJPO BNPOH CMPDLT ćJT JT FBTZ UP BQQSFDJBUF JG XF QMPU UIF NBSHJOBM QPTUFSJPS EJTUSJCVUJPOT PG UIFTF UXP QBSBNFUFST 3 DPEF  +*./ ʚǶ 3/-/ǡ.(+' .ǿ(ǎǏǡǒȀ  ).ǿ +*./ɶ.$"(Ǿ'*& Ǣ 3'ʙǫ.$"(ǫ Ǣ 3'$(ʙǿǍǢǑȀ Ȁ  ).ǿ +*./ɶ.$"(Ǿ/*- Ǣ *'ʙ-)"$Ǐ Ǣ '2ʙǏ Ǣ ʙ Ȁ / 3/ǿ Ǐ Ǣ ǍǡǕǒ Ǣ ǫ/*-ǫ Ǣ *'ʙ-)"$Ǐ Ȁ / 3/ǿ Ǎǡǔǒ Ǣ Ǐ Ǣ ǫ'*&ǫ Ȁ "OE UIJT QMPU BQQFBST PO UIF SJHIU JO 'ĶĴłĿIJ ƉƊƌ 8IJMF UIFSFT VODFSUBJOUZ BCPVU UIF WBSJB UJPO BNPOH BDUPST UIJT NPEFM JT DPOĕEFOU UIBU BDUPST WBSZ NPSF UIBO CMPDLT :PV DBO FBTJMZ TFF UIJT WBSJBUJPO JO UIF WBSZJOH JOUFSDFQU FTUJNBUFT UIF Ǿ/*- EJTUSJCVUJPOT BSF NVDI NPSF TDBUUFSFE UIBO BSF UIF Ǿ'*& EJTUSJCVUJPOT "T B DPOTFRVFODF BEEJOH '*& UP UIJT NPEFM IBTOU BEEFE B MPU PG PWFSĕUUJOH SJTL -FUT DPNQBSF UIF NPEFM XJUI POMZ WBSZJOH JOUFSDFQUT PO /*- UP UIF NPEFM XJUI CPUI LJOET PG WBSZJOH JOUFSDFQUT 3 DPEF  *(+- ǿ(ǎǏǡǑǢ(ǎǏǡǒȀ   +    2 $"#/   (ǎǏǡǑ ǒǐǎǡǒ Ǖǡǎ ǍǡǍ ǍǡǓǒ ǎǖǡǒǍ  (ǎǏǡǒ ǒǐǏǡǔ ǎǍǡǒ ǎǡǏ Ǎǡǐǒ ǎǖǡǔǑ ǎǡǖǑ -PPL BU UIF +  DPMVNO XIJDI SFQPSUT UIF iFČFDUJWF OVNCFS PG QBSBNFUFSTw 8IJMF (ǎǏǡǒ
  22. Posterior predictions • Predictions more subtle: Same clusters or new

    clusters? • Same clusters: proceed as usual • New clusters: should average over distribution of varying effects • In this case: • Same clusters: Predictions for these chimpanzees • New clusters: Prediction for a new chimpanzee or rather for population of chimpanzees
  23. Same clusters, new clusters • Same actors: • Really same

    as before: varying effects are just parameters; you know the model; push samples back through the model • link() and sim() obey this rule • New actors (counterfactual): • which actor (cluster) to use for counterfactual predictions? • average actor • marginal of actor • show sample of actors from posterior
  24. 0.0 0.2 0.4 0.6 0.8 1.0 prosoc_left/condition proportion pulled left

    0/0 1/0 0/1 1/1 average actor 0.0 0.2 0.4 0.6 0.8 1.0 prosoc_left/condition proportion pulled left 0/0 1/0 0/1 1/1 marginal of actor 0.0 0.2 0.4 0.6 0.8 1.0 prosoc_left/condition proportion pulled left 0/0 1/0 0/1 1/1 50 simulated actors 'ĶĴłĿIJ ƉƊƍ 1PTUFSJPS QSFEJDUJWF EJTUSJCVUJPOT GPS UIF DIJNQBO[FFT WBSZ JOH JOUFSDFQU NPEFM (ǎǏǡǑ ćF TPMJE MJOFT BSF QPTUFSJPS NFBOT BOE UIF TIBEFE SFHJPOT BSF  QFSDFOUJMF JOUFSWBMT -Fę 4FUUJOH UIF WBSZJOH JO UFSDFQU Ǿ/*- UP [FSP QSPEVDFT QSFEJDUJPOT GPS BO BWFSBHF BDUPS ćFTF QSFEJDUJPOT JHOPSF VODFSUBJOUZ BSJTJOH GSPN WBSJBUJPO BNPOH BDUPST .JE EMF 4JNVMBUJOH WBSZJOH JOUFSDFQUT VTJOH UIF QPTUFSJPS TUBOEBSE EFWJBUJPO