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

Bayesian statistics Tokyo.R#94

kilometer
September 11, 2021

Bayesian statistics Tokyo.R#94

第94回Tokyo.Rでトークした際のスライド資料です。

kilometer

September 11, 2021
Tweet

More Decks by kilometer

Other Decks in Science

Transcript

  1.       > x + y

    [1] 3 4DSJQUFEJUPS $POTPMFPVUQVU )PXUPVTF34UVEJP
  2.        > x +

    y [1] 4 ಉ͡ม਺໊ʹ୅ೖ͢Δͱ্ॻ͖͞ΕΔ DPNNFOUPVU 4DSJQUFEJUPS $POTPMFPVUQVU )PXUPVTF34UVEJP
  3.      $dyverse: データサイエンス関連パッケージ群をまとめたパッケージ ・dplyr: テーブルデータの加⼯・集計 ・ggplot2:

    グラフの描画 ・stringr: ⽂字列加⼯ ・$dyr: データの整形や変形 ・purrrr: 関数型プログラミング⽤ ・magri7r: パイプ演算⼦%>%を提供 *OTUBMMQBDLBHFGSPN$3"/ QBDLBHFT $3"/ 5IF$PNQSFIFOTJWF3"SDIJWF/FUXPSL 0⒏DJBM3QBDLBHFSFQPTJUPSZ https://cran.r-project.org/
  4. 0367*22(4*,1*/.6&41/6 ) $70-98.56.$' 20+5*59&4*,1*/. ) $70-98.56.$' 20+5*59&70-98.56.'###%# !" "UUBDIUIFQBDLBHF QBDLBHFT

    $3"/ 5IF$PNQSFIFOTJWF3"SDIJWF/FUXPSL 0GGJDJBM3QBDLBHFSFQPTJUPSZ h0ps://cran.r-project.org/ *OTUBMMQBDLBHFGSPN$3"/
  5. Stan A state-of-the-art platform for statistical modeling R A free

    so4ware environment for sta7s7cal compu7ng and graphics. {rstan} package A pla:orm using stan from R
  6. BeginneR Advanced Hoxo_m If I have seen further it is

    by standing on the shoulders of Giants. -- Sir Isaac Newton, 1676
  7. Strong hypothesis obs. principle phenotype f Weak hypothesis obs. principle

    phenotype model Complex data f model Simple data “Hypothesis driven” “Data driven” Experimental design X X
  8. Strong hypothesis obs. principle phenotype f X Weak hypothesis obs.

    principle phenotype model Complex data f X model Simple data “Hypothesis driven” “Data driven” Experimental design ここが気になる(気になりだす)
  9. Dice with α faces ! = 5 $ % =

    ! α = 4 = 0 $ % = ! α = 6 = 1 6 $ % = ! α = 8 = 1 8 $ % = ! α = 12 = 1 12 $ % = ! α = 20 = 1 20 likelihood   maximum likelihood
  10. Dice with α faces ! = {5, 4, 3, 4,

    2, 1, 2, 3, 1, 4} $ % = ! α = 4 = 0 $ % = ! α = 6 = 1 6!" $ % = ! α = 8 = 1 8!" $ % = ! α = 12 = 1 12!" $ % = ! α = 20 = 1 20!" likelihood maximum likelihood  
  11.      Could you find α ?

    Yes, yes, yes. αis 6!! Why do you think so? Because, arg max! - . α = 6 !! Hmmm......, so......, how about ? $(α = 6) Oh, it is " #!"!! ......nnNNNNO!!! WHAT!!????
  12.       Hmmm......, so, how about

    ? $(α = 6) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} $ % = ! α = 6 = 1 6!" maximum likelihood     ! α = 6 % = & !!??
  13. Probability distribution $(% = !) ! % $(% = !|α

    = 6) #(% = '|α) parameter data
  14. Probability distribution $(%) ! % arg max! -(2|α) 1 6!"

    α = 6 α = 8 α = 12 $(4) α 4 -(5 = α|2 = .) ! = # α = 20
  15. Probability distribuEon $#(%) ! % arg max! -$ (2|α) 1

    6!" $$(4) α 4 -! (5 = α|2 = .) ! = # α = 6 α = 8 α = 12 α = 20
  16. Probability distribuEon $#(%) ! % arg max! -$ (2|α) 1

    6!" $$(4) α 4 -! (5 = α|2 = .) ! = # ' 5 : α → & ' 6 : & → α α = 6 α = 8 α = 12 α = 20
  17. Bayes’ theorem ! 7 *|, = ! 8 , *

    ∗ ! 7 (*) ! 8 , "! $ ∩ & = "" (& ∩ $) ! 7 * ∗ ! 8 , * = ! 7 *|, ∗ ! 8 ,
  18. ! 7 *|, = ! 8 , * ∗ !

    7 (*) ! 8 , $! ) = α|+ = ! = $" + = ! ) = α ∗ $! (α) $" ! ' 5 : α → & ' 6 : & → α Bayes’ theorem
  19. ! 7 *|, = ! 8 , * ∗ !

    7 (*) ! 8 , $! ) = α|+ = ! = $" + = ! ) = α ∗ $! (α) $" ! ' 5 : α → & ' 6 : & → α likelihood Bayes’ theorem
  20. ! 7 *|, = ! 8 , * ∗ !

    7 (*) ! 8 , $! α|! = $" ! α ∗ $! (α) $" ! ' 5 : α → & ' 6 : & → α likelihood Bayes’ theorem
  21. ! 7 *|, = ! 8 , * ∗ !

    7 (*) ! 8 , $! α|! = $" ! α ∗ $! () = α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood Bayes’ theorem
  22. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood $$ 4 = α = $$ 4 = α|1 = $$ 4 = α|% = 9 %: 9 → ! sample space
  23. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood $$ 4 = α = $$ 4 = α|1 = $$ 4 = α|% = 9 %: 9 → ! sample space $# % = ! = $# % = !|1 = $# % = !|4 = < 4: < → α sample space
  24. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood $$ 4 = α = $$ 4 = α|% = 9 $# % = ! = $# % = !|4 = < = = ∀$ $# % = !|4 = α ∗ $$ 4 = α|% = 9 marginaliza7on α ∈ {4, 6, 8, 12, 20}
  25. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood = = ∀$ $# !|α ∗ $$ α|9 marginalization α ∈ {4, 6, 8, 12, 20} $$ 4 = α = $$ α|9 $# % = ! = $# !|<
  26. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood = = ∀$ $# !|α ∗ $$ α|9 marginaliza7on α ∈ {4, 6, 8, 12, 20} likelihood $$ 4 = α = $$ α|9 $# % = ! = $# !|<
  27. $! α|! = $" ! α ∗ $! () =

    α) $" + = ! ' 5 : α → & ' 6 : & → α likelihood $$ 4 = α = $$ α|9 $# % = ! = $# !|< = = ∀$ $# !|α ∗ $$ α|9 marginalization α ∈ {4, 6, 8, 12, 20} likelihood
  28. $! α|! = $" ! α ∗ $! (α) $"

    ! ' 5 : α → & ' 6 : & → α likelihood = $" ! α ∗ $! (α|-) Σ∀! $" !|α ∗ $! α|-
  29. Dice with α faces ! = {5, 4, 3, 4,

    2, 1, 2, 3, 1, 4} $ % = ! α = 4 = 0 $ % = ! α = 6 = 1 6!" $ % = ! α = 8 = 1 8!" $ % = ! α = 12 = 1 12!" $ % = ! α = 20 = 1 20!" likelihood  
  30. $! α|! = $" ! α ∗ $! (α|-) Σ∀!

    $" !|α ∗ $! α|- ' 5 : α → & ' 6 : & → α likelihood $! () = α|+ = -)
  31. $! α|! = $" ! α ∗ $! (α|-) Σ∀!

    $" !|α ∗ $! α|- ' 5 : α → & ' 6 : & → α likelihood $! () = α|+ = -) %: 9 → ! 9 : sample space of data ! (20!"= 1,024,000,000,000 pa+ern)
  32. $! α|! = $" ! α ∗ $! (α|-) Σ∀!

    $" !|α ∗ $! α|- ' 5 : α → & ' 6 : & → α likelihood $! () = α|+ = -) %: 9 → ! 9 : sample space of data ! (20$%= 1,024,000,000,000 paHern)
  33. $! α|! = $" ! α ∗ $! (α|-) Σ∀!

    $" !|α ∗ $! α|- ' 5 : α → & ' 6 : & → α likelihood $! () = α|+ = -) + ≅ +′ approximation $! ) = ∀α + = -& = 1 5 α ∈ {4, 6, 8, 12, 20}
  34. $! α|! ≅ $" ! α ∗ $! (α|-′) Σ∀!

    $" !|α ∗ $! α|-′ ' 5 : α → & ' 6 : & → α likelihood = -$ . α Σ∀! -$ .|α = -$ . α -$ . 4 + -$ . 6 + -$ . 8 + -$ . 12 + -$ . 20 ≈ -$ . α 1.7485A − 08 &! ∀α (" = 1 5
  35.      Hmmm......, so, how many ?

    $(α = 6) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} $ % = ! α = 6 = 1 6!" maximum likelihood $$ 4 = 6|! ≅ $# % = ! 4 = 6 1.7485C − 08 ≈ 94.58%
  36. $$ 6|! ≈ 94.58% $$ 6|9′ = 20% $$ 8|!

    ≈ 5.32% $$ 8|9′ = 20% $$ 12|! ≈ 0.09% $$ 12|9′ = 20% $$ 20|! ≈ 0.0005% $$ 20|9′ = 20% $$ 4|! = 0% $$ 4|9′ = 20% prior probability posterior probability Maximum a posteriori (MAP) estimation arg max! $! α ! = 6
  37.      Hmmm......, so, how many ?

    $(α = 6) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} $ % = ! α = 6 = 1 6!" maximum likelihood $$ 4 = 6|! ≈ 94.58% maximum posteriori prob.
  38.      Hmmm......, so, how about ?

    $(α = 6) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} $ % = ! α = 6 = 1 6!" maximum likelihood $$ 4 = 6|! ≈ 94.58% maximum posteriori prob. Could you predict & II?
  39. Dice with α faces ! = {5, 4, 3, 4,

    2, 1, 2, 3, 1, 4} $# !!! ≤ 6|4 ∗ $$ 4|! = 0% $# !!! ≤ 6|6 ∗ $$ 6|! ≈ 94.58% $# !!! ≤ 6|8 ∗ $$ 8|! ≈ 3.99% $# !!! ≤ 6|12 ∗ $$ 12|! ≈ 0.046% $# !!! ≤ 6|20 ∗ $$ 20|! ≈ 0.0001% $# !!! ≤ 6 = = ∀$ {$# !!! ≤ 6|α ∗ $$ α|! } ≈ 98.62% predic$ve probability
  40.      Could you predict & II?

    $ ) = 6 ! ≈ 94.58% $ !$$ ≤ 6 ! ≈ 98.62% and Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4}
  41.      Could you predict & II?

    $ ) = 6 ! ≈ 94.58% $ !$$ ≤ 6 ! ≈ 98.62% and Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} OK, let’s try !!!!!
  42.      !!! = 8 Dice with

    α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4}
  43.      $ ) = 6 !

    ≈ 94.58% $ !$$ ≤ 6 ! ≈ 98.62% Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} OK, let’s try "!!!! !)) = 8 " $ = 6 {,, ,## } = 0%
  44. "$ α|, ≅ "% , α ∗ "$ (α|4′) "%

    (,) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} prior likelihood posterior /( ∀α 1) = 1 5
  45. "$ α|, ≅ "% , α ∗ "$ (α|4′) "%

    (,) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} prior likelihood posterior /( ∀α 1) = 1 5 "$ α| ́ , ≅ "% ́ , α ∗ "$ (α|4′′) "% ( ́ ,) Dice with α faces ́ ! = {!, 8}
  46. "$ α|, ≅ "% , α ∗ "$ (α|4′) "%

    (,) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} prior likelihood posterior /( ∀α 1) = 1 5 "$ α| ́ , ≅ "% ́ , α ∗ "$ (α|4′′) "% ( ́ ,) Dice with α faces ́ ! = {!, 8}
  47. "$ α|, ≅ "% , α ∗ "$ (α|4′) "%

    (,) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} prior likelihood posterior /( ∀α 1) = 1 5 "$ α| ́ , ≅ "% ́ , α ∗ "$ (α|,) "% ( ́ ,) Dice with α faces ́ ! = {!, 8}
  48. Dice with α faces ! = {5, 4, 3, 4,

    2, 1, 2, 3, 1, 4} ́ ! = {!, 8} Non-informa$ve prior distribu$on 20% 20% 20% 20% 20% 0% 94.58% 5.32% 0.09% 0.005% 0% 0% 99.98% 0.02% 0.000004% -! (α|C′) -! (α|.) -! (α| ́ .)
  49.      $ ) = 8 ́

    ! ≈ 99.98% $ !$' ≤ 8 ́ ! ≈ 99.98% Dice with α faces ́ ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4, 8} OK!! Let’s try !!"!! COME OOON
  50.       Hmmm......, so, how about

    ? $(α = 6) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} $ % = ! α = 6 = 1 6!" maximum likelihood     ! α = 6 % = & !!??
  51. ! 7 *|, = ! 8 , * ∗ !

    7 (*) ! 8 , $! ) = α|+ = ! = $" + = ! ) = α ∗ $! (α) $" ! ' 5 : α → & ' 6 : & → α likelihood Bayes’ theorem
  52. $! α|! ≅ $" ! α ∗ $! (α|-′) Σ∀!

    $" !|α ∗ $! α|-′ ' 5 : α → & ' 6 : & → α likelihood = -$ . α Σ∀! -$ .|α = -$ . α -$ . 4 + -$ . 6 + -$ . 8 + -$ . 12 + -$ . 20 ≈ -$ . α 1.7485A − 08 &! ∀α (" = 1 5
  53. $$ 6|! ≈ 94.58% $$ 6|9′ = 20% $$ 8|!

    ≈ 5.32% $$ 8|9′ = 20% $$ 12|! ≈ 0.09% $$ 12|9′ = 20% $$ 20|! ≈ 0.0005% $$ 20|9′ = 20% $$ 4|! = 0% $$ 4|9′ = 20% prior probability posterior probability Maximum a posteriori probability (MAP) estimation arg max! $! α ! = 6
  54. Dice with α faces ! = {5, 4, 3, 4,

    2, 1, 2, 3, 1, 4} $# !!! ≤ 6|4 ∗ $$ 4|! = 0% $# !!! ≤ 6|6 ∗ $$ 6|! ≈ 94.58% $# !!! ≤ 6|8 ∗ $$ 8|! ≈ 3.99% $# !!! ≤ 6|12 ∗ $$ 12|! ≈ 0.046% $# !!! ≤ 6|20 ∗ $$ 20|! ≈ 0.0001% $# !!! ≤ 6 = = ∀$ {$# !!! ≤ 6|α ∗ $$ α|! } ≈ 98.62% predic$ve probability
  55. "$ α|, ≅ "% , α ∗ "$ (α|4′) "%

    (,) Dice with α faces ! = {5, 4, 3, 4, 2, 1, 2, 3, 1, 4} prior likelihood posterior /( ∀α 1) = 1 5 "$ α| ́ , ≅ "% ́ , α ∗ "$ (α|4′′) "% ( ́ ,) Dice with α faces ́ ! = {!, 8}
  56. Strong hypothesis obs. principle phenotype f Weak hypothesis obs. principle

    phenotype model Complex data f model Simple data “Hypothesis driven” “Data driven” Experimental design X X
  57. α ' -(.|α) α |' -(α|.) %|' -(2|α)- α .

    prior distribution posterior distribuBon data predictive distribution $! α ∗ $" ! α $" ! = $! α|! likelihood prior posterior Bayes’ theorem
  58. α ' -(.|α) α |' -(α|.) %|' -(2|α)- α .

    prior distribution posterior distribuBon data predictive distribution $! α ∗ $" ! α $" ! = $! α|! likelihood prior posterior Bayes’ theorem Truth
  59. α ' -(.|α) α |' -(α|.) %|' -(2|α)- α .

    prior distribuBon posterior distribuBon data predicBve distribuBon $! α ∗ $" ! α $" ! = $! α|! likelihood prior posterior Bayes’ theorem #(%|') .(%) Truth L&'(M| $ Kullback-Leibler divergence
  60. α ' -(.|α) α |' -(α|.) %|' -(2|α)- α .

    prior distribuBon posterior distribuBon data predicBve distribuBon $! α ∗ $" ! α $" ! = $! α|! likelihood prior posterior Bayes’ theorem #(%|') .(%) Truth L&'(M| $ = −N( + P KL divergence Entropy Generalization error
  61. /!" (.| # = Q[S $ − S(M)] = Q[(−log

    $ ) − (−log M )] = Q log ( ) = ∫ M % ∗ log ((#) )(,|#) Y% = ∫ M % ∗ log M(!) Y% − ∫ M % ∗ log $ % ! Y% = −Q S M − ∫ M % ∗ log $ % ! Y% B( C Entropy Generaliza$on error
  62. α ' -(.|α) α |' -(α|.) %|' -(2|α)- α .

    prior distribuBon posterior distribution data predictive distribution $! α ∗ $" ! α $" ! = $! α|! likelihood prior posterior Bayes’ theorem #(%|') .(%) Truth L&'(M| $ = −N( + P KL divergence Entropy GeneralizaBon error arg min) L&'(M| $ ⟺ arg min) P P ≅ WAIC Watanabe Akaike InformaAon Criterion
  63. Anaïs Nin – “Life shrinks or expands in proporRon to

    one’s courage.” h0ps://images.gr-assets.com