R/sim.sdt.R

Defines functions sim.sdt

Documented in sim.sdt

##' Simulate the data from an SDT model
##' 
##' @param n how many samples to produce
##' @param dprim d'
##' @param crit main decision criteria centered at the midpoint between the evidence distributions
##' @param sd_ratio standard deviation ratio
##' @export
sim.sdt = function(n = 1, dprim = 1.5, criteria = c(-2.1, -1.4, -.7, 0, .7, 1.4, 2.1), sd_ratio = 1){
    which_bin = function(x, thr)min(which(x <= c(-Inf, thr, Inf)) - 1)
    d = data.frame(stim = rep(1:2, each = n), e = rnorm(n * 2), r = NA)
    d$e[d$stim == 2] = d$e[d$stim == 2] * sd_ratio
    d$e = d$e + .5 * dprim * c(-1, 1)[d$stim]
    for(i in 1:nrow(d))
        d$r[i] = which_bin(d$e[i], criteria)
    attr(d, 'dprim') = dprim
    attr(d, 'criteria') = criteria
    attr(d, 'sd_ratio') = sd_ratio
    d
}
boryspaulewicz/bhsdtr2 documentation built on July 17, 2024, 8:22 p.m.