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

Statistical Rethinking Fall 2017 Lecture 04

Statistical Rethinking Fall 2017 Lecture 04

Week 2, Lecture 4, Statistical Rethinking: A Bayesian Course with Examples in R and Stan. This lecture covers Chapter 4 of the book.

Richard McElreath

November 03, 2017
Tweet

More Decks by Richard McElreath

Other Decks in Education

Transcript

  1. 30 35 40 45 50 55 60 140 150 160

    170 180 weight height SFMBUJWF QMBVTJCJMJUZ UP FBDI ćJT NFBOT QSPCBCJMJUZ *U DPVME CF UIBU UIFSF BSF NB BT UIF ."1 MJOF 0S JU DPVME CF JOTUFBE U UIF ."1 MJOF  5BCMFT PG FTUJNBUFT #FGPSF MPPLJOH DMPTFMZ BU UIF OFX UBCMF PG FTUJNBUFT JUT JN QPSUBOU UP SFBMJ[F UIBU NPEFMT DBOOPU JO HFOFSBM CF VOEFSTUPPE CZ UBCMFT PG FTUJNBUFT *O UIJT TJNQMF NPEFM B MPU DBO CF MFBSOFE GSPN UIF TVNNBSZ PVUQVU #VU UIJT JT OPU B HFOFSBM QSPQFSUZ PG NPEFMT #BZFTJBO PS OPU CFDBVTF PG UIF DPWBSJBUJPO BNPOH QBSBNFUFST 8JUI UIF OFX MJOFBS SFHSFTTJPO ĕU UP UIF ,BMBIBSJ EBUB XF JOTQFDU UIF FTUJNBUFT 3 DPEF  -/" &0ǯ *ǁǑǀ ǰ "+ 1!"3 ǂǑǂɵ džǁǑǂɵ  ƾƾǀǑdžƽ ƾǑdžƾ ƾƾƽǑDžǂ ƾƾǃǑdžǁ  ƽǑdžƽ ƽǑƽǁ ƽǑDžǁ ƽǑdžDŽ 0&$* ǂǑƽDŽ ƽǑƾdž ǁǑDŽDŽ ǂǑǀDž ćF ĕSTU SPX HJWFT UIF RVBESBUJD BQQSPYJNBUJPO GPS α UIF TFDPOE UIF BQQSPYJNBUJPO GPS β BOE UIF UIJSE BQQSPYJNBUJPO GPS σ -FUT USZ UP NBLF TPNF TFOTF PG UIFN JO UIJT WFSZ TJNQMF NPEFM #FTU UP CFHJO XJUI  β CFDBVTF JUT UIF OFX QBSBNFUFS 4JODF β JT B TMPQF UIF WBMVF  DBO CF SFBE BT B QFSTPO  LH IFBWJFS JT FYQFDUFE UP CF  DN UBMMFS  PG UIF QPTUFSJPS QSPCBCJMJUZ MJFT CFUXFFO  BOE  ćBU TVHHFTUT UIBU β WBMVFT DMPTF UP [FSP PS HSFBUMZ BCPWF POF BSF IJHIMZ JODPNQBUJCMF XJUI UIFTF EBUB BOE UIJT NPEFM *G ZPV XFSF UIJOLJOH UIBU QFSIBQT UIFSF XBT OP SFMBUJPOTIJQ BU BMM CFUXFFO IFJHIU BOE XFJHIU UIFO UIJT FTUJNBUF JOEJ DBUFT TUSPOH FWJEFODF PG B QPTJUJWF SFMBUJPOTIJQ JOTUFBE #VU NBZCF ZPV KVTU XBOUFE BT QSFDJTF B NFBTVSFNFOU BT QPTTJCMF PG UIF SFMBUJPOTIJQ CFUXFFO IFJHIU BOE XFJHIU ćJT FTUJNBUF FN CPEJFT UIBU NFBTVSFNFOU DPOEJUJPOBM PO UIF NPEFM 'PS B EJČFSFOU NPEFM UIF NFBTVSF PG UIF SFMBUJPOTIJQ NJHIU CF EJČFSFOU  "%%*/( " 13&%*$503  0 150 160 170 180 height 'ĶĴłĿIJ ƌƌ )FJHIU JO DFOUJNFUFST WFSUJDBM QMPUUFE BHBJOTU XFJHIU JO LJMPHSBNT IPSJ[PO UBM XJUI UIF NBYJNVN B QPTUFSJPSJ MJOF GPS UIF NFBO IFJHIU BU FBDI XFJHIU QMPUUFE JO CMBDL
  2. Sampling from the posterior • Want to get uncertainty onto

    that graph • Again, sample from posterior 1. Use MAP and standard deviation to approximate posterior 2. Sample from multivariate normal distribution of parameters 3. Use samples to generate predictions that “integrate over” the uncertainty
  3. Sampling from the posterior UIF ."1 MJOF 4P IPX DBO

    XF HFU UIBU VODFSUBJOUZ POUP UIF QMPU 5PHFUIFS B DPNCJOBUJPO PG α BOE β EFĕOF B MJOF "OE TP XF DPVME TBNQMF B CVODI PG MJOFT GSPN UIF QPTUFSJPS EJTUSJCVUJPO ćFO XF DPVME EJTQMBZ UIPTF MJOFT PO UIF QMPU UP WJTVBMJ[F UIF VODFSUBJOUZ JO UIF SFHSFTTJPO SFMBUJPOTIJQ 5P CFUUFS BQQSFDJBUF IPX UIF QPTUFSJPS EJTUSJCVUJPO DPOUBJOT MJOFT FYUSBDU TPNF TBNQMFT GSPN UIF NPEFM 3 DPEF  -,01 ʆǦ "51/ 1Ǒ0*-)"0ǯ *ǁǑǀ ǰ ćFO JOTQFDU UIF ĕSTU  SPXT PG UIF TBNQMFT 3 DPEF  -,01DZƾǓǂǒDz   0&$* ƾ ƾƾǁǑDŽDžDžƽ ƽǑDžDžƿƿdžƿƾ ǂǑƾƿƾƾƽƿ ƿ ƾƾƿǑDŽƾƾǂ ƽǑdžƿǀƽDžǂǂ ǁǑdžƽDŽdžDžDŽ ǀ ƾƾǁǑǁǂǂDŽ ƽǑdžƽƾDžǁDžƿ ǂǑƿDŽǃƽǀǃ ǁ ƾƾǁǑDŽǃdžǃ ƽǑDžDžǀƾǂǃƾ ǂǑƽƿƾdžǂDž ǂ ƾƾƿǑǃǀǀǀ ƽǑdžǀDžǀǃǀƿ ǁǑDždžDžǂǂǁ &BDI SPX JT B DPSSFMBUFE SBOEPN TBNQMF GSPN UIF KPJOU QPTUFSJPS PG BMM UISFF QBSBNFUFST VTJOH UIF DPWBSJBODFT QSPWJEFE CZ 3 ,3ǯ*ǁǑǀǰ ćF QBJSFE WBMVFT PG  BOE  PO FBDI SPX EFĕOF B MJOF ćF BWFSBHF PG WFSZ NBOZ PG UIFTF MJOFT JT UIF ."1 MJOF #VU UIF TDBUUFS BSPVOE UIBU BWFSBHF JT NFBOJOHGVM CFDBVTF JU BMUFST PVS DPOĕEFODF JO UIF SFMBUJPOTIJQ CFUXFFO UIF QSFEJDUPS BOE UIF PVUDPNF 4P OPX MFUT EJTQMBZ B CVODI PG UIFTF MJOFT TP ZPV DBO TFF UIF TDBUUFS ćJT MFTTPO XJMM CF FBTJFS UP BQQSFDJBUF JG XF VTF POMZ TPNF PG UIF EBUB UP CFHJO ćFO ZPV DBO TFF IPX BEEJOH UIF ."1 MJOF 4P IPX DBO XF HFU UIBU VODFSUBJOUZ POUP UIF QMPU 5PHFUIFS B DPNCJOBUJPO PG α BOE β EFĕOF B MJOF "OE TP XF DPVME TBNQMF B CVODI PG MJOFT GSPN UIF QPTUFSJPS EJTUSJCVUJPO ćFO XF DPVME EJTQMBZ UIPTF MJOFT PO UIF QMPU UP WJTVBMJ[F UIF VODFSUBJOUZ JO UIF SFHSFTTJPO SFMBUJPOTIJQ 5P CFUUFS BQQSFDJBUF IPX UIF QPTUFSJPS EJTUSJCVUJPO DPOUBJOT MJOFT FYUSBDU TPNF TBNQMFT GSPN UIF NPEFM 3 DPEF  -,01 ʆǦ "51/ 1Ǒ0*-)"0ǯ *ǁǑǀ ǰ ćFO JOTQFDU UIF ĕSTU  SPXT PG UIF TBNQMFT 3 DPEF  -,01DZƾǓǂǒDz   0&$* ƾ ƾƾǁǑDŽDžDžƽ ƽǑDžDžƿƿdžƿƾ ǂǑƾƿƾƾƽƿ ƿ ƾƾƿǑDŽƾƾǂ ƽǑdžƿǀƽDžǂǂ ǁǑdžƽDŽdžDžDŽ ǀ ƾƾǁǑǁǂǂDŽ ƽǑdžƽƾDžǁDžƿ ǂǑƿDŽǃƽǀǃ ǁ ƾƾǁǑDŽǃdžǃ ƽǑDžDžǀƾǂǃƾ ǂǑƽƿƾdžǂDž ǂ ƾƾƿǑǃǀǀǀ ƽǑdžǀDžǀǃǀƿ ǁǑDždžDžǂǂǁ &BDI SPX JT B DPSSFMBUFE SBOEPN TBNQMF GSPN UIF KPJOU QPTUFSJPS PG BMM UISFF QBSBNFUFST VTJOH UIF DPWBSJBODFT QSPWJEFE CZ 3 ,3ǯ*ǁǑǀǰ ćF QBJSFE WBMVFT PG  BOE  PO FBDI SPX EFĕOF B MJOF ćF BWFSBHF PG WFSZ NBOZ PG UIFTF MJOFT JT UIF ."1 MJOF #VU UIF TDBUUFS BSPVOE UIBU BWFSBHF JT NFBOJOHGVM CFDBVTF JU BMUFST PVS DPOĕEFODF JO UIF SFMBUJPOTIJQ CFUXFFO UIF QSFEJDUPS BOE UIF PVUDPNF 4P OPX MFUT EJTQMBZ B CVODI PG UIFTF MJOFT TP ZPV DBO TFF UIF TDBUUFS ćJT MFTTPO XJMM CF FBTJFS UP BQQSFDJBUF JG XF VTF POMZ TPNF PG UIF EBUB UP CFHJO ćFO ZPV DBO TFF IPX BEEJOH
  4. Posterior is full of lines  "%%*/( " 13&%*$503 

    30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 150 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 352 GSPN UIF NPEFM +*./ ʄǤ 3/-/Ǐ.(+' .ǭ (ƿǏƾ Ǯ ćFO JOTQFDU UIF ĕSTU  SPXT PG UIF TBNQMFT +*./ǯƼǑǀǐǰ  .$"(  Ƽ ƼƼǀǏƼDŽǁƿ ƿǏDŽDŽƽƽǁǂ ƻǏǃǂǂǁƾDŽƾ ƽ ƼƼƼǏƻƾǃDŽ ǀǏƼǁDŽǀƼǀ ƻǏDŽǂǀǃǀǀƿ ƾ ƼƼǀǏƿǃƾƾ ǀǏƼƾƾƿǁƾ ƻǏǃǂƽǁǂǀǂ ƿ ƼƻDŽǏǁƿǃǃ ǀǏƻƻǀǃƾǂ ƻǏDŽǃƼƽǁDŽƽ ǀ ƼƼƽǏƿǁƾǂ ƿǏǁǂǃƾƼƿ ƻǏDŽƾǃƿǃƼƿ &BDI SPX JT B DPSSFMBUFE SBOEPN TBNQMF GSPN VTJOH UIF DPWBSJBODFT QSPWJEFE CZ 1*1ǭ(ƿǏƾǮ EFĕOF B MJOF ćF BWFSBHF PG WFSZ NBOZ PG UIFTF M UIBU BWFSBHF JT NFBOJOHGVM CFDBVTF JU BMUFST PVS QSFEJDUPS BOE UIF PVUDPNF 4P OPX MFUT EJTQMBZ B CVODI PG UIFTF MJOFT T FBTJFS UP BQQSFDJBUF JG XF VTF POMZ TPNF PG UIF E JO NPSF EBUB DIBOHFT UIF TDBUUFS PG UIF MJOFT 4P ćF GPMMPXJOH DPEF FYUSBDUT UIF ĕSTU  DBTFT BOE Figure 4.5
  5. Posterior is full of lines  "%%*/( " 13&%*$503 

    30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 150 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 352 Figure 4.5
  6. Posterior is full of lines  "%%*/( " 13&%*$503 

    30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 150 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 352 Figure 4.5
  7. Posterior is full of lines  "%%*/( " 13&%*$503 

    30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 150 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 352 Figure 4.5
  8. Predict mu  4BNQMFT GSPN UIF RVBESBUJD BQQSPYJNBUF QPTUFSJPS O

    GPS UIF IFJHIUXFJHIU NPEFM (ƿǏƾ &BDI QPJOU JT QMF GSPN UIF QPTUFSJPS BOE UIF DSPTT JO FBDI QMPU JT TUJNBUF &TUJNBUFT PG UIF TMPQF  BOE UIF JOUFSDFQU HMZ OFHBUJWFMZ DPSSFMBUFE MFę XIJMF FTUJNBUFT PG UIF IF TUBOEBSE EFWJBUJPO .$"( BSF FTTFOUJBMMZ VODPSSF  ćF JOUFSDFQU BOE .$"( BSF BMTP VODPSSFMBUFE OPU QSFEJDUFE NFBOT GPS  LJMPHSBNT CZ VTJOH ZPVS TBNQMFT GSPN 3 DPEF  ./ɠ Ƿ ǀƻ IU PG UIF ʄǤ BCPWF UBLFT JUT GPSN GSPN UIF FRVBUJPO GPS µJ µJ = α + βYJ. IJT DBTF JT  (P BIFBE BOE UBLF B MPPL JOTJEF UIF SFTVMU (0 JDUFE NFBOT POF GPS FBDI SBOEPN TBNQMF GSPN UIF QPTUFSJPS XFOU JOUP DPNQVUJOH FBDI UIF WBSJBUJPO BDSPTT UIPTF NFBOT JO 30 35 40 45 50 55 60 140 150 160 170 weight height 30 35 40 45 50 55 60 140 150 160 170 weight height 'ĶĴłĿIJ ƌƍ 4BNQMFT GSPN UIF RVBESBUJD BQQSPYJNBUF QPTUFSJPS EJTUSJCVUJPO GPS UIF IFJHIUXFJHIU NPEFM *ǁǑǀ XJUI JODSFBTJOH BNPVOUT PG EBUB *O FBDI QMPU  MJOFT TBNQMFE GSPN UIF QPTUFSJPS EJTUSJCVUJPO TIPXJOH UIF VODFS UBJOUZ JO UIF SFHSFTTJPO SFMBUJPOTIJQ 3 DPEF  *2Ǯ1Ǯǂƽ ʆǦ -,01ɢ ʀ -,01ɢ ǹ ǂƽ ćF DPEF UP UIF SJHIU PG UIF ʆǦ BCPWF UBLFT JUT GPSN GSPN UIF FRVBUJPO GPS µJ  µJ = α + βYJ ćF WBMVF PG YJ JO UIJT DBTF JT  (P BIFBE BOE UBLF B MPPL JOTJEF UIF SFTVMU *2Ǯ1Ǯǂƽ *UT B WFDUPS PG QSFEJDUFE NFBOT POF GPS FBDI SBOEPN TBNQMF GSPN UIF QPTUFSJPS 4JODF KPJOU  BOE SFMBUJPOTIJQ 5P CFUUFS BQQSFDJBUF IPX UIF QPTUFSJPS EJTUSJCVUJPO DPOUBJOT MJOFT FYUSBDU TPNF TBNQMFT GSPN UIF NPEFM 3 DPEF  -,01 ʆǦ "51/ 1Ǒ0*-)"0ǯ *ǁǑǀ ǰ ćFO JOTQFDU UIF ĕSTU  SPXT PG UIF TBNQMFT 3 DPEF  -,01DZƾǓǂǒDz   0&$* ƾ ƾƾǁǑDŽDžDžƽ ƽǑDžDžƿƿdžƿƾ ǂǑƾƿƾƾƽƿ ƿ ƾƾƿǑDŽƾƾǂ ƽǑdžƿǀƽDžǂǂ ǁǑdžƽDŽdžDžDŽ ǀ ƾƾǁǑǁǂǂDŽ ƽǑdžƽƾDžǁDžƿ ǂǑƿDŽǃƽǀǃ ǁ ƾƾǁǑDŽǃdžǃ ƽǑDžDžǀƾǂǃƾ ǂǑƽƿƾdžǂDž ǂ ƾƾƿǑǃǀǀǀ ƽǑdžǀDžǀǃǀƿ ǁǑDždžDžǂǂǁ &BDI SPX JT B DPSSFMBUFE SBOEPN TBNQMF GSPN UIF KPJOU QPTUFSJPS PG BMM UISFF QBSBNFUFST VTJOH UIF DPWBSJBODFT QSPWJEFE CZ 3 ,3ǯ*ǁǑǀǰ ćF QBJSFE WBMVFT PG  BOE  PO FBDI SPX EFĕOF B MJOF ćF BWFSBHF PG WFSZ NBOZ PG UIFTF MJOFT JT UIF ."1 MJOF #VU UIF TDBUUFS BSPVOE UIBU BWFSBHF JT NFBOJOHGVM CFDBVTF JU BMUFST PVS DPOĕEFODF JO UIF SFMBUJPOTIJQ CFUXFFO UIF QSFEJDUPS BOE UIF PVUDPNF 4P OPX MFUT EJTQMBZ B CVODI PG UIFTF MJOFT TP ZPV DBO TFF UIF TDBUUFS ćJT MFTTPO XJMM CF FBTJFS UP BQQSFDJBUF JG XF VTF POMZ TPNF PG UIF EBUB UP CFHJO ćFO ZPV DBO TFF IPX BEEJOH JO NPSF EBUB DIBOHFT UIF TDBUUFS PG UIF MJOFT 4P XFMM CFHJO XJUI KVTU UIF ĕSTU  DBTFT JO !ƿ ćF GPMMPXJOH DPEF FYUSBDUT UIF ĕSTU  DBTFT BOE SFFTUJNBUFT UIF NPEFM
  9. Predict mu Figure 4.6   -*/&"3 .0%&-4 158.0 159.0

    160.0 0.0 0.2 0.4 0.6 0.8 1.0 1.2 mu|weight=50 Density 'ĶĴłĿIJ ƌƏ ć UFSJPS EJTUSJCV XFJHIU JT L UIF SFMBUJWF Q UIF NFBO 3 DPEF  ).ǭ (0Ǭ/Ǭǀƻ ǐ *'ʃ-)"$ƽ ǐ '2ʃƽ ǐ 3'ʃǙ(0Ǵ2 $" 'ĶĴłĿIJ ƌƍ 4BNQMFT GSPN UIF RVBESBUJD BQQSPYJNBUF QPTUFSJPS EJTUSJCVUJPO GPS UIF IFJHIUXFJHIU NPEFM *ǁǑǀ XJUI JODSFBTJOH BNPVOUT PG EBUB *O FBDI QMPU  MJOFT TBNQMFE GSPN UIF QPTUFSJPS EJTUSJCVUJPO TIPXJOH UIF VODFS UBJOUZ JO UIF SFHSFTTJPO SFMBUJPOTIJQ 3 DPEF  *2Ǯ1Ǯǂƽ ʆǦ -,01ɢ ʀ -,01ɢ ǹ ǂƽ ćF DPEF UP UIF SJHIU PG UIF ʆǦ BCPWF UBLFT JUT GPSN GSPN UIF FRVBUJPO GPS µJ  µJ = α + βYJ ćF WBMVF PG YJ JO UIJT DBTF JT  (P BIFBE BOE UBLF B MPPL JOTJEF UIF SFTVMU *2Ǯ1Ǯǂƽ *UT B WFDUPS PG QSFEJDUFE NFBOT POF GPS FBDI SBOEPN TBNQMF GSPN UIF QPTUFSJPS 4JODF KPJOU  BOE  XFOU JOUP DPNQVUJOH FBDI UIF WBSJBUJPO BDSPTT UIPTF NFBOT JODPSQPSBUFT UIF VODFSUBJOUZ JO BOE DPSSFMBUJPO CFUXFFO CPUI QBSBNFUFST *U NJHIU CF IFMQGVM BU UIJT QPJOU UP BDUVBMMZ QMPU UIF EFOTJUZ GPS UIJT WFDUPS PG NFBOT
  10. Predict every mu UIFSF BSF  DPMVNOT JO UIF NBUSJY

    *2 BCPWF /PX XIBU DBO XF EP XJUI UIJT CJH NBUSJY -PUT PG UIJOHT ćF GVODUJPO )&+( QSPWJEFT B QPTUFSJPS EJTUSJCVUJPO PG µ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T SFDJQF XPSLT GPS FWFSZ NPEFM XF

    ĕU JO UIF CPPL "T MPOH BT ZPV LOPX IPX QBSBNFUFST SFMBUF UP UIF EBUB ZPV DBO VTF TBNQMFT GSPN UIF QPTUFSJPS UP EFTDSJCF BOZ BTQFDU PG UIF NPEFMT CFIBWJPS 3FUIJOLJOH 0WFSDPOĕEFOU DPOĕEFODF JOUFSWBMT ćF DPOĕEFODF JOUFSWBM GPS UIF SFHSFTTJPO MJOF JO 'ĶĴłĿIJ ƌƐ DMJOHT UJHIUMZ UP UIF ."1 MJOF ćVT UIFSF JT WFSZ MJUUMF VODFSUBJOUZ BCPVU UIF BWFSBHF IFJHIU BT B GVODUJPO PG BWFSBHF XFJHIU #VU ZPV IBWF UP LFFQ JO NJOE UIBU UIFTF JOGFSFODFT BSF BMXBZT DPOEJUJPOBM PO UIF NPEFM &WFO B WFSZ CBE NPEFM DBO IBWF WFSZ UJHIU DPOĕEFODF JOUFSWBMT *U NBZ IFMQ JG ZPV UIJOL PG UIF SFHSFTTJPO MJOF JO 'ĶĴłĿIJ ƌƐ BT TBZJOH DPOEJUJPOBM PO UIF BTTVNQUJPO UIBU IFJHIU BOE XFJHIU BSF SFMBUFE CZ B TUSBJHIU MJOF UIFO UIJT JT UIF NPTU QMBVTJCMF MJOF BOE UIFTF BSF JUT QMBVTJCMF CPVOET 0WFSUIJOLJOH )PX '$)& XPSLT ćF GVODUJPO '$)& JT OPU SFBMMZ WFSZ TPQIJTUJDBUFE "MM JU JT EPJOH JT VTJOH UIF GPSNVMB ZPV QSPWJEFE XIFO ZPV ĕU UIF NPEFM UP DPNQVUF UIF WBMVF PG UIF MJOFBS NPEFM *U EPFT UIJT GPS FBDI TBNQMF GSPN UIF QPTUFSJPS EJTUSJCVUJPO GPS FBDI DBTF JO UIF EBUB :PV DPVME BDDPNQMJTI UIF TBNF UIJOH GPS BOZ NPEFM ĕU CZ BOZ NFBOT CZ QFSGPSNJOH UIFTF TUFQT ZPVSTFMG ćJT JT IPX JUE MPPL GPS (ƿǏƾ 3 DPEF  +*./ ʄǤ 3/-/Ǐ.(+' .ǭ(ƿǏƾǮ (0Ǐ'$)& ʄǤ !0)/$*)ǭ2 $"#/Ǯ +*./ɠ ɾ +*./ɠǷ2 $"#/ 2 $"#/Ǐ. , ʄǤ . ,ǭ !-*(ʃƽǀ ǐ /*ʃǂƻ ǐ 4ʃƼ Ǯ (0 ʄǤ .++'4ǭ 2 $"#/Ǐ. , ǐ (0Ǐ'$)& Ǯ (0Ǐ( ) ʄǤ ++'4ǭ (0 ǐ ƽ ǐ ( ) Ǯ (0Ǐ  ʄǤ ++'4ǭ (0 ǐ ƽ ǐ  Ǯ "OE UIF WBMVFT JO (0Ǐ( ) BOE (0Ǐ  TIPVME CF WFSZ TJNJMBS BMMPXJOH GPS TJNVMBUJPO WBSJBODF UP XIBU ZPV HPU UIF BVUPNBUFE XBZ VTJOH '$)& ,OPXJOH UIJT NBOVBM NFUIPE JT VTFGVM CPUI GPS  VOEFSTUBOEJOH BOE  TIFFS QPXFS 8IBU FWFS UIF NPEFM ZPV ĕOE ZPVSTFMG XJUI UIJT BQQSPBDI DBO CF VTFE UP HFOFSBUF QPTUFSJPS QSFEJDUJPOT GPS • Sample from posterior • Define series of predictor (weight) values • For each predictor value • For each sample from posterior • Compute mu: a + b*weight • Summarize
  12. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  13. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  14. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  15. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  16. sapply (simplified apply) 1:10 [1] 1 2 3 4 5

    6 7 8 9 10 sapply( 1:10 , function(z) z^2 ) [1] 1 4 9 16 25 36 49 64 81 100
  17. sapply (simplified apply) 1:10 [1] 1 2 3 4 5

    6 7 8 9 10 sapply( 1:10 , function(z) z^2 ) [1] 1 4 9 16 25 36 49 64 81 100 sapply( 1:10 , function(z) prod(1:z)^(1/z) ) [1] 1.000000 1.414214 1.817121 2.213364 2.605171 2.993795 [7] 3.380015 3.764351 4.147166 4.528729
  18. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  19. 'data.frame': 10000 obs. of 3 variables: $ a : num

    115 116 114 111 111 ... $ b : num 0.885 0.871 0.9 0.989 0.981 ... $ sigma: num 5.07 5.23 5.3 4.84 5.07 ... > post <- extract.samples(m4.3) > str(post) > mu.link <- function(weight) post$a + post$b*weight > str( mu.link(50) ) num [1:10000] 159 159 159 160 160 ... > weight.seq <- seq( from=25 , to=70 , by=1 ) > str( weight.seq ) num [1:46] 25 26 27 28 29 30 31 32 33 34 ... > mu <- sapply( weight.seq , mu.link ) > str( mu ) num [1:10000, 1:46] 137 138 136 135 135 ... > mu.mean <- apply( mu , 2 , mean ) > str( mu.mean ) num [1:46] 137 137 138 139 140 ... 1. sample from posterior 2. define link function 3. define weight values to compute predictions for 4. compute prediction for each sample in posterior, for each weight value 5. summarize
  20. Predict every mu '*2 - 0++ - ƼǀǃǏƿƿǁǁ ƼǀDŽǏǂDŽƼƻ 8IBU

    UIFTF OVNCFST NFBO JT UIBU UIFSF JT B  DIBODF UIBU UIF BWFSBHF IFJHIU JT CFUXFFO DN BOE DN DPOEJUJPOBM PO UIF NPEFM BOE EBUB BTTVNJOH UIF XFJHIU JT LH ćBUT HPPE TP GBS CVU XF OFFE UP SFQFBU UIF BCPWF DBMDVMBUJPOT GPS FWFSZ 2 $"#/ WBMVF PO UIF IPSJ[POUBM BYJT OPU KVTU XIFO JU JT LH 8F XBOU UP ESBX  )1%*T BSPVOE UIF ."1 TMPQF JO 'JHVSF  ćJT JT NBEF TJNQMF CZ TUSBUFHJD VTF PG UIF .++'4 DPNNBOE 3 DPEF  2 $"#/Ǐ. , ʄǤ . ,ǭ !-*(ʃƾƻ ǐ /*ʃǁƾ ǐ 4ʃƼ Ǯ (0Ǐ$ ʄǤ .++'4ǭ 2 $"#/Ǐ. , ǐ !0)/$*)ǭ3Ǯ  ǭ +*./ɠ ɾ +*./ɠǷ3 Ǯ Ǯ " QSPCBCJMJUZ NBTT PG  JT UIF EFGBVMU GPS  TP PNJUUJOH UIF +-*ʃƻǏDŽǀ BCPWF JT KVTU UP TBWF TQBDF /PX (0Ǐ$ DPOUBJOT  MPXFS BOE VQQFS CPVOE FTUJNBUFT BDSPTT WBMVFT PG 2 $"#/ GSPN  UP  LH :PV DBO QMPU UIFTF CPVOEBSJFT PO UPQ PG UIF EBUB XJUI B DPVQMF PG DBMMT UP '$) .
  21. Predict every mu '*2 - 0++ - ƼǀǃǏƿƿǁǁ ƼǀDŽǏǂDŽƼƻ 8IBU

    UIFTF OVNCFST NFBO JT UIBU UIFSF JT B  DIBODF UIBU UIF BWFSBHF IFJHIU JT CFUXFFO DN BOE DN DPOEJUJPOBM PO UIF NPEFM BOE EBUB BTTVNJOH UIF XFJHIU JT LH ćBUT HPPE TP GBS CVU XF OFFE UP SFQFBU UIF BCPWF DBMDVMBUJPOT GPS FWFSZ 2 $"#/ WBMVF PO UIF IPSJ[POUBM BYJT OPU KVTU XIFO JU JT LH 8F XBOU UP ESBX  )1%*T BSPVOE UIF ."1 TMPQF JO 'JHVSF  ćJT JT NBEF TJNQMF CZ TUSBUFHJD VTF PG UIF .++'4 DPNNBOE 3 DPEF  2 $"#/Ǐ. , ʄǤ . ,ǭ !-*(ʃƾƻ ǐ /*ʃǁƾ ǐ 4ʃƼ Ǯ (0Ǐ$ ʄǤ .++'4ǭ 2 $"#/Ǐ. , ǐ !0)/$*)ǭ3Ǯ  ǭ +*./ɠ ɾ +*./ɠǷ3 Ǯ Ǯ " QSPCBCJMJUZ NBTT PG  JT UIF EFGBVMU GPS  TP PNJUUJOH UIF +-*ʃƻǏDŽǀ BCPWF JT KVTU UP TBWF TQBDF /PX (0Ǐ$ DPOUBJOT  MPXFS BOE VQQFS CPVOE FTUJNBUFT BDSPTT WBMVFT PG 2 $"#/ GSPN  UP  LH :PV DBO QMPU UIFTF CPVOEBSJFT PO UPQ PG UIF EBUB XJUI B DPVQMF PG DBMMT UP '$) .
  22. Predict every mu '*2 - 0++ - ƼǀǃǏƿƿǁǁ ƼǀDŽǏǂDŽƼƻ 8IBU

    UIFTF OVNCFST NFBO JT UIBU UIFSF JT B  DIBODF UIBU UIF BWFSBHF IFJHIU JT CFUXFFO DN BOE DN DPOEJUJPOBM PO UIF NPEFM BOE EBUB BTTVNJOH UIF XFJHIU JT LH ćBUT HPPE TP GBS CVU XF OFFE UP SFQFBU UIF BCPWF DBMDVMBUJPOT GPS FWFSZ 2 $"#/ WBMVF PO UIF IPSJ[POUBM BYJT OPU KVTU XIFO JU JT LH 8F XBOU UP ESBX  )1%*T BSPVOE UIF ."1 TMPQF JO 'JHVSF  ćJT JT NBEF TJNQMF CZ TUSBUFHJD VTF PG UIF .++'4 DPNNBOE 3 DPEF  2 $"#/Ǐ. , ʄǤ . ,ǭ !-*(ʃƾƻ ǐ /*ʃǁƾ ǐ 4ʃƼ Ǯ (0Ǐ$ ʄǤ .++'4ǭ 2 $"#/Ǐ. , ǐ !0)/$*)ǭ3Ǯ  ǭ +*./ɠ ɾ +*./ɠǷ3 Ǯ Ǯ " QSPCBCJMJUZ NBTT PG  JT UIF EFGBVMU GPS  TP PNJUUJOH UIF +-*ʃƻǏDŽǀ BCPWF JT KVTU UP TBWF TQBDF /PX (0Ǐ$ DPOUBJOT  MPXFS BOE VQQFS CPVOE FTUJNBUFT BDSPTT WBMVFT PG 2 $"#/ GSPN  UP  LH :PV DBO QMPU UIFTF CPVOEBSJFT PO UPQ PG UIF EBUB XJUI B DPVQMF PG DBMMT UP '$) .
  23. Predict every mu '*2 - 0++ - ƼǀǃǏƿƿǁǁ ƼǀDŽǏǂDŽƼƻ 8IBU

    UIFTF OVNCFST NFBO JT UIBU UIFSF JT B  DIBODF UIBU UIF BWFSBHF IFJHIU JT CFUXFFO DN BOE DN DPOEJUJPOBM PO UIF NPEFM BOE EBUB BTTVNJOH UIF XFJHIU JT LH ćBUT HPPE TP GBS CVU XF OFFE UP SFQFBU UIF BCPWF DBMDVMBUJPOT GPS FWFSZ 2 $"#/ WBMVF PO UIF IPSJ[POUBM BYJT OPU KVTU XIFO JU JT LH 8F XBOU UP ESBX  )1%*T BSPVOE UIF ."1 TMPQF JO 'JHVSF  ćJT JT NBEF TJNQMF CZ TUSBUFHJD VTF PG UIF .++'4 DPNNBOE 3 DPEF  2 $"#/Ǐ.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WF TQBDF /PX (0Ǐ$ DPOUBJOT  MPXFS BOE VQQFS CPVOE FTUJNBUFT BDSPTT WBMVFT PG 2 $"#/ GSPN  UP  LH :PV DBO QMPU UIFTF CPVOEBSJFT PO UPQ PG UIF EBUB XJUI B DPVQMF PG DBMMT UP '$) . [,1] [,2] [,3] [,4] [,5] lower 0.95 139.6944 140.6860 141.6516 142.6507 143.6348 upper 0.95 142.3601 143.2046 144.0292 144.8874 145.7358 mu.ci[,1:5]
  25. Figure 4.7 30 35 40 45 50 55 60 140

    150 160 170 180 weight height 30 35 40 45 50 55 60 140 150 160 170 180 weight height 'ĶĴłĿIJ ƌƐ -Fę ćF ĕSTU  WBMVFT JO UIF EJTUSJCVUJPO PG µ BU FBDI XFJHIU WBMVF 3JHIU ćF ,VOH IFJHIU EBUB BHBJO OPX XJUI  )1%* PG UIF NFBO JOEJDBUFE CZ UIF TIBEFE SFHJPO $PNQBSF UIJT SFHJPO UP UIF EJTUSJCVUJPOT PG CMVF QPJOUT PO UIF MFę +'*/ǭ # $"#/ ʋ 2 $"#/ ǐ /ʃƽ ǐ *'ʃ*'Ǐ'+#ǭ-)"$ƽǐƻǏǀǮ Ǯ ȃ +'*/ /#  '$) ǐ & /# ( ) (0 !*- # 2 $"#/ '$) .ǭ 2 $"#/Ǐ. , ǐ (0Ǐ( ) Ǯ ȃ +'*/  .#  - "$*) !*- DŽǀɳ  .# ǭ (0Ǐ  ǐ 2 $"#/Ǐ. , Ǯ  ȅ 20" 16-"ʅǛ+Ǜ 1, %&!" /4 !1 -),1ǯ %"&$%1 ʍ 4"&$%1 ǒ !ƿ ǒ 16-"ʅǛ+Ǜ ǰ ȅ ),,- ,3"/ 0*-)"0 +! -),1 " % *2 3)2" #,/ ǯ & &+ ƾǓƾƽƽ ǰ -,&+10ǯ 4"&$%1Ǒ0". ǒ *2DZ&ǒDz ǒ - %ʅƾǃ ǒ ,)ʅ ,)Ǒ)-%ǯ/+$&ƿǒƽǑƾǰ ǰ ćF SFTVMU JT TIPXO PO UIF MFęIBOE TJEF PG 'ĶĴłĿIJ ƌƏ "U FBDI XFJHIU WBMVF JO 4"&$%1Ǒ0". B QJMF PG DPNQVUFE µ WBMVFT BSF TIPXO &BDI PG UIFTF QJMFT JT B (BVTTJBO EJTUSJCVUJPO MJLF UIBU JO 'ĶĴłĿIJ ƌƎ :PV DBO TFF OPX UIBU UIF BNPVOU PG VODFSUBJOUZ JO µ EFQFOET VQPO UIF WBMVF PG 4"&$%1 "OE UIJT JT UIF TBNF GBDU ZPV TBX JO UIF SJHIUIBOE QMPU JO 'ĶĴłĿIJ ƌƍ ćF ĕOBM TUFQ JT UP TVNNBSJ[F UIF EJTUSJCVUJPO GPS FBDI XFJHIU WBMVF 8FMM VTF --)6 XIJDI BQQMJFT B GVODUJPO PG ZPVS DIPJDF UP B NBUSJY 3 DPEF  ȅ 02**/&7" 1%" !&01/&21&,+ ,# *2 *2Ǒ*"+ ʆǦ --)6ǯ *2 ǒ ƿ ǒ *"+ ǰ *2Ǒ  ʆǦ --)6ǯ *2 ǒ ƿ ǒ  ǒ -/,ʅƽǑDždž ǰ 3FBE --)6ǯ*2ǒƿǒ*"+ǰ BT DPNQVUF UIF NFBO PG FBDI DPMVNO EJNFOTJPO iw PG UIF NBUSJY *2 /PX *2Ǒ*"+ DPOUBJOT UIF BWFSBHF µ BU FBDI XFJHIU WBMVF BOE *2Ǒ  DPOUBJOT  MPXFS BOE VQQFS CPVOET GPS FBDI XFJHIU WBMVF #F TVSF UP UBLF B MPPL JOTJEF *2Ǒ*"+ BOE *2Ǒ  UP EFNZTUJGZ UIFN ćFZ BSF KVTU EJČFSFOU LJOET PG TVNNBSJFT PG UIF EJTUSJCVUJPOT JO *2 XJUI FBDI DPMVNO CFJOH GPS B EJČFSFOU XFJHIU WBMVF :PV DBO QMPU UIFTF TVNNBSJFT PO UPQ PG UIF EBUB XJUI B GFX MJOFT PG 3 DPEF 30 35 40 45 50 55 60 140 150 160 17 weight height 30 35 40 45 50 55 60 140 150 160 17 weight height 'ĶĴłĿIJ ƌƏ -Fę ćF ĕSTU  WBMVFT JO UIF EJTUSJCVUJPO PG µ BU FBDI XFJHIU WBMVF 3JHIU ćF ,VOH IFJHIU EBUB BHBJO OPX XJUI  )1%* PG UIF NFBO JOEJDBUFE CZ UIF TIBEFE SFHJPO $PNQBSF UIJT SFHJPO UP UIF EJTUSJCVUJPOT PG CMVF QPJOUT PO UIF MFę 3 DPEF  ȅ -),1 /4 !1 ȅ #!&+$ ,21 -,&+10 1, *(" )&+" +! &+1"/3) *,/" 3&0&)" -),1ǯ %"&$%1 ʍ 4"&$%1 ǒ !1ʅ!ƿ ǒ ,)ʅ ,)Ǒ)-%ǯ/+$&ƿǒƽǑǂǰ ǰ ȅ -),1 1%"  )&+"ǒ ( 1%" *"+ *2 #,/ " % 4"&$%1 )&+"0ǯ 4"&$%1Ǒ0". ǒ *2Ǒ*"+ ǰ ȅ -),1  0%!"! /"$&,+ #,/ Dždžɵ  0%!"ǯ *2Ǒ  ǒ 4"&$%1Ǒ0". ǰ
  26. 30 35 40 45 50 55 60 140 150 160

    170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 20 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 100 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 200 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 350
  27. 30 35 40 45 50 55 60 140 150 160

    170 180 weight height N = 10 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 20 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 50 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 100 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 200 30 35 40 45 50 55 60 140 150 160 170 180 weight height N = 350
  28. Prediction intervals, too • What about predicted heights, not just

    mean height? • Uncertainty from posterior and uncertainty from likelihood => distribution of predicted height • Could use rnorm to simulate sampling — like your Chapter 3 homework • Can automate with sim   -*/&"3 .0%&-4 8IBU ZPVWF EPOF TP GBS JT KVTU VTF TBNQMFT GSPN UIF QPTUFSJPS UP WJTVBMJ[F UIF VODFSUB JO µJ UIF MJOFBS NPEFM PG UIF NFBO #VU BDUVBM QSFEJDUJPOT PG IFJHIUT EFQFOE BMTP VQPO TUPDIBTUJD EFĕOJUJPO JO UIF ĕSTU MJOF ćF (BVTTJBO EJTUSJCVUJPO PO UIF ĕSTU MJOF UFMMT VT UIF NPEFM FYQFDUT PCTFSWFE IFJHIUT UP CF EJTUSJCVUFE BSPVOE µ OPU SJHIU PO UPQ PG JU UIF TQSFBE BSPVOE µ JT HPWFSOFE CZ σ "MM PG UIJT TVHHFTUT XF OFFE UP JODPSQPSBUF σ JO QSFEJDUJPOT TPNFIPX )FSFT IPX ZPV EP JU *NBHJOF TJNVMBUJOH IFJHIUT 'PS BOZ VOJRVF XFJHIU WBMVF TBNQMF GSPN B (BVTTJBO EJTUSJCVUJPO XJUI UIF DPSSFDU NFBO µ GPS UIBU XFJHIU VTJOH UIF SFDU WBMVF PG σ TBNQMFE GSPN UIF TBNF QPTUFSJPS EJTUSJCVUVPO *G ZPV EP UIJT GPS FWFSZ TBN GSPN UIF QPTUFSJPS GPS FWFSZ XFJHIU WBMVF PG JOUFSFTU ZPV FOE VQ XJUI B DPMMFDUJPO PG T MBUFE IFJHIUT UIBU FNCPEZ UIF VODFSUBJOUZ JO UIF QPTUFSJPS BT XFMM BT UIF VODFSUBJOUZ JO (BVTTJBO MJLFMJIPPE 3 DPEF  .$(Ǐ# $"#/ ʄǤ .$(ǭ (ƿǏƾ ǐ /ʃ'$./ǭ2 $"#/ʃ2 $"#/Ǐ. ,Ǯ Ǯ ./-ǭ.$(Ǐ# $"#/Ǯ )0( ǯƼǑƼƻƻƻǐ ƼǑƿǁǰ ƼƾDŽ Ƽƿƿ ƼƿƼ Ƽƿƻ Ƽƾƻ ǏǏǏ ćJT NBUSJY JT NVDI MJLF UIF FBSMJFS POF (0 CVU JU DPOUBJOT TJNVMBUFE IFJHIUT OPU EJTUS UJPOT PG QMBVTJCMF BWFSBHF IFJHIU µ 8F DBO TVNNBSJ[F UIFTF TJNVMBUFE IFJHIUT JO UIF TBNF XBZ XF TVNNBSJ[FE UIF E
  29. Figure 4.9 95% prediction intervals Nothing special about 95% Try

    50%, 80%, 99% Interested in shape, not boundaries  "%%*/( " 13&%*$503 30 35 40 45 50 55 60 140 150 160 170 180 weight height 'ĶĴłĿIJ ƌƑ  QSFEJDUJPO J IFJHIU BT B GVODUJPO PG XFJHIU MJOF JT UIF ."1 FTUJNBUF PG UIF N BU FBDI XFJHIU ćF UXP TIB TIPX EJČFSFOU  QMBVTJCMF SF OBSSPX TIBEFE JOUFSWBM BSPVOE UI EJTUSJCVUJPO PG µ ćF XJEFS TI SFQSFTFOUT UIF SFHJPO XJUIJO XIJD FYQFDUT UP ĕOE  PG BDUVBM IF QPQVMBUJPO BU FBDI XFJHIU UIF SFBEFS +VTU HP CBDL UP UIF DPEF BCPWF BOE BEE +-*ʃƻǏǃ GPS FYBNQMF UP UI ćBU XJMM HJWF ZPV  JOUFSWBMT JOTUFBE PG  POFT
  30. How sim works   -*/&"3 .0%&-4 (BVTTJBO EJTUSJCVUJPO UIF

    DPNQBOJPO JT -)*-( BOE JU TJNVMBUFT TBNQMJOH GSPN B UJPO 8IBU XF XBOU 3 UP EP TJNVMBUF B IFJHIU GPS FBDI TFU PG TBNQMFT BOE UP EP UI XFJHIU ćF GPMMPXJOH XJMM EP JU 3 DPEF  +*./ ʄǤ 3/-/Ǐ.(+' .ǭ(ƿǏƾǮ 2 $"#/Ǐ. , ʄǤ ƽǀǑǂƻ .$(Ǐ# $"#/ ʄǤ .++'4ǭ 2 $"#/Ǐ. , ǐ !0)/$*)ǭ2 $"#/Ǯ -)*-(ǭ )ʃ)-*2ǭ+*./Ǯ ǐ ( )ʃ+*./ɠ ɾ +*./ɠǷ2 $"#/ ǐ .ʃ+*./ɠ.$"( Ǯ Ǯ # $"#/Ǐ ʄǤ ++'4ǭ .$(Ǐ# $"#/ ǐ ƽ ǐ  Ǯ ćF WBMVFT JO # $"#/Ǐ XJMM CF QSBDUJDBMMZ JEFOUJDBM UP UIF POFT DPNQVUFE JO EJTQMBZFE JO 'ĶĴłĿIJ ƌƑ • For each weight • For each sample from posterior • Simulate a height: rnorm(n,mu,sigma)
  31. Polynomial regression • Linear trends can make absurd predictions •

    Some relationships obviously not linear 30 40 50 60 70 80 130 150 170 190 weight height 0 20 40 60 80 60 100 140 180 age height
  32. Polynomial regression • Purely descriptive (geocentric) strategy: use polynomial of

    predictor variable ɠ (' Ǒ $)/ Ƽ ƻ ƻ Ƽ ƻ Ƽ ƻ Ƽ ƻ Ƽ ǏǏǏ (P BIFBE BOE QMPU # $"#/ BHBJOTU 2 $"#/ ćF SFMBUJPOTIJQ JT WJTJCMZ DVSWF UIBU XFWF JODMVEFE UIF OPOBEVMU JOEJWJEVBMT ćFSF BSF NBOZ XBZT UP NPEFM B DVSWFE SFMBUJPOTIJQ CFUXFFO UXP WBS )FSF *MM TIPX ZPV B WFSZ DPNNPO POF ĽļĹņĻļĺĶĮĹ ĿIJĴĿIJŀŀĶļĻ *O UI UFYU iQPMZOPNJBMw NFBOT FRVBUJPOT GPS µJ UIBU BEE BEEJUJPOBM UFSNT XJUI TR DVCFT BOE FWFO IJHIFS QPXFST PG UIF QSFEJDUPS WBSJBCMF ćFSFT TUJMM POMZ PO EJDUPS WBSJBCMF JO UIF NPEFM TP UIJT JT TUJMM B CJWBSJBUF SFHSFTTJPO #VU UIF EFĕ PG µJ IBT NPSF QBSBNFUFST OPX )FSFT UIF NPTU DPNNPO QPMZOPNJBM SFHSFTTJPO B QBSBCPMJD NPEFM NFBO µJ = α + β YJ + β Y J ćF BCPWF JT B QBSBCPMJD TFDPOE PSEFS QPMZOPNJBM ćF α+β YJ QBSU JT UI MJOFBS GVODUJPO PG Y JO B MJOFBS SFHSFTTJPO KVTU XJUI B MJUUMF iw TVCTDSJQU BE UIFQBSBNFUFSOBNF TP XFDBOUFMM JUBQBSUGSPNUIFOFX QBSBNFUFS ćFBEE UFSN VTFT UIF TRVBSF PG YJ UP DPOTUSVDU B QBSBCPMB SBUIFS UIBO B QFSGFDUMZ T MJOF ćF OFX QBSBNFUFS β NFBTVSFT UIF DVSWBUVSF PG UIF SFMBUJPOTIJQ 1st order (line): (P BIFBE BOE QMPU # $"#/ BHBJOTU 2 $"#/ ćF SFMBUJPOTIJQ JT WJTJCMZ DVSWF UIBU XFWF JODMVEFE UIF OPOBEVMU JOEJWJEVBMT ćFSF BSF NBOZ XBZT UP NPEFM B DVSWFE SFMBUJPOTIJQ CFUXFFO UXP WBS )FSF *MM TIPX ZPV B WFSZ DPNNPO POF ĽļĹņĻļĺĶĮĹ ĿIJĴĿIJŀŀĶļĻ *O UI UFYU iQPMZOPNJBMw NFBOT FRVBUJPOT GPS µJ UIBU BEE BEEJUJPOBM UFSNT XJUI TR DVCFT BOE FWFO IJHIFS QPXFST PG UIF QSFEJDUPS WBSJBCMF ćFSFT TUJMM POMZ PO EJDUPS WBSJBCMF JO UIF NPEFM TP UIJT JT TUJMM B CJWBSJBUF SFHSFTTJPO #VU UIF EFĕ PG µJ IBT NPSF QBSBNFUFST OPX )FSFT UIF NPTU DPNNPO QPMZOPNJBM SFHSFTTJPO B QBSBCPMJD NPEFM NFBO µJ = α + β YJ + β Y J ćF BCPWF JT B QBSBCPMJD TFDPOE PSEFS QPMZOPNJBM ćF α+β YJ QBSU JT UI MJOFBS GVODUJPO PG Y JO B MJOFBS SFHSFTTJPO KVTU XJUI B MJUUMF iw TVCTDSJQU BE UIFQBSBNFUFSOBNF TP XFDBOUFMM JUBQBSUGSPNUIFOFX QBSBNFUFS ćFBEE UFSN VTFT UIF TRVBSF PG YJ UP DPOTUSVDU B QBSBCPMB SBUIFS UIBO B QFSGFDUMZ T MJOF ćF OFX QBSBNFUFS β NFBTVSFT UIF DVSWBUVSF PG UIF SFMBUJPOTIJQ 3FUIJOLJOH -JOFBS BEEJUJWF GVOLZ ćF QBSBCPMJD NPEFM PG µJ BCPWF JT TUJMM D iMJOFBS NPEFMw PG UIF NFBO ćJT JT TP FWFO UIPVHI UIF FRVBUJPO JT DMFBSMZ OPU PG B 2nd order (parabola): Polynomial models suck, but are very common
  33. Polynomial regression • We’ll use full !Kung height/weight data 

    1PMZOPNJBM SFHSFTTJPO *O UIF OFYU DIBQUFS ZPVMM TFF IPX UP VTF MJOFBS NPEFMT UP CVJME SFHSFTTJPOT XJUI NPSF UIBO POF QSFEJDUPS WBSJBCMF #VU CFGPSF UIFO JU IFMQT UP TFF IPX UP NPEFM UIF PVUDPNF BT B DVSWFE GVODUJPO PG B TJOHMF QSFEJDUPS ćF NPEFMT TP GBS BMM BTTVNF UIBU B TUSBJHIU MJOF EFTDSJCFT UIF SFMBUJPOTIJQ #VU UIFSFT OPUIJOH TQFDJBM BCPVU TUSBJHIU MJOFT BTJEF GSPN UIFJS TJNQMJDJUZ -FUT XPSL UISPVHI BO FYBNQMF VTJOH UIF GVMM ,VOH EBUB 3 DPEF  /ǭ *2 ''ƼǮ  ʄǤ *2 ''Ƽ ./-ǭǮ ǘ/Ǐ!-( ǘǑ ǀƿƿ *.Ǐ *! ƿ 1-$' .Ǒ ɠ # $"#/Ǒ )0( Ƽǀƽ Ƽƿƻ Ƽƾǂ Ƽǀǂ Ƽƿǀ ǏǏǏ 'data.frame': 544 obs. of 4 variables: $ height: num 152 140 137 157 145 ... $ weight: num 47.8 36.5 31.9 53 41.3 ... $ age : num 63 63 65 41 51 35 32 27 19 54 ... $ male : int 1 0 0 1 0 1 0 1 0 1 ... 10 30 50 60 100 140 180 weight height adults (18+)
  34. Standardized predictors • Very helpful to standardize predictor variables before

    fitting • Makes estimation easier • Makes interpretation maybe easier • To standardize: • subtract mean • divide by standard deviation • result: mean of zero and standard deviation of 1   -*/&"3 .0%&-4 3 DPEF  !ɢ4"&$%1Ǒ0 ʆǦ ǯ !ɢ4"&$%1 Ǧ *"+ǯ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+VTU NPEJGZ UIF EFĕOJUJPO PG *2 TP UIBU JU DPOUBJOT UIF PSEJOBSZ BOE RVBESBUJD UFSNT #VU JO HFOFSBM JU JT CFUUFS UP QSFQSPDFTT BOZ WBSJBCMF GPSNBUJPOT 4P *MM BMTP CVJME UIF TRVBSF PG 4"&$%1Ǒ0 BT B TFQBSBUF WBSJBCMF &$%1Ǒ0ƿ ʆǦ !ɢ4"&$%1Ǒ0ʋƿ ʆǦ *-ǯ )&01ǯ 178
  36. -2 -1 0 1 2 60 100 140 180 weight.s

    height N = 10 -2 -1 0 1 2 60 100 140 180 weight.s height N = 20
  37. -2 -1 0 1 2 60 100 140 180 weight.s

    height N = 10 -2 -1 0 1 2 60 100 140 180 weight.s height N = 20 -2 -1 0 1 2 60 100 140 180 weight.s height N = 50
  38. -2 -1 0 1 2 60 100 140 180 weight.s

    height N = 10 -2 -1 0 1 2 60 100 140 180 weight.s height N = 20 -2 -1 0 1 2 60 100 140 180 weight.s height N = 50 -2 -1 0 1 2 60 100 140 180 weight.s height N = 100
  39. -2 -1 0 1 2 60 100 140 180 weight.s

    height N = 10 -2 -1 0 1 2 60 100 140 180 weight.s height N = 20 -2 -1 0 1 2 60 100 140 180 weight.s height N = 50 -2 -1 0 1 2 60 100 140 180 weight.s height N = 100 -2 -1 0 1 2 60 100 140 180 weight.s height N = 300
  40. -2 -1 0 1 2 60 100 140 180 weight.s

    height N = 10 -2 -1 0 1 2 60 100 140 180 weight.s height N = 20 -2 -1 0 1 2 60 100 140 180 weight.s height N = 50 -2 -1 0 1 2 60 100 140 180 weight.s height N = 100 -2 -1 0 1 2 60 100 140 180 weight.s height N = 300 -2 -1 0 1 2 60 100 140 180 weight.s height N = 544
  41. Cubic model • Can go further down the rabbit hole:

    TPNF TQFDUVMBSMZ QPPS QSFEJDUJPOT BU CPUI WFSZ MPX BOE NJEEMF XFJHIUT $PN QBSF UIJT UP QBOFM C PVS OFX QBSBCPMJD SFHSFTTJPO ćF DVSWF EPFT B NVDI C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1Ǒ0 ʀ ƿǹ4"&$%1Ǒ0ƿ ʀ ǀǹ4"&$%1Ǒ0ǀ ǒ  ʍ !+,/*ǯ ƾDŽDž ǒ ƾƽƽ ǰ ǒ ƾ ʍ !+,/*ǯ ƽ ǒ ƾƽ ǰ ǒ ƿ ʍ !+,/*ǯ ƽ ǒ ƾƽ ǰ ǒ ǀ ʍ !+,/*ǯ ƽ ǒ ƾƽ ǰ ǒ 0&$* ʍ !2+&#ǯ ƽ ǒ ǂƽ ǰ ǰ ǒ !1ʅ! ǰ
  42. Polynomial regression 1st order 2nd order 3rd order  10-:/0.*"-

    3&(3&44*0/  (a) (b) (c) -2 -1 0 1 2 60 80 100 140 180 weight.s height -2 -1 0 1 2 60 80 100 140 180 weight.s height -2 -1 0 1 2 60 80 100 140 180 weight.s height 'ĶĴłĿIJ ƌƉƈ 1PMZOPNJBM SFHSFTTJPOT PG IFJHIU PO XFJHIU TUBOEBSEJ[FE GPS UIF GVMM ,VOH EBUB *O FBDI QMPU UIF SBX EBUB BSF TIPXO CZ UIF DJSDMFT
  43. Work • Chapter 4 homework: 4H1, 4H2, 4H3 • Next

    week: • Multiple regression • Categorical data • Steady practice with these same tools • quadratic approximation • plotting implied predictions • model criticism