Skip to content

Instantly share code, notes, and snippets.

@pgomez1dpu
Created January 24, 2016 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgomez1dpu/485e535d99ecb2d52b43 to your computer and use it in GitHub Desktop.
Save pgomez1dpu/485e535d99ecb2d52b43 to your computer and use it in GitHub Desktop.
Based on:
Ratcliff, R., & Tuerlinckx, F. (2002). Estimating the parameters of the diffusion model: Approaches to dealing with contaminant reaction times and parameter variability. *Psychonomic Bulletin & Review, 9,* 438–481. doi:10.3758/BF03196302
1 condition, 50 trials, 45 correct responses, 5 errror responses No outliers
```{r}
emp.correct=c(777,779,632,625,600,612,714,706,737,614,643,574,849,617,591,816,680,596,948,580,609,588,604,650,643,866,667,593,650,615,638,750,610,798,590,1014,651,747,602,787,605,644,775,601,676)
emp.error=c(777,779,632,625,600)
emp.quant=quantile(emp.correct, seq(.1,.9,.2))
emp.quant
# 10% 30% 50% 70% 90%
# 591.8 610.4 643.0 712.4 808.8
# So the bins are bound by the empirical quantiles.
# (.1 * accuracy) < 592 ms
# (.2 * accuracy) between 592 ms & 610 ms
# (.2 * accuracy) between 611 ms & 643 ms
# (.2 * accuracy) between 644 ms & 712 ms
# (.2 * accuracy) between 713 ms & 808 ms
# (.1 * accuracy) > 808
# 45/50 is proportion(correct): accuracy
emp.prop= 45/50 * c(.1,.2,.2,.2,.2,.1)
# Hence, the empirical proportion
emp.prop
# [1] 0.09 0.18 0.18 0.18 0.18 0.09
# The model's prediction for a set of parameters might be
# model.acc = .93 (for example)
# The proportion of correct responses according to the model
# using the empirical boundaries is
# (.084 * model.acc) < 592 ms
# (.095 * model.acc) between 592 ms & 610 ms
# (.187 * model.acc) between 611 ms & 643 ms
# (.339 * model.acc) between 644 ms & 712 ms
# (.224 * model.acc) between 713 ms & 808 ms
# (.070 * model.acc) > 808
mod.prop=.93 * c(.084,.095,.187,.339,.224,.07)
mod.prop
# [1] 0.07812 0.08835 0.17391 0.31527 0.20832 0.06510
# Based on the empirical and expected proportion of responses
# one can calculate the chi-squared
chisq.words=sum(((mod.prop*50-emp.prop*50)^2)/(mod.prop*50))
# and the (O-E)^2 / E for the error reponses are added too.
# in this case given the small n of errors we use the proportion of responses
chisq.words=chisq.words+(5-.07*50)^2 / (.07*50)
# By changing the parameter values we minimize the chisq
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment