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 ,
108- 1 ,1 ,1 ,13 ,4 ,3 ,0 ,11 ,6 ,1 ,2 ,16 ,1 ,2 ,1 ,10 ,1 ,3 ,6 ,7 ,13 ,0 ,0 ,8 ,4 ,3 ,5 ,16 ,1 ,
109- 1 ,2 ,5 ,4 ,7 ,4 ,15 ,0 ,5 ,0 ,6 ,3 ,6 ,5 ,17 ,2 ,0 ,1 ,17 ,1 ,0 ,2 ,8 ,3 ,6 ,3 ),
110- .Dim = c(4 , 21 )))
111-
112- response_1 <- t(trial_1 $ response )
113- response_2 <- t(trial_2 $ response )
114- response_6 <- t(trial_6 $ response )
94+ # ## Riefer et al (2002) data:
95+ load(" dataMPT.Rdata" )
11596
11697nparams <- 3 # Number of free parameters per participant: c_i, r_i, u_i
11798I <- diag(3 ) # Identity matrix for Wishart
11899
119- k <- response_1
120- nsubjs <- nrow(k ) # Number of word pairs per participant
121-
122- # To be passed on to Stan
123- data <- list (k = k , nparams = nparams , nsubjs = nsubjs , I = I )
124-
125100myinits <- list (
126- list (deltahat = matrix (0 , 21 , 3 ), Sigma = diag(3 ),
127- muchat = 0 , murhat = 0 , muuhat = 0 , xichat = 1 , xirhat = 1 , xiuhat = 1 ))
128-
101+ list (deltahat = matrix (rnorm(21 * 3 ), 21 , 3 ), Sigma = diag(3 ),
102+ muchat = rnorm(1 ), murhat = rnorm(1 ), muuhat = rnorm(1 ),
103+ xichat = runif(1 ), xirhat = runif(1 ), xiuhat = runif(1 )),
104+ list (deltahat = matrix (rnorm(21 * 3 ), 21 , 3 ), Sigma = diag(3 ),
105+ muchat = rnorm(1 ), murhat = rnorm(1 ), muuhat = rnorm(1 ),
106+ xichat = runif(1 ), xirhat = runif(1 ), xiuhat = runif(1 )),
107+ list (deltahat = matrix (rnorm(21 * 3 ), 21 , 3 ), Sigma = diag(3 ),
108+ muchat = rnorm(1 ), murhat = rnorm(1 ), muuhat = rnorm(1 ),
109+ xichat = runif(1 ), xirhat = runif(1 ), xiuhat = runif(1 )))
110+
129111# Parameters to be monitored
130112parameters <- c(" muc" , " mur" , " muu" , " sigmac" , " sigmar" , " sigmau" , " rho" )
131113
132114# Run higher iterations for better estimate
133- myiterations <- 3300
134- mywarmup <- 300
115+ myiterations <- 2100
116+ mywarmup <- 100
117+
118+ k <- response_1
119+ nsubjs <- nrow(k ) # Number of word pairs per participant
120+ data <- list (k = k , nparams = nparams , nsubjs = nsubjs , I = I ) # To be passed on to Stan
135121
136122# The following command calls Stan with specific options.
137123# For a detailed description type "?stan".
@@ -140,37 +126,37 @@ samples_1 <- stan(model_code=model,
140126 init = myinits , # If not specified, gives random inits
141127 pars = parameters ,
142128 iter = myiterations ,
143- chains = 1 ,
129+ chains = 3 ,
144130 thin = 1 ,
145131 warmup = mywarmup , # Stands for burn-in; Default = iter/2
146132 # seed=123 # Setting seed; Default is random seed
147133)
148134
149135k <- response_2
150136nsubjs <- nrow(k ) # Number of word pairs per participant
151- # To be passed on to Stan
152- data <- list ( k = k , nparams = nparams , nsubjs = nsubjs , I = I )
137+ data <- list ( k = k , nparams = nparams , nsubjs = nsubjs , I = I ) # To be passed on to Stan
138+
153139samples_2 <- stan(fit = samples_1 ,
154140 data = data ,
155141 init = myinits , # If not specified, gives random inits
156142 pars = parameters ,
157143 iter = myiterations ,
158- chains = 1 ,
144+ chains = 3 ,
159145 thin = 1 ,
160146 warmup = mywarmup , # Stands for burn-in; Default = iter/2
161147 # seed=123 # Setting seed; Default is random seed
162148)
163149
164150k <- response_6
165151nsubjs <- nrow(k ) # Number of word pairs per participant
166- # To be passed on to Stan
167- data <- list ( k = k , nparams = nparams , nsubjs = nsubjs , I = I )
152+ data <- list ( k = k , nparams = nparams , nsubjs = nsubjs , I = I ) # To be passed on to Stan
153+
168154samples_6 <- stan(fit = samples_1 ,
169155 data = data ,
170156 init = myinits , # If not specified, gives random inits
171157 pars = parameters ,
172158 iter = myiterations ,
173- chains = 1 ,
159+ chains = 3 ,
174160 thin = 1 ,
175161 warmup = mywarmup , # Stands for burn-in; Default = iter/2
176162 # seed=123 # Setting seed; Default is random seed
@@ -188,35 +174,64 @@ muc6 <- extract(samples_6)$muc
188174mur6 <- extract(samples_6 )$ mur
189175muu6 <- extract(samples_6 )$ muu
190176
177+ rhocr1 <- extract(samples_1 )$ rho [, 1 , 2 ]
178+ rhocu1 <- extract(samples_1 )$ rho [, 1 , 3 ]
179+ rhoru1 <- extract(samples_1 )$ rho [, 2 , 3 ]
180+ rhocr2 <- extract(samples_2 )$ rho [, 1 , 2 ]
181+ rhocu2 <- extract(samples_2 )$ rho [, 1 , 3 ]
182+ rhoru2 <- extract(samples_2 )$ rho [, 2 , 3 ]
183+ rhocr6 <- extract(samples_6 )$ rho [, 1 , 2 ]
184+ rhocu6 <- extract(samples_6 )$ rho [, 1 , 3 ]
185+ rhoru6 <- extract(samples_6 )$ rho [, 2 , 3 ]
186+
191187# ### Plots posteriors of the group--level c, r, and u parameters
192- windows(14 ,7 )
193- layout(matrix (1 : 3 ,1 ,3 ,byrow = T ))
194- par(mar = c(4.25 , 3 , 1 , 1 ))
195- par(cex.axis = 0.9 )
196- plot(density((muc1 )),ylim = c(0 ,6 ),xlim = c(0 ,1 ), axes = F ,xlab = " c" ,ylab = " " ,
197- main = " " )
198- axis(1 ,at = seq(0 ,1 ,0.2 ))
199- axis(2 ,at = c(0 ,12 ),labels = F ,lwd.ticks = 0 )
200- mtext(" Density" ,2 ,1 ,cex = 0.55 ,las = 0 )
201- par(cex = 0.60 )
202- legend(0.3 , 10 , c(" Trial1" ," Trial 2" ," Trial 3" ),lty = c(1 ,2 ,3 ),col = c(" black" ),
203- text.col = " black" )
204- par(cex = 0.65 )
205- lines(density((muc2 )),lty = 2 )
206- lines(density((muc6 )),lty = 3 )
207-
208- plot(density((mur1 ),to = 0.75 ),ylim = c(0 ,13 ),xlim = c(0 ,1 ), axes = F ,xlab = " r" ,
209- ylab = " " ,main = " " )
210- axis(1 ,at = seq(0 ,1 ,0.2 ))
211- axis(2 ,at = c(0 ,13 ),labels = F ,lwd.ticks = 0 )
212- mtext(" Density" ,2 ,1 ,cex = 0.55 ,las = 0 )
213- lines(density((mur2 )),lty = 2 )
214- lines(density((mur6 )),lty = 3 )
215-
216- plot(density((muu1 )),ylim = c(0 ,9 ),xlim = c(0 ,1 ), axes = F ,xlab = " u" ,ylab = " " ,
217- main = " " )
218- axis(1 ,at = seq(0 ,1 ,0.2 ))
219- axis(2 ,at = c(0 ,10 ),labels = F ,lwd.ticks = 0 )
220- mtext(" Density" ,2 ,1 ,cex = 0.55 ,las = 0 )
221- lines(density((muu2 )),lty = 2 )
222- lines(density((muu6 )),lty = 3 )
188+ windows(10 , 5 )
189+ layout(matrix (1 : 3 , 1 , 3 , byrow = TRUE ))
190+ par(cex = 1.1 , mar = c(2 , 2 , 1 , 1 ), mgp = c(.8 , .1 , 0 ))
191+
192+ plot(density(muc6 ), xlim = c(0 , 1 ), ylim = c(0 , 7 ), lty = " dotted" ,
193+ ylab = " Probability Density" , xlab = expression(mu [c ]), main = " " ,
194+ yaxt = " n" , xaxt = " n" )
195+ lines(density(muc2 ), lty = " dashed" )
196+ lines(density(muc1 ))
197+ axis(1 , seq(0 , 1 , by = .2 ), tick = FALSE )
198+
199+ plot(density(mur6 ), xlim = c(0 , 1 ), ylim = c(0 , 15 ), lty = " dotted" , ylab = " " ,
200+ xlab = expression(mu [r ]), yaxt = " n" , xaxt = " n" , main = " " )
201+ lines(density(mur2 ), lty = " dashed" )
202+ lines(density(mur1 ))
203+ axis(1 , seq(0 , 1 , by = .2 ), tick = FALSE )
204+ legend(0 , 15.5 , c(" Trial 1" , " Trial 2" , " Trial 6" ), lty = c(1 , 2 , 3 ),
205+ col = c(" black" ), text.col = " black" , bty = " n" )
206+
207+ plot(density(muu6 ), xlim = c(0 , 1 ), ylim = c(0 , 9 ), lty = " dotted" , ylab = " " ,
208+ xlab = expression(mu [u ]), yaxt = " n" , xaxt = " n" , main = " " )
209+ lines(density(muu2 ), lty = " dashed" )
210+ lines(density(muu1 ))
211+ axis(1 , seq(0 , 1 , by = .2 ), tick = FALSE )
212+
213+ # ### Plots posteriors for the correlations
214+ windows(10 , 5 )
215+ layout(matrix (1 : 3 , 1 , 3 , byrow = TRUE ))
216+ par(cex = 1.1 , mar = c(2 , 2 , 1 , 1 ), mgp = c(.8 , .1 , 0 ))
217+
218+ plot(density(rhocr6 ), xlim = c(- 1 , 1 ), ylim = c(0 , 1.5 ), lty = " dotted" ,
219+ ylab = " Probability Density" , xlab = expression(italic(rho [cr ])), main = " " ,
220+ yaxt = " n" , xaxt = " n" )
221+ lines(density(rhocr2 ), lty = " dashed" )
222+ lines(density(rhocr1 ))
223+ axis(1 , seq(- 1 , 1 , by = .5 ), tick = FALSE )
224+
225+ plot(density(rhocu6 ), xlim = c(- 1 , 1 ), ylim = c(0 , 1.5 ), lty = " dotted" , ylab = " " ,
226+ xlab = expression(italic(rho [cu ])), yaxt = " n" , xaxt = " n" , main = " " )
227+ lines(density(rhocu2 ), lty = " dashed" )
228+ lines(density(rhocu1 ))
229+ axis(1 , seq(- 1 , 1 , by = .5 ), tick = FALSE )
230+ legend(- 1 , 1.55 , c(" Trial 1" , " Trial 2" , " Trial 6" ), lty = c(1 , 2 , 3 ),
231+ col = c(" black" ), text.col = " black" , bty = " n" )
232+
233+ plot(density(rhoru6 ), xlim = c(- 1 , 1 ), ylim = c(0 , 1.5 ), lty = " dotted" , ylab = " " ,
234+ xlab = expression(italic(rho [ru ])), yaxt = " n" , xaxt = " n" , main = " " )
235+ lines(density(rhoru2 ), lty = " dashed" )
236+ lines(density(rhoru1 ))
237+ axis(1 , seq(- 1 , 1 , by = .5 ), tick = FALSE )
0 commit comments