SlideShare a Scribd company logo
1 of 8
Download to read offline
基礎からのベイズ統計学
7章課題4
201640111
葛木美紀
Miki Katsuragi
問題
1. Mさんが UFO キャッチャーに挑戦しており、過去16回の結果
は×○××○○×××××○×××○、あと4回挑戦できます。結果がベル
ヌイ試行に、失敗回数が負の二項分布に従っているとして、残
り4回中3回以上成功する確率はどれくらいでしょうか。
2. 2つのぬいぐるみを取るために多く見積もって何回挑戦する必
要がある?
各問題に適用するモデル
1. 結果がベルヌーイ試行に従うと仮定しθをサンプリングする。
その上で下記生成量 p (4回成功する確率 + 3回成功する確
率)を定義する
p(t)
= g(θ(t)
) = 4+0-1
C4-1
θ4
(1 - θ)0
+ 3+1-1
C3-1
θ3
(1 - θ)1
2. 負の二項分布に従う予測分布の予測値
   x*(t)
〜 f(2, θ(t)
)
を生成し、成功回数である 2 を足した x*(t)
+ 2 によって2回
成功するまでの試行回数の予測分布を近似的に得る
stanファイル
data {
int<lower=0> N;
int<lower=0> x[N];
}
parameters {
real<lower=0, upper=1> theta;
}
model {
x ~ bernoulli(theta);
}
generated quantities{
real p; #4回中3回以上成功する確率
real beta;
int pred; #2回成功するまでの総試行数
p = 1*pow(theta, 4)*pow((1-theta),0)+4*pow(theta, 3)*pow((1-theta),1);
beta = theta/(1-theta);
pred = neg_binomial_rng(2, beta)+2;
}
Rスクリプト
scr <- "model774.stan"
N <- 16
x <- c(0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
data <- list(N=N,x=x)
par <- c("p", "pred")
fit <- stan(file=scr, model_name=scr, data=data, pars=par, verbose=F,
seed=123, chains=1, warmup=5000, iter=100000)
library(ggmcmc) #チャート出力用ライブラリ
ggmcmc(ggs(fit), file='fit-ggmcmc.pdf')
結果
> fit
Inference for Stan model: model774.stan.
4 chains, each with iter=1e+05; warmup=10000; thin=1;
post-warmup draws per chain=90000, total post-warmup draws=360000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
p 0.13 0.00 0.11 0.01 0.05 0.11 0.19 0.41 236584 1
pred 6.80 0.01 5.33 2.00 3.00 5.00 8.00 21.00 317352 1
lp__ -11.97 0.00 0.73 -14.03 -12.14 -11.69 -11.51 -11.46 164598 1
Samples were drawn using NUTS(diag_e) at Fri Jan 27 19:50:09 2017.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
結果
mean se_m
ean
sd 2.5% 25% 50% 75% 97.5
%
n_eff Rhat
p 0.134 0 0.106 0.01 0.054 0.106 0.186 0.409 51289 1
pred 6.799 0.019 5.327 2 3 5 8 21 77584 1
● pのEAP推定値より、残り 4 回中 3 回以上成功する確率は平均 13.4%
● pred (x* + 2) の平均値は 6.799, 予測分布の区間は [2.000, 21.000] のため、平
均的に7回挑戦すれば新たに2つのぬいぐるみを取れ、余裕を持って 21 回挑戦す
れば目的を果たせる可能性が高い
プロットの出力
サンプルのヒストグラム
    事後平均の推移
p               pred

More Related Content

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

基礎からのベイズ統計学

  • 2. 問題 1. Mさんが UFO キャッチャーに挑戦しており、過去16回の結果 は×○××○○×××××○×××○、あと4回挑戦できます。結果がベル ヌイ試行に、失敗回数が負の二項分布に従っているとして、残 り4回中3回以上成功する確率はどれくらいでしょうか。 2. 2つのぬいぐるみを取るために多く見積もって何回挑戦する必 要がある?
  • 3. 各問題に適用するモデル 1. 結果がベルヌーイ試行に従うと仮定しθをサンプリングする。 その上で下記生成量 p (4回成功する確率 + 3回成功する確 率)を定義する p(t) = g(θ(t) ) = 4+0-1 C4-1 θ4 (1 - θ)0 + 3+1-1 C3-1 θ3 (1 - θ)1 2. 負の二項分布に従う予測分布の予測値    x*(t) 〜 f(2, θ(t) ) を生成し、成功回数である 2 を足した x*(t) + 2 によって2回 成功するまでの試行回数の予測分布を近似的に得る
  • 4. stanファイル data { int<lower=0> N; int<lower=0> x[N]; } parameters { real<lower=0, upper=1> theta; } model { x ~ bernoulli(theta); } generated quantities{ real p; #4回中3回以上成功する確率 real beta; int pred; #2回成功するまでの総試行数 p = 1*pow(theta, 4)*pow((1-theta),0)+4*pow(theta, 3)*pow((1-theta),1); beta = theta/(1-theta); pred = neg_binomial_rng(2, beta)+2; }
  • 5. Rスクリプト scr <- "model774.stan" N <- 16 x <- c(0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1) data <- list(N=N,x=x) par <- c("p", "pred") fit <- stan(file=scr, model_name=scr, data=data, pars=par, verbose=F, seed=123, chains=1, warmup=5000, iter=100000) library(ggmcmc) #チャート出力用ライブラリ ggmcmc(ggs(fit), file='fit-ggmcmc.pdf')
  • 6. 結果 > fit Inference for Stan model: model774.stan. 4 chains, each with iter=1e+05; warmup=10000; thin=1; post-warmup draws per chain=90000, total post-warmup draws=360000. mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat p 0.13 0.00 0.11 0.01 0.05 0.11 0.19 0.41 236584 1 pred 6.80 0.01 5.33 2.00 3.00 5.00 8.00 21.00 317352 1 lp__ -11.97 0.00 0.73 -14.03 -12.14 -11.69 -11.51 -11.46 164598 1 Samples were drawn using NUTS(diag_e) at Fri Jan 27 19:50:09 2017. For each parameter, n_eff is a crude measure of effective sample size, and Rhat is the potential scale reduction factor on split chains (at convergence, Rhat=1).
  • 7. 結果 mean se_m ean sd 2.5% 25% 50% 75% 97.5 % n_eff Rhat p 0.134 0 0.106 0.01 0.054 0.106 0.186 0.409 51289 1 pred 6.799 0.019 5.327 2 3 5 8 21 77584 1 ● pのEAP推定値より、残り 4 回中 3 回以上成功する確率は平均 13.4% ● pred (x* + 2) の平均値は 6.799, 予測分布の区間は [2.000, 21.000] のため、平 均的に7回挑戦すれば新たに2つのぬいぐるみを取れ、余裕を持って 21 回挑戦す れば目的を果たせる可能性が高い