Mo_
Q§IπΫθΖ»Μg£Ε
]θ@f[^ΜxCYͺΝ
ͺ{ΐ°A2019.10A2023.05
@Q§Iπi2 alternative-forced-choice: 3AFCjΫθΜκAmCYhΖVOihͺesΙ¨’Δρ¦³κιͺAσΤIΚuπΟ¦ΔiEΖΆA ι’ΝγΖΊΘΗj―Ιρ¦³κικA ι’Νρ¦ΜΤπΟ¦ΔiζPC^oΖζQC^ojρ¦³κικͺ ιBvfπl¦ιΖ«ΝAσΤ ι’ΝΤΙ¨―ιQΒΜhρ¦@πΖΰΙA ι’ΝAΕ\΅Δζ’BAΝAhͺσΤΚuΕρ¦³κΔ’ιΖ«ΝAα¦ΞAΆ€ΙmCYhAE€ΙVOihͺρ¦³κι±Ζπ\΅AΤΜΖ«ΝζPC^oΕmCYhͺρ¦³κAζQC^oΕVOihͺρ¦³κι±Ζπ\·BAΜΖ«ΝAͺtΙΘιBΘγΜΰΎΕΝAα¦ΞAΝAΝζPΚuAΝζQΚuΙρ¦³κιππ\·Ζ’€±ΖΙ·ιBhρ¦πΚΙ»fi½jπͺή·ιΖ\1Μζ€ΙΘιB
\1@2AFCΫθΙ¨―ιhρ¦πΖ½i»fjB
|
VOihΜρ¦ΚuΖ΅Δ»f³κ½Κu |
|
|
ζPΚu |
ζQΚu |
A |
λ½ |
³½ |
A |
³½ |
λ½ |
@’άA1AFCΫθΜfΖ―ΆAmCYhΜ΄oͺ½ΟOAͺUPΜ³KͺzΙ]’AVOihΜ΄oͺ½ΟAͺUΜ³KͺzΙ]€ΰΜΖ·ιiͺUKEX^fjB·ΘνΏA
A@
Ε ιB
@ρ¦πA¨ζΡAΙ¨’ΔPνλ·¨ζΡΚuIπoCAXπl¦ιBPνλ·ΝAΤλ· ι’ΝσΤλ·π\·BΚuIπoCAXΝA΄oΜα’ΜΩΚΖΝΚΙζPΚu ι’ΝζQΚuΜIππDήXόπ\·B±κηΜoCAXπάΖίΔ
Ζ¨«AζQΚuπξΙ΅½ζPΚuΦΜoCAXψΚΖ΅Δ\·ΖA΄o¨ζΡΜͺzΝΘΊΜζ€ΙΘιB
hρ¦ͺAΜΖ«A
A@
Ε^¦ηκA
ΖΘιB
hρ¦ͺAΜΖ«A
A@
Ε^¦ηκA
ΖΘιB
@]θ@Ι¨―ι»fJeSΜ«EliξljπΖ¨B·ΘνΏAVOihΜ΄oΖmCYhΜ΄oΜ·ͺΖΜΤΙ ιΖ«JeSΜ»fΙΘιΖl¦ιB
ΜΖ«
Ο@Μ»fJeS
Ε ιB
@»fJeSΜͺSJeSΜΖ«Aα¦Ξ»fJeSΝΜζ€ΙΘιB±±ΕAΜlΝAVOihΜ΄oͺ’ΩΗJeSΜlΝε«’lΙΘιͺAAΖAΕΝVOihΜρ¦ΚuͺΩΘι±ΖΙΣB
AΜΖ«A
JeSPF@VOiΝζPΚuΕ ιB
JeSQF@VOiΝ½ͺζPΚuΕ ιB
JeSRF@VOiΝ½ͺζQΚuΕ ιB
JeSSF@VOiΝζQΚuΕ ιB
AΜΖ«A
JeSPF@VOiΝζQΚuΕ ιB
JeSQF@VOiΝ½ͺζQΚuΕ ιB
JeSRF@VOiΝ½ͺζPΚuΕ ιB
JeSSF@VOiΝζPΚuΕ ιB
@’άA»fJeSΜπΖ¨’½Ζ«AJeS«Eπ
Ζ¨BέΟW³KͺzΦΙΞ΅Δ
A@
Ζ¨’½Ζ«A»fJeSͺJeSΕ ιm¦ΝΜζ€Ι^¦ηκιB
AΜΖ«AJeSΕ ιm¦ΝAiPjζθ
ΖΘιB
AΜΖ«AJeSΕ ιm¦ΝAiQjζθ
ΖΘιB
\2@hρ¦πΙΞ·ιJeS]θ»fΜpxB
|
JeSP |
EEE |
JeSk |
EEE |
JeSK |
A |
|
EEE |
|
EEE |
|
A |
|
EEE |
|
EEE |
|
@ehρ¦πΙΞ·ιJeS»fΜpxͺ\2Μζ€Ε ιΖ«AήxΦΝΕ^¦ηκιB
@fΜp[^ΜΝ
Ε ιͺAiRj¨ζΡiSjΜΦΜψΜͺ`©ηΘΊΜζ€Θp[^lΜsθ«ͺFίηκιB
@ͺΜͺκqΙ―Άπ|―ΔΰlΝΟνηΘ’ΜΕAͺκΜlπΖ¨’ΔΰκΚ«ΝΈνκΘ’B±κΝAͺUfij ι’ΝζθκΚIΙΝ΄oΜPΚπΕ ιζ€Ιέθ·ιΖ’€±ΖΕ ιB
΅©΅ABrady et al. (2023; https://link.springer.com/article/10.3758/s13423-022-02179-w)ΝAL―ΜptH[}XΜ€Ι¨’ΔΝQAFCπp’ι±Ζπ§΅Δ’ιͺA³ηΙAsͺUfͺROCΘόΙζ€ΖΰΎ΅Δ’ιip. 442jB2AFCπg£΅ΔsͺUfͺKpΕ«ιζ€ΙHv³κ½ΐ±@ΖͺΝfͺρΔ³κΔ’ιihttps://osf.io/ts2eq/jBsͺUͺ\z³κικΝA±Μg£2§Iπ]θ@πp’ιΧ«Ε λ€Bg£ΕΙΒ’ΔΝA{EFuTCgΜγΌΕΰΎ΅½B
WΜQAFCΫθΙΒ’Δc_π±―ιB
±ΜκΝAͺUfΕl¦ιͺA΄oΜΩΚΝΝ
Ζ\L³κιB
@ά½AͺqΙ¨―ιΖΙ―ΆθπΑ¦Δΰ
Ε ιΜΕAp[^lπίι½ίΙΝ§ρπͺKvΕ ιB΄oΜ·Μ»fͺ΄_ΙΦ΅ΔΞΜΕ ιΖ·ιΖA±κΝJeS«EΙΜΌθπ¨±ΖΕ ιB
@JeSͺτi@©RjΜΖ«
@±ΜΖ«AfΜp[^Μ©RxΝ
ΖΘιB
@JeSͺοi@©RjΜΖ«
@±ΜΖ«AfΜp[^Μ©RxΝ
ΖΘιB
@\2Μf[^Μ©RxΝA\2Μf[^πhρ¦πΙ¨―ιpxΜδ¦f[^Ζl¦κΞ
ΖΘιBp[^ΜθͺsθΖΘηΘ’½ίΙΝAp[^Μ©RxΝf[^Μ©RxΘΊΕΘ―κΞΘηΘ’B·ΘνΏA
Ε ιͺA±ΜπΝ½³κΔ’ιB
γLΜfΙξΓxCYͺΝΜ½ίΜStanXNvgΖ»κπp’ιPythonXNvgπAKQiWIΘQAFCΫθjAKͺοAKͺSΘγΜτΜRΒΜκΙͺ―Δ쬡Δέ½BΘ¨APythonpΜStaniPyStanjΙΒ’ΔΝAΩͺ{ΐ°u’ά³η·―Θ’PythonΕf[^ͺΝvΫPoΕΕΰΎ΅Δ’ιBMo_ΜξbIΘΰΎπΩͺ{ΐ°uSwf[^ͺΝΖͺθv€[ ι’Νͺ{ΐ°uvΚSwv|ΩΕsΑΔ’ιB
K=2ΜκiWIΘQAFCΫθj
StanXNvgXgA.1Μζ€ΙpΣ΅½B
XgA.1@K=2ΜκΜStanXNvgit@CΌSDT2AFC2Cat.stanj
data {
int n_NS[2];
int n_SN[2];
}
parameters {
real mu_s;
real tau;
}
transformed parameters {
simplex[2] p_NS;
simplex[2] p_SN;
p_NS[1] = Phi(-(mu_s -
tau)/sqrt(2.0));
p_NS[2] = 1 - p_NS[1];
p_SN[1] = Phi(-(mu_s +
tau)/sqrt(2.0));
p_SN[2] = 1 - p_SN[1];
}
model {
mu_s ~ normal(0.0, 100.0);
tau ~ normal(0.0, 100.0);
n_NS ~ multinomial(p_NS);
n_SN ~ multinomial(p_SN);
}
XgA.1ΜStanXNvgt@CSDT2AFC2Cat.stanπp·ιPythonXNvgπAXgA.2Μζ€ΙpΣ΅½B
XgA.2@StanXNvgt@CSDT2AFC2Cat.stanπp·ιPythonXNvgit@CΌSDT2AFC2Cat.pyj
import numpy as np
import pystan
import matplotlib.pyplot as plt
import csv
flnm = input('όΝf[^t@CΌ(*.csv) = ')
with open(flnm, 'r') as f:
data = [v for v in csv.reader(f)]
fout_nm = input('oΝeLXgt@CΌ(*.txt) = ')
fout = open(fout_nm, 'w')
fout.write('Input Data File =
{}\n'.format(flnm))
Freq_NS = []
Freq_NS.append(int(data[1][1]))
Freq_NS.append(int(data[1][2]))
Freq_SN = []
Freq_SN.append(int(data[2][1]))
Freq_SN.append(int(data[2][2]))
print(Freq_NS)
print(Freq_SN)
fout.write('<N, S>:
{}'.format(Freq_NS))
fout.write('\n<S, N>:
{}'.format(Freq_SN))
TN_NS = sum(Freq_NS)
Rating_NS = []
Rating_NS.append(Freq_NS[0])
Rating_NS.append(Freq_NS[1])
TN_SN = sum(Freq_SN)
Rating_SN = []
Rating_SN.append(TN_SN - Freq_SN[0])
Rating_SN.append(TN_SN - Freq_SN[1])
Data = {'n_NS': Rating_NS, 'n_SN':
Rating_SN}
sm = pystan.StanModel(file =
'SDT2AFC2Cat.stan')
fit = sm.sampling(data = Data, n_jobs
= 1)
print(fit)
fout.write('\n{}\n'.format(fit))
mu = fit['mu_s']
tau = fit['tau']
p_NS = fit['p_NS']
p_SN = fit['p_SN']
mu_L05 = np.percentile(mu, 5)
mu_med = np.percentile(mu, 50)
mu_U95 = np.percentile(mu, 95)
fout.write("\nd': \nMed. =
{0:<.3f}, 90%CI = [{1:<.3f},
{2:<.3f}".
format(mu_med, mu_L05, mu_U95))
tau_L05 = np.percentile(tau, 5)
tau_med = np.percentile(tau, 50)
tau_U95 = np.percentile(tau, 95)
fout.write('\ntau: \nMed. =
{0:<.3f}, 90%CI ~ [{1:<.3f},
{2:<.3f}]'.
format(tau_med,
tau_L05, tau_U95))
p1 = np.median(p_NS, axis = 0)
p2 = np.median(p_SN, axis = 0)
p2 = [p2[1], p2[0]]
plt.hist(mu)
plt.xlabel("d'($\mu_S$)",
fontsize = 14)
plt.title("Posterior Distribution
of d'($\mu_S$)" + \
'\nMed. = {0:<.3f}, 90%CI
= [{1:M<.3f}, {2:<.3f}]'.
format(mu_med, mu_L05, mu_U95), fontsize = 16)
plt.show()
plt.hist(tau)
plt.xlabel(r'$\tau$', fontsize = 18)
plt.title(r'Posterior Distribution of
$\tau$' + \
'\nMed. = {0:<.3f}, 90%CI
= [{1:<.3f}, {2:<.3f}]'.
format(tau_med, tau_L05, tau_U95), fontsize = 16)
plt.show()
xcat = [1, 2]
xlabels = ['Cat-1', 'Cat-2']
y1 = [Freq_NS[0]/TN_NS,
Freq_NS[1]/TN_NS]
y2 = [Freq_SN[0]/TN_SN,
Freq_SN[1]/TN_SN]
plt.plot(xcat, y1, 'b:', linewidth = 10,
label = 'Data/<N, S>')
plt.plot(xcat, p1, 'g-', linewidth =
3, label = 'Model/<N, S>')
plt.plot(xcat, y2, 'r:', linewidth =
10, label = 'Data/<S, N>')
plt.plot(xcat, p2, 'm-', linewidth =
3,label = 'Model/<S, N>')
plt.xticks(xcat, xlabels, fontsize =
14)
plt.xlim(0.8, 2.2)
plt.xlabel('Rating Category', fontsize
= 14)
plt.ylabel('Probability/Proportion',
fontsize = 14)
plt.title('Rating in Conditions <N,
S> and <S, N>', fontsize = 18)
plt.legend(loc = 'upper center',
fontsize = 10)
plt.show()
fout.close()
print('\n' + fout_nm + ' was
saved.\n')
XgA.1ΖXgA.2Μt@C¨ζΡTvf[^t@CΝAάΖίΔ³kt@CRating2Cat.zipΖ΅½B_E[hπ·κΞA©RΙpΕ«ιB
XgA.2Μt@CSDT2AFC2Cat.pyπΐs·ιΖAόΝf[^t@CΌΖoΝf[^t@CΌΜέθͺίηκιi}A.1jB
}A.1
oΝf[^t@CΝCΣΜeLXgt@CΌit@Cg£q.txtjΕ ιͺAόΝf[^t@CΝCSV`Μt@CΖ΅Δ}A.2ΜlΕpΣ·ιB
}A.2@f[^t@CData2Cat.csv
ζPsΪΝΟΌΜΌOπέθ·ιͺAvOΕΝp’Θ’ΜΕCΣΜΆρΕζ’B½Ύ΅AζPsΪζPρΪΙΆρIDπέθ·ιΖAExcelΜκAΗέέΙG[bZ[Wͺ\¦³κι±Ζͺ ιͺA±κΝ³·ιBζQsΪΙhρ¦πNAS>iα¦ΞAΆΙmCYhAEΙVOihjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOihΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζRsΪΙhρ¦πSANiα¦ΞAΆΙVOihAEΙmCYhjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOihΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζQsΪAζRsΪΖΰAζQρΪΝuVOihΝζPΚuΕ ιiα¦ΞAVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΝuVOihΝζQΚuΕ ιiα¦ΞAVOihΝEΕ ιjvΖ»f³κ½xΕ ιBf[^ΜέθͺIνκΞAt@Cg£qΖ΅Δu.csvvπIρΕΫΆ·ιΖACSV`Μt@CΖ΅ΔΫΆ³κιB
}A.1Μζ€ΙόΝf[^t@CΌΖoΝeLXgt@CΌπέθ·ιΖAvZͺnάιBStanΙζιTvOͺIΉ·ιΖAάΈijΜγͺzΜqXgOͺ\¦³κιi}A.3jB
}A.3
γͺzΜlͺMed.=1.075A90CIͺ[0.850, 1.316]Ε ι±Ζͺ¦³κΔ’ιB
}A.3ΜΣ§ήπΒΆιΖAΡΜγͺzΜqXgOͺ\¦³κιi}A.4jB
}A.4
γͺzΜlͺMed.=0.335A90CIͺ[0.106, 0.579]Ε ι±Ζͺ¦³κΔ’ιB
}A.4ΜtH[πΒΆιΖAe»fJeSΜm¦^δ¦π¦·OtͺάκόOtΕ\¦³κιi}A.5jB
}A.5
f[^ͺjόΕδ¦π\΅AfͺΐόΕe»fJeSΜm¦ΜlΕ ιBuVOihΝζPΚuΕ ιv»fͺuCat-1vΕAuVOihΝζQΚuΕ ιv»fͺuCat-2vΕ\³κΔ’ιB
}A.5ΜtH[πΒΆιΖAvOΜΐsIΉΖΘιBΐsIΉγAoΝt@CπKΘGfB^ΕJΖAΘΊΜζ€ΙΘΑΔ’ιB
Input Data File = Data2Cat.csv
<N, S>: [30, 70]
<S, N>: [84, 16]
Inference for Stan model:
anon_model_76fee9688e040eaa9d47a70bb9cf69e2.
4 chains, each with iter=2000;
warmup=1000; thin=1;
post-warmup draws per chain=1000,
total post-warmup draws=4000.
mean se_mean
sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
mu_s 1.08 2.6e-3 0.14 0.8 0.99 1.08 1.18 1.37 3058 1.0
tau 0.34 2.3e-3 0.14 0.06 0.24 0.34 0.43 0.62 3648 1.0
p_NS[0] 0.3 7.2e-4 0.05 0.22 0.27 0.3 0.33 0.39 4000 1.0
p_NS[1] 0.7 7.2e-4 0.05 0.61 0.67 0.7 0.73 0.78 4000 1.0
p_SN[0] 0.16 6.8e-4 0.04 0.1 0.13 0.16 0.18 0.24 2877 1.0
p_SN[1] 0.84 6.8e-4 0.04 0.76 0.82 0.84 0.87 0.9 2877 1.0
lp__ -106.0 0.02 1.04 -108.7 -106.4 -105.7 -105.3
-105.0 1800 1.0
Samples were drawn using NUTS at Tue
Oct 22 10:30:19 2019.
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).
d':
Med. = 1.082, 90%CI = [0.847, 1.320
tau:
Med. = 0.339, 90%CI ~ [0.105, 0.577]
KͺοΜκ
»fΜJeSKͺοΜκΜStanXNvgπXgB.1Μζ€ΙpΣ΅½B
XgB.1@KͺοΜκΜStanXNvgit@CΌSDT2AFCOddCat.stanj
functions {
real half_normal_lpdf(real
y, real sgm){
if
(y > 0.0){
return normal_lpdf(y | 0.0, sgm);
}
else {
return log(0.0);
}
}
}
data {
int K;
int n_NS[K];
int n_SN[K];
}
parameters {
real mu_s;
real tau;
real<lower = 0.0>
theta[(K - 1) / 2];
}
transformed parameters {
real C[K - 1];
simplex[K] p_NS;
simplex[K] p_SN;
C[(K - 1) / 2 + 1] =
theta[1];
C[(K - 1) / 2] = -C[(K - 1)
/ 2 + 1];
for (k in 2: ((K - 1) / 2)){
C[(K
- 1) /2 + k] = C[(K - 1) / 2 + k - 1] + theta[k];
C[(K
- 1) / 2 - k + 1] = -C[(K - 1) / 2 + k];
}
p_NS[1] = Phi((C[1] - (mu_s
- tau))/sqrt(2.0));
p_NS[K] = 1 - Phi((C[K - 1]
- (mu_s - tau))/sqrt(2.0));
for (k in 2:(K-1)) {
p_NS[k] = Phi((C[k] - (mu_s - tau))/sqrt(2.0)) -
Phi((C[k - 1] - (mu_s - tau))/sqrt(2.0));
}
p_SN[1] = Phi((C[1] - (mu_s
+ tau))/sqrt(2.0));
p_SN[K] = 1 - Phi((C[K - 1]
- (mu_s + tau))/sqrt(2.0));
for (k in 2:(K-1)) {
p_SN[k] = Phi((C[k] - (mu_s + tau))/sqrt(2.0)) -
Phi((C[k - 1] - (mu_s + tau))/sqrt(2.0));
}
}
model {
for (k in 1:((K - 1) / 2)) {
theta[k] ~ half_normal(1000.0);
}
mu_s ~ normal(0.0, 100.0);
tau ~ normal(0.0, 100.0);
n_NS ~ multinomial(p_NS);
n_SN ~ multinomial(p_SN);
}
XgB.1ΜStanXNvgSDT2AFCOddCat.stanπp·ιPythonXNvgπAXgB.2Μζ€ΙpΣ΅½B
XgB.2@StanXNvgSDT2AFCOddCat.stanπp·ιPythonXNvgit@CΌSDT2AFCOddCat.pyj
import numpy as np
import pystan
import matplotlib.pyplot as plt
import csv
flnm = input('όΝf[^t@C(*.csv) = ')
with open(flnm, 'r') as f:
data = [v for v in
csv.reader(f)]
fout_nm = input('oΝeLXgt@CΌ = ')
fout = open(fout_nm, 'w')
fout.write('\nInput Data File =
{}\n'.format(flnm))
K = len(data[0]) - 1
print('K = ', K)
if (K % 2) == 0:
print('JeS K ΝοΕΘ―κΞΘηΘ’I')
import sys
sys.exit()
Freq_NS = []
for k in range(K):
Freq_NS.append(int(data[1][1
+ k]))
Freq_SN = []
for k in range(K):
Freq_SN.append(int(data[2][1
+ k]))
print(Freq_NS)
print(Freq_SN)
fout.write('\n<N,
S>\n{}\n'.format(Freq_NS))
fout.write('\n<S,
N>\n{}\n'.format(Freq_SN))
TN_NS = sum(Freq_NS)
Rating_NS = Freq_NS
TN_SN = sum(Freq_SN)
Rating_SN = []
for k in range(K):
Rating_SN.append(Freq_SN[K -
1 - k])
Data = {'K': K, 'n_NS': Rating_NS,
'n_SN': Rating_SN}
sm = pystan.StanModel(file =
'SDT2AFCOddCat.stan')
fit = sm.sampling(data = Data, n_jobs
= 1)
print(fit)
fout.write('\n{}\n'.format(fit))
mu = fit['mu_s']
tau = fit['tau']
C = fit['C']
p_NS = fit['p_NS']
p_SN = fit['p_SN']
mu_L05 = np.percentile(mu, 5)
mu_med = np.percentile(mu, 50)
mu_U95 = np.percentile(mu, 95)
fout.write("\nd':\nMedian =
{0:<.3f}, 90%CI =
[{1:<.3f}, {2:<.3f}]\n".
format(mu_med, mu_L05, mu_U95))
tau_L05 = np.percentile(tau, 5)
tau_med = np.percentile(tau, 50)
tau_U95 = np.percentile(tau, 95)
fout.write('\ntau:\nMedian =
{0:<.3f}, 90%CI =
[{1:<.3f}, {2:<.3f}]\n'.
format(tau_med,
tau_L05, tau_U95))
C_L05 = np.zeros(K-1)
C_med = np.zeros(K-1)
C_U95 = np.zeros(K-1)
for k in range(K-1):
C_L05[k] =
np.percentile(C.T[k], 5)
C_med[k] =
np.percentile(C.T[k], 50)
C_U95[k] =
np.percentile(C.T[k], 95)
for k in range(K-1):
fout.write(('\nC[{0}]:\n' +
\
'Median = {1:<.3f},
90%CI = [{2:<.3f}, {3:<.3f}]\n').
format(k+1, C_med[k], C_L05[k], C_U95[k]))
plt.hist(mu)
plt.xlabel("d'($\mu_S$)",
fontsize = 14)
plt.title("Posterior Distribution
of d'($\mu_S$)" + \
'\nMed. = {0:<.3f},
90%CI = [{1:<.3f}, {2:<.3f}]'.
format(mu_med, mu_L05, mu_U95), fontsize = 16)
plt.show()
plt.hist(tau)
plt.xlabel(r'$\tau$', fontsize = 18)
plt.title(r'Posterior Distribution of
$\tau$' + \
'\nMed. = {0:<.3f},
90%CI = [{1:<.3f}, {2:<.3f}]'.
format(tau_med, tau_L05, tau_U95), fontsize = 16)
plt.show()
for k in range(K-1):
plt.hist(C.T[k], label =
'C{}'.format(k+1))
plt.title('Posterior Distributions of
Category Boundaries', fontsize = 18)
plt.legend()
plt.show()
p1 = np.median(p_NS, axis = 0)
p2 = np.median(p_SN, axis = 0)
p2 = np.flip(p2)
xcat = np.arange(1, K+0.1, 1)
xlabels = ['{}'.format(int(v)) for v
in xcat]
y1 = []
y2 = []
for k in range(K):
y1.append(Freq_NS[k]/TN_NS)
y2.append(Freq_SN[k]/TN_SN)
plt.plot(xcat, y1, 'b--', linewidth =
3, alpha = 0.7, label = 'Data/<N, S>')
plt.plot(xcat, p1, 'g-', linewidth =
3, alpha = 0.7, label = 'Model/<N, S>')
plt.plot(xcat, y2, 'r--', linewidth =
3, alpha = 0.7, label = 'Data/<S, N>')
plt.plot(xcat, p2, 'm-', linewidth =
3, alpha = 0.7, label = 'Model/<S, N>')
plt.xticks(xcat, xlabels, fontsize =
14)
plt.xlabel('Rating Category', fontsize
= 14)
plt.ylabel('Probability/Proportion',
fontsize = 14)
plt.title('Ratings in Conditions
<N, S> and <S, N>', fontsize = 18)
plt.legend(loc = 'upper center',
fontsize = 10)
plt.show()
fout.close()
print('\n{} was
saved.\n'.format(fout_nm))
XgB.1ΖXgB.2Μt@C¨ζΡTvf[^t@CΝAάΖίΔ³kt@CRatingOddCat.zipΖ΅½B_E[hπ·κΞA©RΙpΕ«ιB
XgB.2Μt@CSDT2AFCOddCat.pyπΐs·ιΖAόΝf[^t@CΌΖoΝf[^t@CΌΜέθͺίηκιi}B.1jB
}B.1
oΝf[^t@CΝCΣΜeLXgt@CΌit@Cg£q.txtjΕ ιͺAόΝf[^t@CΝCSV`Μt@CΖ΅Δ}B.2ΜlΕpΣ·ιB
}B.2@f[^t@CData3Cat.csv
ζPsΪΝΟΌΜΌOπέθ·ιͺAvOΕΝp’Θ’ΜΕCΣΜΆρΕζ’B½Ύ΅AζPsΪζPρΪΙΆρIDπέθ·ιΖAExcelΜκAΗέέΙG[bZ[Wͺ\¦³κι±Ζͺ ιͺA±κΝ³·ιBζQsΪΙhρ¦πNAS>iα¦ΞAΆΙmCYhAEΙVOihjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOiΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΙuν©ηΘ’vΖ»f³κ½xAζSρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζRsΪΙhρ¦πSANiα¦ΞAΆΙVOihAEΙmCYhjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOihΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζ3ρΪΙuν©ηΘ’vAζSρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζQsΪAζRsΪΖΰAζQρΪΝuVOihΝζPΚuΕ ιiα¦ΞAVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΝuν©ηΘ’vAζSρΪΝuVOihΝζQΚuΕ ιiα¦ΞAVOihΝEΕ ιjvΖ»f³κ½xΕ ιBf[^ΜέθͺIνκΞAt@Cg£qΖ΅Δu.csvvπIρΕΫΆ·ιΖACSV`Μt@CΖ΅ΔΫΆ³κιB
}B.1Μζ€ΙόΝf[^t@CΌΖoΝeLXgt@CΌπέθ·ιΖAvZͺnάιBStanΙζιTvOͺIΉ·ιΖAάΈijΜγͺzΜqXgOͺ\¦³κιi}B.3jB
}B.3
γͺzΜlͺMed.=1.055A90CIͺ[0.834, 1.262]Ε ι±Ζͺ¦³κΔ’ιB
}B.3ΜΣ§ήπΒΆιΖAΡΜγͺzΜqXgOͺ\¦³κιi}B.4jB
}B.4
γͺzΜlͺMed.=0.403A90CIͺ[0.194, 0.614]Ε ι±Ζͺ¦³κΔ’ιB
}B.4ΜtH[πΒΆιΖAJeS«EΜγͺzͺ¦³κιi}B.5jB
}B.5
}B.5ΜtH[πΒΆιΖAe»fJeSΜm¦^δ¦π¦·OtͺάκόOtΕ\¦³κιi}B.6jB
}B.6
f[^ͺjόΕδ¦π\΅AfͺΐόΕe»fJeSΜm¦ΜlΕ ιBuVOiΝζPΚuΕ ιv»fͺuJeSPvΕAuν©ηΘ’v»fͺuJeSQvAuVOiΝζQΚuΕ ιv»fͺuJeSRvΕ\³κΔ’ιB
}B.6ΜtH[πΒΆιΖAvOΜΐsIΉΖΘιBΐsIΉγAoΝt@CπKΘGfB^ΕJΖAΘΊΜζ€ΙΘΑΔ’ιB
Input Data File = Data3Cat.csv
<N, S>
[20, 26, 54]
<S, N>
[77, 12, 11]
Inference for Stan model:
anon_model_4f4c02dce251e874ae19399d5b4bfa08.
4 chains, each with iter=2000;
warmup=1000; thin=1;
post-warmup draws per chain=1000,
total post-warmup draws=4000.
mean se_mean
sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
mu_s 1.05 2.0e-3 0.13 0.8 0.97 1.05 1.14 1.3 4000 1.0
tau
0.4 2.1e-3 0.13 0.15 0.32 0.4 0.49 0.65 3685 1.0
theta[0] 0.46 1.2e-3 0.07 0.33 0.41 0.46 0.5 0.6 3380 1.0
C[0] -0.46 1.2e-3 0.07 -0.6 -0.5 -0.46 -0.41 -0.33 3380 1.0
C[1] 0.46 1.2e-3 0.07 0.33 0.41 0.46 0.5 0.6 3380 1.0
p_NS[0] 0.22 6.2e-4 0.04 0.15 0.19 0.22 0.24 0.3 4000 1.0
p_NS[1] 0.23 5.3e-4 0.03 0.17 0.2 0.23 0.25 0.3 4000 1.0
p_NS[2] 0.55 7.7e-4 0.05 0.46 0.52 0.55 0.59 0.65 4000 1.0
p_SN[0] 0.09 4.9e-4 0.02 0.05 0.07 0.09 0.11 0.15 2583 1.0
p_SN[1] 0.15 4.4e-4 0.03 0.1 0.13 0.15 0.17 0.21 4000 1.0
p_SN[2] 0.76 6.9e-4 0.04 0.67 0.73 0.76 0.79 0.83 3707 1.0
lp__ -181.4 0.03 1.25 -184.6 -181.9 -181.0 -180.4
-179.9 1942 1.0
Samples were drawn using NUTS at Wed
Oct 23 11:33:50 2019.
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).
d':
Median = 1.055, 90%CI = [0.834, 1.262]
tau:
Median = 0.403, 90%CI = [0.194, 0.614]
C[1]:
Median = -0.455, 90%CI = [-0.575, -0.353]
C[2]:
Median = 0.455, 90%CI = [0.353, 0.575]
ΙA»fJeSͺTΒΜκiK=5jΜαπ¦·B
f[^απ}B.7Ι¦·B
}B.7@f[^t@CΌData5Cat.csv
vOπN΅ΔA}B.8Μζ€ΙόΝf[^t@CΌΖoΝf[^t@CΌπέθ·ιB
}B.8
όΝf[^t@CΌΖoΝf[^t@CΌπέθ·ιΖvZͺnάθAStanΙζιTvOͺIΉ·ιΖAάΈdfΜγͺzͺ\¦³κιi}B.9jB
}B.9
}B.9ΜtH[πΒΆιΖAΡΜγͺzͺ\¦³κιi}B.10jB
}B.10
}B.10ΜtH[πΒΆιΖAJeS«EΜγͺzͺ\¦³κιi}B.11jB
}B.11
}B.11ΜtH[πΒΆιΖA»fJeSΜδ¦Ζm¦ͺ\¦³κιi}B.12jB
}B.12
f[^ͺjόΕδ¦π\΅AfͺΐόΕe»fJeSΜm¦ΜlΕ ιBα¦ΞAuVOiΝζPΚuΕ ιv»fͺuJeSPvAu½ΤρVOiΝζPΚuΕ ιv»fͺuJeSQvAuν©ηΘ’v»fͺuJeSRvAu½ΤρVOiΝζQΚuΕ ιv»fͺuJeSSvAuVOiΝζQΚuΕ ιv»fͺuJeSTvΕ\³κΔ’ιB
}B.12ΜtH[πΒΆιΖAvOΜΐsIΉΖΘιBΐsIΉγAoΝt@CπeLXgGfB^ΕJΖΘΊΜζ€ΙΘΑΔ’ιB
Input Data File = Data5Cat.csv
<N, S>
[21, 10, 5, 18, 46]
<S, N>
[66, 10, 7, 12, 5]
Inference for Stan model:
anon_model_4f4c02dce251e874ae19399d5b4bfa08.
4 chains, each with iter=2000;
warmup=1000; thin=1;
post-warmup draws per chain=1000,
total post-warmup draws=4000.
mean se_mean
sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
mu_s 0.93 1.9e-3 0.12 0.68 0.85 0.93 1.01 1.17 4000 1.0
tau
0.38 1.9e-3 0.12 0.16 0.3 0.38 0.46 0.62 4000 1.0
theta[0] 0.14 5.9e-4 0.04 0.08 0.11 0.14 0.16 0.22 3924 1.0
theta[1] 0.58 1.1e-3 0.07 0.44 0.53 0.58 0.62 0.72 4000 1.0
C[0] -0.72 1.2e-3 0.08 -0.87 -0.77 -0.72 -0.66 -0.57 4000 1.0
C[1] -0.14 5.9e-4 0.04 -0.22 -0.16 -0.14 -0.11 -0.08 3924 1.0
C[2] 0.14 5.9e-4 0.04 0.08 0.11 0.14 0.16 0.22 3924 1.0
C[3] 0.72 1.2e-3 0.08 0.57 0.66 0.72 0.77 0.87 4000 1.0
p_NS[0] 0.19 5.6e-4 0.04 0.12 0.16 0.19 0.21 0.26 4000 1.0
p_NS[1] 0.13 2.6e-4 0.02 0.1 0.12 0.13 0.14 0.16 4000 1.0
p_NS[2] 0.07 3.1e-4 0.02 0.04 0.06 0.07 0.09 0.11 3901 1.0
p_NS[3] 0.16 3.2e-4 0.02 0.12 0.15 0.16 0.17 0.2 4000 1.0
p_NS[4] 0.45 7.6e-4 0.05 0.36 0.42 0.45 0.48 0.55 4000 1.0
p_SN[0] 0.08 3.4e-4 0.02 0.04 0.06 0.08 0.09 0.12 3837 1.0
p_SN[1] 0.08 2.0e-4 0.01 0.05 0.07 0.08 0.08 0.1 4000 1.0
p_SN[2] 0.05 2.4e-4 0.01 0.03 0.04 0.05 0.06 0.08 3703 1.0
p_SN[3] 0.13 3.0e-4 0.02 0.1 0.12 0.13 0.14 0.17 4000 1.0
p_SN[4] 0.66 7.2e-4 0.05 0.57 0.63 0.66 0.69 0.75 4000 1.0
lp__ -270.3 0.03 1.41 -273.8 -271.0 -270.0 -269.3
-268.5 2250 1.0
Samples were drawn using NUTS at Wed
Oct 23 12:01:07 2019.
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).
d':
Median = 0.927, 90%CI = [0.727, 1.131]
tau:
Median = 0.383, 90%CI = [0.190, 0.579]
C[1]:
Median = -0.715, 90%CI = [-0.845, -0.592]
C[2]:
Median = -0.136, 90%CI = [-0.206, -0.086]
C[3]:
Median = 0.136, 90%CI = [0.086, 0.206]
C[4]:
Median = 0.715, 90%CI = [0.592, 0.845]
KͺSΘγΜτΜκ
»fΜJeSKͺSΘγΜτΕ ικΜStanXNvgπXgC.1Μζ€ΙpΣ΅½B
XgC.1@KͺSΘγΜτΜκΜStanXNvgit@CΌSDT2AFCEvenCat.stanj
functions {
real half_normal_lpdf(real
y, real sgm){
if
(y > 0.0){
return
normal_lpdf(y | 0.0, sgm);
}
else {
return log(0.0);
}
}
}
data {
int K;
int n_NS[K];
int n_SN[K];
}
parameters {
real mu_s;
real tau;
real<lower = 0.0>
theta[K/2 - 1];
}
transformed parameters {
real C[K - 1];
simplex[K] p_NS;
simplex[K] p_SN;
C[K/2] = 0.0;
for (k in 1: (K/2 -1)){
C[K/2 + k] = C[K/2 + k - 1] + theta[k];
C[K/2 - k] = -C[K/2 + k];
}
p_NS[1] = Phi((C[1] - (mu_s -
tau))/sqrt(2.0));
p_NS[K] = 1 - Phi((C[K - 1]
- (mu_s - tau))/sqrt(2.0));
for (k in 2:(K-1)) {
p_NS[k] = Phi((C[k] - (mu_s - tau))/sqrt(2.0)) -
Phi((C[k - 1] - (mu_s - tau))/sqrt(2.0));
}
p_SN[1] = Phi((C[1] - (mu_s
+ tau))/sqrt(2.0));
p_SN[K] = 1 - Phi((C[K - 1]
- (mu_s + tau))/sqrt(2.0));
for (k in 2:(K-1)) {
p_SN[k] = Phi((C[k] - (mu_s + tau))/sqrt(2.0)) -
Phi((C[k - 1] - (mu_s + tau))/sqrt(2.0));
}
}
model {
for (k in 1:(K/2 - 1)) {
theta[k] ~ half_normal(1000.0);
}
mu_s ~ normal(0.0, 100.0);
tau ~ normal(0.0, 100.0);
n_NS ~ multinomial(p_NS);
n_SN ~ multinomial(p_SN);
}
XgC.1ΜStanXNvgSDT2AFCEvenCat.stanπp·ιPythonXNvgπAXgC.2Μζ€ΙpΣ΅½B
XgC.2@StanXNvgSDT2AFCEvenCat.stanπp·ιPythonXNvgit@CΌSDT2AFCEvenCat.pyj
import numpy as np
import pystan
import matplotlib.pyplot as plt
import csv
import pickle
flnm = input('όΝf[^t@CΌ(*.csv) = ')
with open(flnm, 'r') as f:
data = [v for v in
csv.reader(f)]
fout_nm = input('oΝeLXgt@CΌ = ')
fout = open(fout_nm, 'w')
fout.write('Input Data File =
{}\n'.format(flnm))
K = len(data[0]) - 1
print('K = ', K)
if (K % 2) == 1:
print(']θJeSΝτΕΘ―κΞΘηΘ’!')
import sys
sys.exit()
Freq_NS = []
for k in range(K):
Freq_NS.append(int(data[1][1
+ k]))
Freq_SN = []
for k in range(K):
Freq_SN.append(int(data[2][1
+ k]))
print(Freq_NS)
print(Freq_SN)
fout.write('\n<N,
S>\n{}\n'.format(Freq_NS))
fout.write('\n<S, N>\n{}\n'.format(Freq_SN))
TN_NS = sum(Freq_NS)
Rating_NS = Freq_NS
print(Rating_NS)
TN_SN = sum(Freq_SN)
Rating_SN = []
for k in range(K):
Rating_SN.append(Freq_SN[K -
1 - k])
Data = {'K': K, 'n_NS': Rating_NS,
'n_SN': Rating_SN}
sm = pystan.StanModel(file =
'SDT2AFCEvenCat.stan')
fit = sm.sampling(data = Data, n_jobs
= 1)
print(fit)
fout.write('\n{}\n'.format(fit))
mu = fit['mu_s']
tau = fit['tau']
C = fit['C']
p_NS = fit['p_NS']
p_SN = fit['p_SN']
mu_L05 = np.percentile(mu, 5)
mu_med = np.percentile(mu, 50)
mu_U95 = np.percentile(mu, 95)
fout.write("\nd':\nMedian =
{0:<.3f}, 90%CI =
[{1:<.3f}, {2:<.3f}]\n".
format(mu_med, mu_L05, mu_U95))
tau_L05 = np.percentile(tau, 5)
tau_med = np.percentile(tau, 50)
tau_U95 = np.percentile(tau, 95)
fout.write('\ntau:\nMedian =
{0:<.3f}, 90%CI =
[{1:<.3f}, {2:<.3f}]\n'.
format(tau_med, tau_L05, tau_U95))
C_L05 = np.zeros(K-1)
C_med = np.zeros(K-1)
C_U95 = np.zeros(K-1)
for k in range(K-1):
C_L05[k] = np.percentile(C.T[k],
5)
C_med[k] =
np.percentile(C.T[k], 50)
C_U95[k] =
np.percentile(C.T[k], 95)
for k in range(K-1):
fout.write(('\nC[{0}]:\n' +
\
'Median = {1:<.3f},
90%CI = [{2:<.3f}, {3:<.3f}]\n').
format(k+1, C_med[k], C_L05[k], C_U95[k]))
plt.hist(mu)
plt.xlabel("d'($\mu_S$)",
fontsize = 14)
plt.title("Posterior Distribution
of d'($\mu_S$)" + \
'\nMed. = {0:<.3f},
90%CI = [{1:<.3f}, {2:<.3f}]'.
format(mu_med, mu_L05, mu_U95), fontsize = 16)
plt.show()
plt.hist(tau)
plt.xlabel(r'$\tau$', fontsize = 18)
plt.title(r'Posterior Distribution of
$\tau$' + \
'\nMed. = {0:<.3f},
90%CI = [{1:<.3f}, {2:<.3f}]'.
format(tau_med, tau_L05, tau_U95), fontsize = 16)
plt.show()
for k in range(K-1):
if k + 1 != K/2:
plt.hist(C.T[k], label = 'C{}'.format(k+1))
plt.title('Posterior Distributions of
Category Boundaries' + \
'\nC{} = 0 fixed'.format(K//2), fontsize = 16)
plt.legend(loc = 'lower center')
plt.show()
xcat = np.arange(1, K+0.1, 1)
xlabels = ['{}'.format(int(v)) for v
in xcat]
y1 = []
y2 = []
for k in range(K):
y1.append(Freq_NS[k]/TN_NS)
y2.append(Freq_SN[k]/TN_SN)
p1 = np.median(p_NS, axis = 0)
p2 = np.median(p_SN, axis = 0)
p2 = np.flip(p2)
plt.plot(xcat, y1, 'b--', linewidth =
3, alpha = 0.7, label = 'Data/<N, S>')
plt.plot(xcat, p1, 'g-', linewidth =
3, alpha = 0.7, label = 'Model/<N, S>')
plt.plot(xcat, y2, 'r--', linewidth =
3, alpha = 0.7, label = 'Data/<S, N>')
plt.plot(xcat, p2, 'm-', linewidth =
3, alpha = 0.7, label = 'Model/<S, N>')
plt.xticks(xcat, xlabels, fontsize =
14)
plt.xlabel('Rating Category', fontsize
= 14)
plt.ylabel('Probability/Proportion',
fontsize = 14)
plt.title('Ratings in Conditions
<N, S> and <S, N>', fontsize = 18)
plt.legend(loc = 'upper center',
fontsize = 10)
plt.show()
fout.close()
print('\n{} was
saved.\n'.format(fout_nm))
XgC.1ΖXgC.2Μt@C¨ζΡTvf[^t@CΝAάΖίΔ³kt@CRatingEvenCat.zipΖ΅½B_E[hπ·κΞA©RΙpΕ«ιB
XgC.2Μt@CSDT2AFCEvenCat.pyπΐs·ιΖAόΝf[^t@CΌΖoΝf[^t@CΌΜέθͺίηκιi}C.1jB
}C.1
oΝf[^t@CΝCΣΜeLXgt@CΌit@Cg£q.txtjΕ ιͺAόΝf[^t@CΝCSV`Μt@CΖ΅Δ}C.2ΜlΕpΣ·ιB
}C.2@f[^t@CData4Cat.csv
ζPsΪΝΟΌΜΌOπέθ·ιͺAvOΕΝp’Θ’ΜΕCΣΜΆρΕζ’B½Ύ΅AζPsΪζPρΪΙΆρIDπέθ·ιΖAExcelΜκAΗέέΙG[bZ[Wͺ\¦³κι±Ζͺ ιͺA±κΝ³·ιBζQsΪΙhρ¦πNAS>iα¦ΞAΆΙmCYhAEΙVOihjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOiΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΙu½ͺVOihΝζPΚuΕ ιi½ͺVOihΝΆΕ ιjvΖ»f³κ½xAζSρΪΙu½ͺVOihΝζQΚuΕ ιi½ͺVOihΝEΕ ιjvΖ»f³κ½xAζTρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζRsΪΙhρ¦πSANiα¦ΞAΆΙVOihAEΙmCYhjΙ¨―ιf[^πέθ·ιBζQρΪΙuVOihΝζPΚuΕ ιiVOihΝΆΕ ιjvΖ»f³κ½xAζ3ρΪΙu½ͺVOihΝΆΕ ιvΖ»f³κ½xAζSρΪΙu½ͺVOihΝζQΚuΕ ιi½ͺVOihΝEΕ ιjvΖ»f³κ½xAζTρΪΙuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xπέθ·ιBζQsΪAζRsΪΖΰAζQρΪΝuVOihΝζPΚuΕ ιiα¦ΞAVOihΝΆΕ ιjvΖ»f³κ½xAζRρΪΝu½ͺVOihΝζPΚuΕ ιi½ͺVOihΝΆΕ ιjvΖ»f³κ½xAζSρΪΝu½ͺVOihΝζQΚuΕ ιi½ͺVOihΝEΕ ιjvΖ»f³κ½xAζTρΪΝuVOihΝζQΚuΕ ιiVOihΝEΕ ιjvΖ»f³κ½xΕ ιBf[^ΜέθͺIνκΞAt@Cg£qΖ΅Δu.csvvπIρΕΫΆ·ιΖACSV`Μt@CΖ΅ΔΫΆ³κιB
}C.1Μζ€ΙόΝf[^t@CΌΖoΝeLXgt@CΌπέθ·ιΖAvZͺnάιBStanΙζιTvOͺIΉ·ιΖAάΈijΜγͺzΜqXgOͺ\¦³κιi}C.3jB
}C.3
γͺzΜlͺMed.=1.052A90CIͺ[0.849, 1.264]Ε ι±Ζͺ¦³κΔ’ιB
}C.3ΜΣ§ήπΒΆιΖAΡΜγͺzΜqXgOͺ\¦³κιi}C.4jB
}C.4
γͺzΜlͺMed.=0.433A90CIͺ[0.227, 0.631]Ε ι±Ζͺ¦³κΔ’ιB
}C.4ΜtH[πΒΆιΖAJeS«EΜγͺzͺ¦³κιi}C.5jB
}C.5
JeS«EC2=0Ν§ρπΖ΅ΔΕθ³κΔ’ιΜΕAC2ΜqXgOΝ\¦³κΔ’Θ’A
}C.5ΜtH[πΒΆιΖAe»fJeSΜm¦^δ¦π¦·OtͺάκόOtΕ\¦³κιi}C.6jB
}C.6
f[^ͺjόΕδ¦π\΅AfͺΐόΕe»fJeSΜm¦ΜlΕ ιBuVOihΝζPΚuΕ ιv»fͺuJeSPvAu½ͺVOihΝζPΚuΕ ιv»fͺuJeSQvAu½ͺVOihΝζQΚuΕ ιv»fͺuJeSRvAuVOihΝζQΚuΕ ιv»fͺuJeSSvΕ\³κΔ’ιB
}C.6ΜtH[πΒΆιΖAvOΜΐsIΉΖΘιBΐsIΉγAoΝt@CπKΘGfB^ΕJΖAΘΊΜζ€ΙΘΑΔ’ιB
Input Data File = Data4Cat.csv
<N, S>
[24, 9, 12, 55]
<S, N>
[74, 13, 7, 6]
Inference for Stan model:
anon_model_f2c4de04275e32f42265169574310b77.
4 chains, each with iter=2000;
warmup=1000; thin=1;
post-warmup draws per chain=1000,
total post-warmup draws=4000.
mean se_mean
sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
mu_s 1.05 2.0e-3 0.12 0.81 0.97 1.05 1.14 1.3 4000 1.0
tau
0.43 2.0e-3 0.12 0.19 0.35 0.43 0.52 0.68 4000 1.0
theta[0] 0.51 1.1e-3 0.07 0.38 0.46 0.5 0.55 0.65 4000 1.0
C[0] -0.51 1.1e-3 0.07 -0.65 -0.55 -0.5 -0.46 -0.38 4000 1.0
C[1]
0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 4000 nan
C[2] 0.51 1.1e-3 0.07 0.38 0.46 0.5 0.55 0.65 4000 1.0
p_NS[0] 0.22 6.0e-4 0.04 0.15 0.19 0.21 0.24 0.29 4000 1.0
p_NS[1] 0.12 2.5e-4 0.02 0.09 0.11 0.12 0.13 0.15 4000 1.0
p_NS[2] 0.14 3.1e-4 0.02 0.1 0.12 0.14 0.15 0.18 4000 1.0
p_NS[3] 0.53 7.6e-4 0.05 0.44 0.5 0.53 0.56 0.63 4000 1.0
p_SN[0] 0.08 3.8e-4 0.02 0.04 0.07 0.08 0.1 0.13 3404 1.0
p_SN[1] 0.07 1.9e-4 0.01 0.05 0.06 0.07 0.07 0.09 4000 1.0
p_SN[2] 0.1 2.7e-4 0.02 0.07 0.09 0.1 0.11 0.13 4000 1.0
p_SN[3] 0.75 6.5e-4 0.04 0.67 0.73 0.76 0.78 0.83 4000 1.0
lp__ -209.9 0.03 1.22 -213.0 -210.4 -209.6 -209.1
-208.5 1661 1.0
Samples were drawn using NUTS at Wed
Oct 23 15:01:23 2019.
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).
d':
Median = 1.052, 90%CI = [0.849, 1.264]
tau:
Median = 0.433, 90%CI = [0.227, 0.631]
C[1]:
Median = -0.503, 90%CI = [-0.623, -0.396]
C[2]:
Median = 0.000, 90%CI = [0.000, 0.000]
C[3]:
Median = 0.503, 90%CI = [0.396, 0.623]
ΙA»fJeSͺUΒΜκiK=UjΜαπ¦·B
f[^απ}C.7Ι¦·B
}C.7@f[^t@CΌData6Cat.csv
vOπN΅ΔA}C.8Μζ€ΙόΝf[^t@CΌΖoΝf[^t@CΌπέθ·ιB
}C.8
όΝf[^t@CΌΖoΝf[^t@CΌπέθ·ιΖvZͺnάθAStanΙζιTvOͺIΉ·ιΖAάΈdfΜγͺzͺ\¦³κιi}C.9jB
}C.9
}C.9ΜtH[πΒΆιΖAΡΜγͺzͺ\¦³κιi}C.10jB
}C.10
}C.10ΜtH[πΒΆιΖAJeS«EΜγͺzͺ\¦³κιi}C.11jB
}C.11
}C.11ΜtH[πΒΆιΖA»fJeSΜδ¦Ζm¦ͺ\¦³κιi}C.12jB
}C.12
f[^ͺjόΕδ¦π\΅AfͺΐόΕe»fJeSΜm¦ΜlΕ ιBα¦ΞAum©ΙVOihΝζPΚuΕ ιv»fͺuJeSPvAuVOihΝζPΚuΕ ιv»fͺuJeSQvAu½ͺVOihΝζPΚuΕ ιv»fͺuJeSRvAu½ͺVOiΝζQΚuΕ ιv»fͺuJeSSvAuVOiΝζQΚuΕ ιv»fͺuJeSTvAum©ΙVOihΝζQΚuΕ ιv»fͺuJeSUvΕ\³κΔ’ιB
}C.12ΜtH[πΒΆιΖAvOΜΐsIΉΖΘιBΐsIΉγAoΝt@CπeLXgGfB^ΕJΖΘΊΜζ€ΙΘΑΔ’ιB
Input Data File = Data6Cat.csv
<N, S>
[6, 23, 5, 4, 37, 25]
<S, N>
[42, 38, 2, 5, 11, 2]
Inference for Stan model:
anon_model_f2c4de04275e32f42265169574310b77.
4 chains, each with iter=2000;
warmup=1000; thin=1;
post-warmup draws per chain=1000,
total post-warmup draws=4000.
mean se_mean
sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
mu_s 0.98 1.9e-3 0.12 0.75 0.9 0.98 1.06 1.21 3659 1.0
tau
0.36 1.8e-3 0.11 0.14 0.29 0.36 0.44 0.58 3867 1.0
theta[0] 0.19 7.1e-4 0.04 0.11 0.16 0.19 0.22 0.29 4000 1.0
theta[1] 1.42 1.9e-3 0.11 1.2 1.34 1.41 1.49 1.64 3720 1.0
C[0] -1.61 2.0e-3 0.12 -1.83 -1.68 -1.6 -1.53 -1.39 3409 1.0
C[1] -0.19 7.1e-4 0.04 -0.29 -0.22 -0.19 -0.16 -0.11 4000 1.0
C[2]
0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 4000 nan
C[3] 0.19 7.1e-4 0.04 0.11 0.16 0.19 0.22 0.29 4000 1.0
C[4] 1.61 2.0e-3 0.12 1.39 1.53 1.6 1.68 1.83 3409 1.0
p_NS[0] 0.06 2.9e-4 0.02 0.03 0.05 0.06 0.07 0.1 3717 1.0
p_NS[1] 0.22 4.2e-4 0.03 0.17 0.21 0.22 0.24 0.28 4000 1.0
p_NS[2] 0.05 1.7e-4 0.01 0.03 0.04 0.05 0.05 0.07 4000 1.0
p_NS[3] 0.05 1.9e-4 0.01 0.03 0.04 0.05 0.06 0.08 4000 1.0
p_NS[4] 0.37 4.7e-4 0.03 0.32 0.36 0.37 0.39 0.43 3591 1.0
p_NS[5] 0.24 6.1e-4 0.04 0.17 0.22 0.24 0.27 0.33 4000 1.0
p_SN[0] 0.02 1.5e-4 8.1e-3 7.8e-3 0.01 0.02 0.02 0.04 2755 1.0
p_SN[1] 0.12 3.6e-4 0.02 0.08 0.11 0.12 0.14 0.16 3664 1.0
p_SN[2] 0.03 1.2e-4 7.5e-3 0.02 0.03 0.03 0.04 0.05 4000 1.0
p_SN[3] 0.04 1.5e-4 9.3e-3 0.02 0.03 0.04 0.04 0.06 4000 1.0
p_SN[4] 0.36 4.7e-4 0.03 0.31 0.34 0.36 0.38 0.42 4000 1.0
p_SN[5] 0.43 7.3e-4 0.05 0.34 0.4 0.43 0.46 0.52 4000 1.0
lp__ -298.2 0.03 1.48 -301.9 -298.8 -297.8 -297.1
-296.3 1982 1.0
Samples were drawn using NUTS at Wed
Oct 23 15:26:01 2019.
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).
d':
Median = 0.981, 90%CI = [0.789, 1.178]
tau:
Median = 0.363, 90%CI = [0.177, 0.547]
C[1]:
Median = -1.605, 90%CI = [-1.799, -1.424]
C[2]:
Median = -0.187, 90%CI = [-0.271, -0.124]
C[3]:
Median = 0.000, 90%CI = [0.000, 0.000]
C[4]:
Median = 0.187, 90%CI = [0.124, 0.271]
C[5]:
Median = 1.605, 90%CI = [1.424, 1.799]
QAFCΫθΕΝAVOih΄oΜ½ΟlΖͺUπΒΚΙθ·ι±ΖΝΕ«Θ’B±Μ±ΖπOtΕ©ΔέιB
’άAmCYh΄oΖVOih΄oͺΜ³KͺzΙ]€Ζ·ιB
±ΜΖ«
ΖΘιΜΕA³m¦Ν
Ε^¦ηκιB
³m¦ΜΜOtΝA}Ex.1Μζ€Ε ιB
}Ex.1
}Ex.1ΜOtΝXgEx.1ΜXNvgΕ`’Δ’ιBXNvgt@CΝA³kt@CEx2AFCR.zipΙZί½ΜΕA_E[hWJ΅Δ©RΙp³κ½’B
VOi΄oΜ½Οlͺε«ΘιΖA³m¦ΰγͺιͺAWΞ·ͺε«ΘιΖ³m¦ΝΊͺιB
―ΆόγΜΖΜlΜgΝ―Ά³m¦Pcπ^¦ιΜΕA³m¦Pc©ηΖΜlΜgπίι±ΖΝΕ«Θ’BΖΜlΜgΝAQAFCΫθπΘΊΜζ€Ιg£·ιΖίι±ΖͺΕ«ιB
QAFCΕΝAρ¦hΞΝmCYAVOiΖVOiAmCYΜ2νήΕ ιB±κΙAmCYAmCYΖVOiAVOiΜQνήπΑ¦ΔASνήΜhΞΙΞ΅Δ]θ@πp’ιΖAVOih΄oΜ½ΟlΖͺUΜθπs€±ΖͺΕ«ιB
QAFCΫθΕΝAesΙ¨’ΔQΒΜhihΞjͺ^¦ηκιBehΜρ¦ΚuiσΤIAΤIjπS1, S2Ε\·Bζ1ρ¦ΚuͺS1AζQρ¦ΚuͺS2Ε ιBn, si ι’ΝAn-sjΝAζPΚuΙmCYhAζQΚuΙVOihͺρ¦³κ½±Ζπ\·B
ζPρ¦ΚuΜh΄oπAζQhρ¦ΚuΜh΄oπΕ\·B
ζPhΚuΙΞ·ιζQhΚuΜoCAXπbΕ\·B±ΜoCAXΝPνλ·Μζ€Ι΄oΜΰΜΖ½ΜΰΜΜΌπάήΰΜΕ ιB
±ΜΖ«AΘΊΜζ€ΙΘιB
ΜΖ«A
ΜΖ«A
ΜΖ«A
ΜΖ«A
’άA»fͺKΒΜJeSΙζι]θΕρ³κιΰΜΖ΅A»fΜJeS«EπΘΊΜζ€Ι¨B
±ΜΖ«A
Ε κΞAρ¦hΞ<>ΙΞ·ι»fΝͺ^¦ηκιΖ·ιB·ΘνΏA
Ε ιB
α¦ΞA»fJeS[ͺΒΜΖ«ΝA]θ»fΝΘΊΜζ€ΘΰΜͺl¦ηκιB
F@VOihΝm©ΙζPΚuΕ ιB
F@VOihΝζPΚuΕ ιB
F@VOihΝ½ΤρζPhΕ ιB
F@ν©ηΘ’^ΗΏηΰ―ΆΖvνκιB
F@VOihΝ½ΤρζQΚuΕ ιB
F@VOihΝζQΚuΕ ιB
F@VOihΝm©ΙζQΚuΕ ιB
½ΟAͺUΜ³KͺzΜέΟͺzπ
Ε\΅AΘΊΜζ€ΙΦXIΙέθ·ιB
±ΜΖ«A·ΜͺzΝΘΊΜζ€Ι^¦ηκιB
hΞ ͺρ¦³κΖ«A
΅½ͺΑΔA
hΞͺρ¦³κ½Ζ«A
΅½ͺΑΔA
hΞͺρ¦³κ½Ζ«A
΅½ͺΑΔA
hΞͺρ¦³κ½Ζ«A
΅½ͺΑΔA
’άAJeS«EΝA΄_πSΖ΅ΔΞΜΙέθ³κΔ’ιΖ·ιB
΅½ͺΑΔAKͺτΕ κΞA
οΕ κΞA
γΜfΙξΓ’ΔxCYͺΝ·ι½ίΜStanXNvgπAKͺτΜκπXgEx.QΙAKͺοΜκπXgEx.3Ι¦·B±κηΜXNvgt@Cπp’Δg£QAFC]θ@Ιζιf[^πxCYͺΝ·ιXNvgπXgEx.4Ι¦·B±κηΜt@CΝ³kt@CEx2AFCR.zipΙάΖί½B_E[hWJ΅Δ©RΙp³κ½’B
Θ¨APyStan 3pΜXNvgπ±ΜEFuTCgΙpΣ΅Δ’ιB
XgEx.4ΜΐsαπΘΊΙ¦·BXNvgΜΐsΝAWindowsΙCXg[³κ½AnacondaΜPython3.7ΌzΒ«Ι¨’ΔPyStan2.17.1.0πp’ΔsΑ½B
StanXNvgΜΐsΙARpCΙΦνιG[ͺo½Ζ«ΝAC++RpCπCXg[΅ΔέιΖζ’BgpPCΕΝAVisual StudioΜC++ͺCXg[³κΔ’ιB
UbuntuΜκΰAStanXNvgΜΐsΙRpCΙΦνιG[ͺ\¦³κ½Ζ«ΝAC++RpCπCXg[΅ΔέιΖζ’BC++πάί½‘ΜΎκΙΞ·ιΰΜΖ΅Δg++ͺ ιBUbuntuΜκAR}hug++vπΐs·ιΖAug++Ν©Β©θάΉρBΜR}hΕCXg[΅ΔΊ³’BvΖ’€ζ€ΘbZ[Wͺ\¦³κ½ηAw¦ΚθAR}hπόΝΐs·ιΖCXg[³κιBg++ΜCXg[γΝAStanXNvgΝRpCΐs³κιΝΈΕ ιB
άΈAJeSͺUΒΜτΜκΙΒ’Δ¦΅A±’ΔJeSͺVΒΜοΜκπ¦·B
\Ex.1Μζ€Θf[^ͺ^¦ηκ½Ζ·ιB
\Ex.1@JeSͺUΒΜκ |
||||
»fJeSR |
n-n |
n-s |
s-n |
s-s |
1 |
2 |
1 |
6 |
6 |
2 |
5 |
1 |
10 |
3 |
3 |
15 |
13 |
24 |
12 |
4 |
21 |
21 |
7 |
21 |
5 |
6 |
7 |
3 |
6 |
6 |
1 |
7 |
0 |
2 |
XgEx.4Μt@CAnalEx2AFCR.pyπΐs·ιBR}hΕΐs·ικΝAΘΊΜζ€Ε ιB
(py37)c> python AnalEx2AFCR.py
vvg gn_n =h ͺ\¦³κ½ηAJeSP©ηUάΕΜρ¦hΞπ<noise, noise>ΙΞ·ι»fρπόΝ·ιB\Ex.1Μf[^Ε κΞAΜζ€ΙlπΌpσΆΕζΨΑΔΐΧΔΕγΙEnterL[π΅ΔόΝ·ιB
n_n = 2 5 15
21 6 1
EnterL[π·ΖAΜόΝvvgͺ\¦³κιΜΕA―lΙόΝ΅Δ’B
n_n = 2 5 15
21 6 1
n_s =
\Ex.1Μf[^π·ΧΔόΝ·ιΖA[ζΚΝΘΊΜζ€ΙΘΑΔ’ιB
n_n = 2 5 15 21 6 1
n_s = 1 1 13 21 7 7
s_n = 6 10 24 7 3 0
s_s = 6 3 12 21 6 2
SΒΜhΞΙΞ·ιf[^ΜόΝͺIνιΖAMCMCTvOͺnάιBTvOͺIΉ·ιΖAάΈAΜγͺzΖMAPθlͺ\¦³κιi}Ex.1jB
}Ex.1
MAPθlͺΗ’±ΖΝAͺ{i2022Ghttps://doi.org/10.14947/psychono.41.1jΙρ³κΔ’ιB
}Ex.1ΜtH[πΒΆιΖAΜγͺzΖMAPθlͺ\¦³κιi}Ex.2jB
}Ex.2
}Ex.2ΜtH[πΒΆιΖAJeS«ElC1, C2, C4, C5ΜγͺzΖMAPθlΜOtͺ\¦³κιi}Ex.3jB
}Ex.3
JeSͺτΕ ιΜΕAC3ΝOΙΕθ³κΔ’ιͺA_iOCOjΜΤ’Ό~Ε\³κΔ’ιB
}Ex.3ΜtH[πΒΆιΖAp[^ΜγͺzΖMAPθlΜOtͺ\¦³κιi}Ex.4jB
}Ex.4
}Ex.4ΜtH[πΒΆιΖA}Ex.5ΜOtͺ\¦³κιi}Ex.5jB
}Ex.5
eρ¦hΞΙΞ΅ΔA]θJeS»fΜέΟm¦Μf[^lic²jΖfΙζι\ͺli‘²jΜOtͺ\¦³κΔ’ιBjόΜΞpόΝAf[^lΖf\ͺlͺSΙκv΅½κΜOtΕ ιBf[^lΖ\ͺlΜΦWΝA±ΜΞpόΙΩΪΑΔ’ιΜΕAfΜf[^ΙΞ·ιΔΝάθΝΗ’Ζ’¦ιB
}Ex.5ΜtH[πΒΆιΖAvOΜIΉΕ ιB
OtΜ}ΝAXNvgt@CΖ―ΆtH_Ιt@CΖ΅ΔΫΆ³κΔ’ιB
XgEx.4ΜXNvgAnalEx2AFCR.pyπΜζ€Ιΐs·ιB
(py37) c> python AnalEx2AFCR.py
άΈAρ¦hΞmCYAmCYΙΞ·ιf[^ΜόΝͺίηκιB
\Ex.2ΜκΜf[^πΘΊΜζ€ΙόΝ·ιB
\Ex.2@JeSVΒΜκΜf[^ |
||||
]θJeS |
n-n |
n-s |
s-n |
s-s |
1 |
2 |
0 |
5 |
0 |
2 |
7 |
3 |
9 |
7 |
3 |
9 |
10 |
14 |
13 |
4 |
17 |
14 |
11 |
7 |
5 |
11 |
9 |
10 |
13 |
6 |
1 |
10 |
1 |
9 |
7 |
3 |
4 |
0 |
1 |
elπΌpσΆiQΒΘγΕΰΒjΕζΨΑΔΐΧAΕγΙEnterL[π·B
n_n = 2 7 9
17 11 1 3
EnterL[π·ΖAΜόΝvvgͺ\¦³κιΜΕAόΝ΅Δ’B
n_n = 2 7 9 17 11 1 3
n_s = 0 3 10 14 9 10 4
s_n = 5 9 14 11 10 1 0
s_s = 0 7 13 7 13 9 1
VOiAVOiΙΞ·ιόΝπI¦ιΖAlblbTvOͺnάιB
TvOͺIΉ·ιΖAάΈAΜγͺzΖl`oθlͺ\¦³κιi}Ex.6jB
}Ex.6
MAPθlͺΗ’Ζ’€ρͺ ιiͺ{A2022Ghttps://doi.org/10.14947/psychono.41.1j
}Ex.6ΜtH[πΒΆιΖAΜγͺzΖMAPθlͺ\¦³κιi}Ex.7jB
}Ex.7
}Ex.7πΒΆιΖA]θ«ElC1, C2, C3, C4, C5, C6ΜγͺzΖMAPθlͺ\¦³κιi}Ex.8jB
}Ex.8
}Ex.8πΒΆιΖAp[^ΜγͺzΖl`oθlͺ\¦³κιi}Ex.9jB
}Ex.9
}Ex.9ΜtH[πΒΆιΖA}Ex.10ΜOtͺ\¦³κιB
}Ex.10
eρ¦hΞΙΞ΅ΔA]θJeS»fΜέΟm¦Μf[^lic²jΖfΙζι\ͺli‘²jΜOtͺ\¦³κΔ’ιBjόΜΞpόΝAf[^lΖf\ͺlͺSΙκv΅½κΜOtΕ ιBf[^lΖ\ͺlΜΦWΝA±ΜΞpόΙΩΪΑΔ’ιΜΕAfΜf[^ΙΞ·ιΔΝάθΝΗ’Ζ’¦ιB
}Ex.10ΜtH[πΒΆιΖAvOΜIΉΕ ιB
OtΜ}ΝAXNvgt@CΖ―ΆtH_Ιt@CΖ΅ΔΫΆ³κΔ’ιB
XgEx.1.@³m¦PcΜ`ζXNvg
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
import scipy.stats as ss
X = np.linspace(0.1, 2.0, 1000) # mu_s
Y = np.linspace(0.4, 2.0, 100) # sigma_s
Xg, Yg = np.meshgrid(X, Y)
def Pc(mu, sgm):
return ss.norm.cdf(mu / ((1 + sgm**2)**0.5))
Z = np.empty((len(Y), len(X)))
for i in range(len(X)):
for j in range(len(Y)):
Z[j][i] = Pc(X[i], Y[j])
fig = plt.figure(figsize = (7,6))
ax = fig.add_subplot(111)
C = ax.contourf(Xg, Yg, Z, levels =
20)
ax.set_xlabel('$\mu_s$', fontsize =
16);
ax.set_ylabel('$\sigma_s$', fontsize =
16)
ax.set_title('Pc')
fig.colorbar(C, ax=ax, fraction=0.02,
pad=0.1)
plt.tight_layout()
plt.savefig('FigPcCont.png')
plt.show()
data {
int K;
int nn_cond[K];
int ns_cond[K];
int sn_cond[K];
int ss_cond[K];
}
transformed data {
int hK;
vector[K/2] alpha;
hK = K / 2;
for (i in 1:hK) {
alpha[i] = 1.0;
}
}
parameters {
real mu_s;
real<lower = 0.0>
sgm_s;
real b;
simplex[hK] preC;
}
transformed parameters {
vector[K] nn_theta;
vector[K] ns_theta;
vector[K] sn_theta;
vector[K] ss_theta;
vector[K+1] nn_cum_p;
vector[K+1] ns_cum_p;
vector[K+1] sn_cum_p;
vector[K+1] ss_cum_p;
vector[K-1] C;
real vsum;
real sgm_nn;
real sgm_ns;
real sgm_ss;
C[hK] = 0.0;
vsum = 0.0;
for (i in 1:hK-1) {
vsum
+= preC[i];
C[hK+i]
= vsum / (1.0 - vsum);
C[hK-i] = -C[hK+i];
}
sgm_nn = sqrt(1.0 + 1.0);
sgm_ns = sqrt(1.0 +
square(sgm_s));
sgm_ss =
sqrt(square(sgm_s)*2);
nn_cum_p[1] = 0.0;
ns_cum_p[1] = 0.0;
sn_cum_p[1] = 0.0;
ss_cum_p[1] = 0.0;
nn_cum_p[K+1] = 1.0;
ns_cum_p[K+1] = 1.0;
sn_cum_p[K+1] = 1.0;
ss_cum_p[K+1] = 1.0;
for (i in 2:K) {
nn_cum_p[i] = normal_cdf(C[i-1], b, sgm_nn);
ns_cum_p[i] = normal_cdf(C[i-1], mu_s + b, sgm_ns);
sn_cum_p[i]
= normal_cdf(C[i-1], -mu_s + b, sgm_ns);
ss_cum_p[i] = normal_cdf(C[i-1], b, sgm_ss);
}
for (i in 1:K) {
nn_theta[i] = nn_cum_p[i+1] - nn_cum_p[i];
ns_theta[i] = ns_cum_p[i+1] - ns_cum_p[i];
sn_theta[i]
= sn_cum_p[i+1] - sn_cum_p[i];
ss_theta[i] = ss_cum_p[i+1] - ss_cum_p[i];
}
}
model {
mu_s ~ normal(0.0, 1000.0);
sgm_s ~ exponential(0.001);
preC ~ dirichlet(alpha);
b ~ normal(0.0, 1000.0);
nn_cond ~ multinomial(nn_theta);
ns_cond ~
multinomial(ns_theta);
sn_cond ~
multinomial(sn_theta);
ss_cond ~
multinomial(ss_theta);
}
data {
int K;
int nn_cond[K];
int ns_cond[K];
int sn_cond[K];
int ss_cond[K];
}
transformed data {
int hK;
vector[(K/2)+1] alpha;
hK = K / 2;
for (i in 1:hK+1) {
alpha[i] = 1.0;
}
}
parameters {
real mu_s;
real<lower = 0.0>
sgm_s;
real b;
simplex[hK+1] preC;
}
transformed parameters {
vector[K] nn_theta;
vector[K] ns_theta;
vector[K] sn_theta;
vector[K] ss_theta;
vector[K+1] nn_cum_p;
vector[K+1] ns_cum_p;
vector[K+1] sn_cum_p;
vector[K+1] ss_cum_p;
vector[K-1] C;
real vsum;
real sgm_nn;
real sgm_ns;
real sgm_ss;
vsum = 0.0;
for (i in 1:hK) {
vsum
+= preC[i];
C[hK+i] = vsum / (1.0 - vsum);
C[hK+1-i] = -C[hK+i];
}
sgm_nn = sqrt(1.0 + 1.0);
sgm_ns = sqrt(1.0 +
square(sgm_s));
sgm_ss = sqrt(square(sgm_s)*2);
nn_cum_p[1] = 0.0;
ns_cum_p[1] = 0.0;
sn_cum_p[1] = 0.0;
ss_cum_p[1] = 0.0;
nn_cum_p[K+1] = 1.0;
ns_cum_p[K+1] = 1.0;
sn_cum_p[K+1] = 1.0;
ss_cum_p[K+1] = 1.0;
for (i in 2:K) {
nn_cum_p[i] = normal_cdf(C[i-1], b, sgm_nn);
ns_cum_p[i] = normal_cdf(C[i-1], mu_s + b, sgm_ns);
sn_cum_p[i] = normal_cdf(C[i-1], -mu_s + b, sgm_ns);
ss_cum_p[i] = normal_cdf(C[i-1], b, sgm_ss);
}
for (i in 1:K) {
nn_theta[i] = nn_cum_p[i+1] - nn_cum_p[i];
ns_theta[i] = ns_cum_p[i+1] - ns_cum_p[i];
sn_theta[i] = sn_cum_p[i+1] - sn_cum_p[i];
ss_theta[i] = ss_cum_p[i+1] - ss_cum_p[i];
}
}
model {
mu_s ~ normal(0.0, 1000.0);
sgm_s ~ exponential(0.001);
preC ~ dirichlet(alpha);
b ~ normal(0.0, 1000.0);
nn_cond ~
multinomial(nn_theta);
ns_cond ~
multinomial(ns_theta);
sn_cond ~
multinomial(sn_theta);
ss_cond ~
multinomial(ss_theta);
}
XgEx.4@g£Q§Iπ]θ@f[^ΜxCYͺΝXNvgiAnalEx2AFCR.pyj
import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
import seaborn as sb
import pystan
import sys
def CalcMAPEst(samples, a = 0.05,
n_points = 10000):
"""
Calculatte
a MAP estimate from a KDE graph on [Lp, Up]
Lp
and Up are 100*a/2 and 100(1-a/2) percentile points of samples
"""
Lp, Up =
np.percentile(samples, [100 * a/2, 100 * (1 - a/2)]) # import numpy as np
coord = np.linspace(Lp, Up,
n_points)
est_pdf =
ss.gaussian_kde(samples).pdf(coord)
# import scipy.stats as ss
map_idx = np.argmax(est_pdf)
MAP_Est =
coord[map_idx]
return MAP_Est,
est_pdf[map_idx]
n_n = [int(v) for v in input('n_n =
').split()]
K = len(n_n)
if K < 3:
print('Number of categories
should be larger than 2.')
sys.exit()
n_s = [int(v) for v in input('n_s =
').split()]
if len(n_s) != K:
print('Numbers of categories
are not consistent.')
sys.exit()
s_n = [int(v) for v in input('s_n =
').split()]
if len(s_n) != K:
print('Numbers of categories
are not consistent.')
sys.exit()
s_s = [int(v) for v in input('s_s =
').split()]
if len(s_s) != K:
print('Numbers of categories
are not consistent.')
sys.exit()
print('n_n =', n_n)
print('n_s =', n_s)
print('s_n =', s_n)
print('s_s =', s_s)
sm = pystan.StanModel(file =
'SDT_2AFC_KCat_odd.stan' if K % 2 == 1 else 'SDT_2AFC_KCat_even.stan')
print('Compiling ended.')
Data = {'K':K, 'nn_cond':n_n,
'ns_cond':n_s, 'sn_cond':s_n, 'ss_cond':s_s}
fit = sm.sampling(data = Data, iter =
10000, n_jobs = 1)
print(fit)
mu_s_map = CalcMAPEst(fit['mu_s'])[0]
sb.kdeplot(fit['mu_s'])
plt.xlabel('$\mu_s$')
plt.title('$\mu_s$(MAP) =
{0:.3f}'.format(mu_s_map))
plt.savefig('Fig_mu.png')
plt.show()
sgm_s_map =
CalcMAPEst(fit['sgm_s'])[0]
sb.kdeplot(fit['sgm_s'])
plt.title('$\sigma_s$(MAP) =
{0:.3f}'.format(sgm_s_map))
plt.xlabel('$\sigma_s$')
plt.savefig('Fig_sgm.png')
plt.show()
s_title = ''
if K % 2 == 1:
for k in range(K-1):
sb.kdeplot(fit['C'].T[k])
c_map = CalcMAPEst(fit['C'].T[k])[0]
s_title += f'C{k+1}={c_map:.2f}'
if k
< K-2:
s_title += ', '
else:
for k in range(K-1):
if k
!= (K//2) - 1:
sb.kdeplot(fit['C'].T[k])
c_map = CalcMAPEst(fit['C'].T[k])[0]
s_title += f'C{k+1}={c_map:.2f}'
if k < K-2:
s_title += ', '
else:
plt.plot([0], [0], marker = 'o', markersize = 15, c = 'r')
s_title +=
f'C{k+1}=0, '
plt.title('MAP estimates\n' + s_title)
plt.savefig('FigC.png')
plt.show()
b_map = CalcMAPEst(fit['b'])[0]
sb.kdeplot(fit['b'])
plt.title('b(MAP) =
{0:.3f}'.format(b_map))
plt.savefig('Fig_b.png')
plt.show()
cum_n_n = np.cumsum(n_n)
pcum_n_n = cum_n_n/cum_n_n[-1]
cum_n_s = np.cumsum(n_s)
pcum_n_s = cum_n_s / cum_n_s[-1]
cum_s_n = np.cumsum(s_n)
pcum_s_n = cum_s_n / cum_s_n[-1]
cum_s_s = np.cumsum(s_s)
pcum_s_s = cum_s_s / cum_s_s[-1]
est_pcum_n_n = np.median(fit['nn_cum_p'],
axis = 0)[1:-1]
est_pcum_n_s =
np.median(fit['ns_cum_p'], axis = 0)[1:-1]
est_pcum_s_n =
np.median(fit['sn_cum_p'], axis = 0)[1:-1]
est_pcum_s_s =
np.median(fit['ss_cum_p'], axis = 0)[1:-1]
plt.plot(est_pcum_n_n, pcum_n_n[:-1],
label = 'n_n')
plt.plot(est_pcum_n_s, pcum_n_s[:-1],
label = 'n_s')
plt.plot(est_pcum_s_n, pcum_s_n[:-1],
label = 's_n')
plt.plot(est_pcum_s_s, pcum_s_s[:-1],
label = 's_s')
plt.plot([0,1], [0,1], c = 'k', ls =
'--', label = 'Obs.=Est.')
plt.xlabel('Est.Cum.P')
plt.ylabel('Obs.Cum.P')
plt.legend()
plt.title('Cumulative Proportions')
plt.savefig('FigCumEstObs.png')
plt.show()
f[^ͺΝpΜPythonπΰͺ{ΐ°u’ά³η·―Θ’PythonΕf[^ͺΝvΫPoΕπpΣ΅½B