SlideShare a Scribd company logo
1 of 23
Download to read offline
Stanでpsychophysics
──階層ベイズモデルで恒常法データを分析する──
Osaka.Stan #5 – LT資料 2017年7月1日
大阪大学大学院人間科学研究科D2・日本学術振興会
武藤 拓之 (Hiroyuki Muto)
01/23
サ イ コ フ ィ ジ ッ ク ス
Twitter: @mutopsy
Web: http://kiso.hus.osaka-u.ac.jp/muto/
自己紹介
武藤 拓之 (むとう ひろゆき)
• 大阪大学大学院人間科学研究科D2
研究分野
• 認知心理学
• メインテーマは空間的思考の身体性
• 【宣伝】つい最近論文がJEP:HPPにアクセプトされました!
Muto, H., Matsushita, S., & Morikawa, K. (in press). Spatial
perspective taking mediated by whole-body motor simulation.
Journal of Experimental Psychology: Human Perception and
Performance.
ベイズ歴
• 2017/4/25に自分がベイジアンであることに気が付きました。
02/23
錯視を測りたい
3本の線分は同じ長さ。
03/23
錯視を測りたい
矢羽を付けると長さが変わって見える=ミュラー・リヤー錯視
実際のところ何倍に見えているのか?
→心理物理学的測定法で測定できる!そのうちの1つが恒常法。
(psychophysical methods)
04/23
恒常法の例
左右の線分,どっちが長い?
標準刺激
(知覚される大きさを測定したい対象)
比較刺激
(ものさし)
1st
みぎ!
2nd
3rd
ひだり!
なやむ…
…
このような試行をランダムな順序で繰り返して0/1型のデータを収集する。
05/23
得られるデータの例 (ある個人のデータ)
参加者ごとに
プロビット関数をあてはめる
プロビット関数は
累積正規分布の
ことだよ!
06/23
得られるデータの例 (ある個人のデータ)
参加者ごとに
プロビット関数をあてはめる
選択率が50%となる長さ
=主観的等価点
(正規分布の平均値)
この人の場合,
は の
120%の長さに見えたと
解釈される
正規分布の標準偏差は
ノイズの大きさを表す120
07/23
3種類の推定方法を比較してみる
3種類の推定方法で結果を比較
1. 参加者ごとに最尤推定
2. 参加者ごとにベイズ推定
3. 階層ベイズでまとめて推定
使用するデータ
Web実験で収集したミュラー・リヤー錯視測定データ
 参加者:Twitter・Facebookで募集した延べ26名
(うち1名は逆に回答していたと思われるため分析から除外)
 標準刺激:主線が200 px (=100%) の外向図形と内向図形
(今回の分析では外向図形条件のデータのみを用いる)
 比較刺激:長さ50─200% (10%刻み) の線分11種類
 提示位置をカウンターバランスしランダム順に提示。各セル8試行。
実際の刺激の例→
08/23
1.参加者ごとに最尤推定 (1/1)
M <- 1:n
SD <- M
for (i in 1:n){
di <- data.frame(
x = seq(50,150,10), #比較刺激の幅
Rate = Rates[i] #比較刺激の選択率データのベクトル
)
fit <- glm(formula = di$Rate ~ di$x, family = binomial(probit)) #glm()で最尤推定
c1 <- coefficients((fit))
p1 <- c(-c1[1]/c1[2],1/c1[2])
M[i] <- p1[1]
SD[i] <- p1[2]
}
M #参加者ごとの平均値(等価点)ベクトル
SD #参加者ごとの標準偏差ベクトル
Rコード
09/23
2.参加者ごとにベイズ推定 (1/2)
data {
int N; #全部で何試行か。今回は2200 (= 88試行 × 25人)。
int NP; #参加者の数。今回は25。
real Length[N]; #比較刺激の水準 (単位は%) = {50, 60, …, 140, 150}
int P[N]; #参加者番号 = {1, 2, …, 24, 25}
int <lower=0, upper=1> SelectC[N]; #比較刺激を選んだか否かのベクトル = {0, 1, 1, …}
}
parameters{
real<lower=0, upper=200> mu[NP]; #参加者一人ひとりの平均
real<lower=0, upper=50> sigma[NP]; #参加者一人ひとりの標準偏差
}
transformed parameters{
real<lower=0, upper=1> p[N];
for (n in 1:N){
p[n] = normal_cdf(Length[n], mu[P[n]], sigma[P[n]]); #累積正規分布の確率を取得
}
}
Stanコード (1/2)
母数の範囲を指定しないと
うまく収束しないよ!
10/23
2.参加者ごとにベイズ推定 (2/2)
model{
for (n in 1:N){
SelectC[n] ~ bernoulli(p[n]); #ベルヌーイ分布から反応データ (0/1) が生じるモデル
}
}
generated quantities{ #参加者間の平均 (mu0とsigma0) を生成
real<lower=0, upper=200> mu0;
real<lower=0, upper=50> sigma0;
mu0 = 0;
sigma0 = 0;
for (np in 1:NP){
mu0 = mu0 + mu[np];
sigma0 = sigma0 + sigma[np];
}
mu0 = mu0 / NP;
sigma0 = sigma0 / NP;
}
Stanコード (2/2)
11/23
3.階層ベイズでまとめて推定 (1/2)
data {
int N;
int NP;
real Length[N];
int P[N];
int <lower=0, upper=1> SelectC[N];
}
parameters{
real<lower=0, upper=200> mu[NP];
real<lower=0, upper=50> sigma[NP];
real<lower=0, upper=200> mu0; #全体平均
real<lower=0, upper=50> sigma0; #全体標準偏差
real<lower=0, upper=200> s_mu0; #参加者による平均のばらつき
real<lower=0, upper=200> s_sigma0; #参加者による標準偏差のばらつき
}
Stanコード (1/2)
12/23
3.階層ベイズでまとめて推定 (2/2)
transformed parameters{
real<lower=0, upper=1> p[N];
for (n in 1:N){
p[n] = normal_cdf(Length[n], mu[P[n]], sigma[P[n]]);
}
}
model{
for (np in 1:NP){
mu[np] ~ normal(mu0,s_mu0); #参加者ごとの平均を得る
sigma[np] ~ normal(sigma0,s_sigma0); #参加者ごとの標準偏差を得る
}
for (n in 1:N){
SelectC[n] ~ bernoulli(p[n]);
}
}
Stanコード (2/2)
参加者一人ひとりの平均が
Normal(全体平均, s_mu0) に
従うと仮定したよ!
標準偏差も同様!
13/23
ある参加者の結果
個別に最尤推定
個別にベイズ推定
階層ベイズ
※推定値としてEAPを使用。
14/23
みんなの結果 (1/2)
個別に最尤推定 個別にベイズ推定 階層ベイズ
15/23
みんなの結果 (2/2)
個別に最尤推定 個別にベイズ推定 階層ベイズ
16/23
推定法による母平均の違い
点推定値はほとんど同じ
区間推定幅が最も狭いのは
個別にベイズ推定したとき
エラーバーは95%信頼区間または95%確信区間。
ベイズ推定で過大推定傾向
(分布の歪みが原因?)
区間推定幅が最も狭いのは
個別にベイズ推定したとき
17/23
データを減らしたらどうなるか
#ランダムに欠損を作る
V <- 1:nrow(d)
Smpl <- sample(V,nrow(d)*0.5) #何パーセントにするか
d_sps <- d[Smpl,]
Rコード
データを半分にしてみる
個別に最尤推定
個別にベイズ推定
階層ベイズ
↓ある参加者の結果 ※条件によって分母が異なる
18/23
欠損データのみんなの結果 (1/2)
個別に最尤推定 個別にベイズ推定 階層ベイズ
19/23
欠損データのみんなの結果 (2/2)
個別に最尤推定 個別にベイズ推定 階層ベイズ
20/23
推定法による母平均の違い(欠損データ)
どの推定法でも
あまり変わらない。
データを削っても
意外と正確に推定できている。
エラーバーは95%信頼区間または95%確信区間。
ベイズ推定で過大推定傾向
区間推定幅が最も狭いのは
個別にベイズ推定したとき
21/23
まとめと考察
 全体平均の点推定値はどの推定方法でもあまり変わらなかった。
 データ数を減らしても割と正確に全体平均を推定できた。
→ミュラー・リヤー錯視が頑健すぎるから?
 全体平均の区間推定幅は個別にベイズ推定した時に最も狭くなった。
→なぜかは不明。
→今回のデータに特有の結果なのか一般的な傾向なのか要検討。
 全体標準偏差の推定値は推定方法に影響された (ベイズで過大推定傾向)。
→分布の歪みが原因?参加者ごとのMAP推定値の平均をとるべき?
 全体標準偏差の区間推定幅は個別にベイズ推定した時に最も狭くなった。
→なぜかは不明。
 結局どの推定方法が一番いいの?
→見かけ上は個別にベイズ推定した時に精度が高かった。
→最初に想定するモデル(分析者の信念)とデータの特徴次第?
22/23
どんなにくるしくても
おいしいものたべて
ベイズしたらなおるよ!
なおるよ!
23/23

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
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
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
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...
 

Stanでpsychophysics──階層ベイズモデルで恒常法データを分析する──【※Docswellにも同じものを上げています】