rplba: Generate Random Choice Response Times using pLBA Model

Description Usage Arguments Details Value Examples

Description

This function uses two-accumulator piecewise LBA model to generate random choice RTs. There are 3 variants: rplba, rplba1, and rplba2. Each of them has a corresponding R version, rplbaR, rplbaR1, and rplbaR2, for the purpose of speed testing. Because the difference of random number generators in C and R, they do not generate exactly identical RTs. When generating large enough observations, the distributions generated by R and C will match.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
rplba(n, pVec)

rplba1(n, pVec)

rplba2(n, pVec)

rplba3(n, pVec)

rplba4(n, pVec)

rplbaR1(n = 10, pVec = c(A = 1.51, b = 2.7, v1 = 3.32, v2 = 2.24, w1 = 1.51,
  w2 = 3.69, sv = 1, rD = 0.31, swt = 0.5, t0 = 0.08))

rplbaR2(n = 10, pVec = c(A1 = 1.51, A2 = 1.51, b1 = 2.7, b2 = 2.7, v1 =
  3.32, v2 = 2.24, w1 = 1.51, w2 = 3.69, sv1 = 1, sv2 = 1, sw1 = 1, sw2 = 1, rD
  = 0.31, swt = 0.5, t0 = 0.08))

rplbaR3(n, pVec = c(A1 = 1.5, A2 = 1.5, B1 = 1.2, B2 = 1.2, C1 = 0.3, C2 =
  0.3, v1 = 3.32, v2 = 2.24, w1 = 1.51, w2 = 3.69, sv1 = 1, sv2 = 1, sw1 = 1,
  sw2 = 1, rD = 0.3, tD = 0.3, swt = 0.5, t0 = 0.08))

Arguments

n

number of observations. Must be an integer

pVec

a numeric vector storing pLBA model parameters. The sequence is critical. See details for the sequence.

Details

The main function rplba implements a more flexible version of pLBA random number generator than the other two. It uses the following parameterisation (order matter):

rplba1 uses the following parameterisation:

rplba2 uses the following parameterisation:

Value

A n x 2 matrix with a first column storing choices and second column storing response times.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
################
## Example 1  ##
################
pVec3.1 <- c(A1=1.51, A2=1.51, B1=1.2, B2=1.2, C1=.3, C2=.3, v1=3.32,
             v2=2.24, w1=1.51, w2=3.69, sv1=1, sv2=1, sw1=1, sw2=1, rD=0.1,
             tD=.1, swt=0.5, t0=0.08)
pVec3.2 <- c(A1=1.51, A2=1.51, B1=1.2, B2=1.2, C1=.3, C2=.3, v1=3.32,
             v2=2.24, w1=1.51, w2=3.69, sv1=1, sv2=1, sw1=1, sw2=1, rD=0.1,
             tD=.15, swt=0.5, t0=0.08)
pVec3.3 <- c(A1=1.51, A2=1.51, B1=1.2, B2=1.2, C1=.3, C2=.3, v1=3.32,
             v2=2.24, w1=1.51, w2=3.69, sv1=1, sv2=1, sw1=1, sw2=1, rD=0.15,
             tD=.1, swt=0.5, t0=0.08)

n <- 1e5
set.seed(123); system.time(dat5.1 <- cpda::rplbaR(n, pVec3.1))
set.seed(123); system.time(dat5.2 <- cpda::rplbaR(n, pVec3.2))
set.seed(123); system.time(dat5.3 <- cpda::rplbaR(n, pVec3.3))
set.seed(123); system.time(dat6.1 <- cpda::rplba( n, pVec3.1))
set.seed(123); system.time(dat6.2 <- cpda::rplba( n, pVec3.2))
set.seed(123); system.time(dat6.3 <- cpda::rplba( n, pVec3.3))
tmp5.1 <- data.frame(choice=factor(dat5.1[,1]), rt=dat5.1[,2])
tmp5.2 <- data.frame(choice=factor(dat5.2[,1]), rt=dat5.2[,2])
tmp5.3 <- data.frame(choice=factor(dat5.3[,1]), rt=dat5.3[,2])
tmp6.1 <- data.frame(choice=factor(dat6.1[,1]), rt=dat6.1[,2])
tmp6.2 <- data.frame(choice=factor(dat6.2[,1]), rt=dat6.2[,2])
tmp6.3 <- data.frame(choice=factor(dat6.3[,1]), rt=dat6.3[,2])

tmp5.1$fun <- "R"
tmp5.2$fun <- "R"
tmp5.3$fun <- "R"
tmp6.1$fun <- "C"
tmp6.2$fun <- "C"
tmp6.3$fun <- "C"

tmp5.1$vec <- "1"
tmp5.2$vec <- "2"
tmp5.3$vec <- "3"
tmp6.1$vec <- "1"
tmp6.2$vec <- "2"
tmp6.3$vec <- "3"

df <- rbind(tmp5.1, tmp5.2, tmp5.3, tmp6.1, tmp6.2, tmp6.3)
df$fun <- factor(df$fun)

## Show R and C functions produce almost identical distributions
## Not run: 
## Set up a colour palette
cb <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2",
        "#D55E00", "#CC79A7")

require(ggplot2)
ggplot(data=df, aes(x = rt, fill=fun, color=fun)) +
  geom_density(alpha=0.2) +
  facet_grid(vec~ choice) +
  scale_fill_manual(values=cb)

## Or you can use lattice or base graphics
require(lattice)
histogram( ~rt | vec+choice+fun, data=df, breaks="fd", type="density",
           xlab="Response Time (s)",
           panel=function(x, ...) {
                 panel.histogram(x, ...)
                 panel.densityplot(x, darg=list(kernel="gaussian"),...)
  })

## End(Not run)

par(mfrow=c(3,2))
hist(tmp5.1[tmp5.1$choice==1,"rt"], breaks="fd", col="gray", freq=FALSE,
       xlab="RT (s)", main="pLBA-Choice 1")
lines(density(tmp6.1[tmp6.1$choice==1,"rt"]), col="red", lty="dashed",  lwd=1.5)

hist(tmp5.1[tmp5.1$choice==2,"rt"], breaks="fd", col="gray", freq=FALSE,
       xlab="RT (s)", main="pLBA-Choice 2")
lines(density(tmp6.1[tmp6.1$choice==2,"rt"]), col="red", lty="dashed",  lwd=1.5)

#############
hist(tmp5.2[tmp5.2$choice==1,"rt"], breaks="fd", col="gray", freq=FALSE,
       xlab="RT (s)", main="pLBA-Choice 1")
lines(density(tmp6.2[tmp6.2$choice==1,"rt"]), col="red", lty="dashed",  lwd=1.5)

hist(tmp5.2[tmp5.2$choice==2,"rt"], breaks="fd", col="gray", freq=FALSE,
         xlab="RT (s)", main="pLBA-Choice 2")
lines(density(tmp6.2[tmp6.2$choice==2,"rt"]), col="red", lty="dashed",  lwd=1.5)

#############
hist(tmp5.3[tmp5.3$choice==1,"rt"], breaks="fd", col="gray", freq=FALSE,
         xlab="RT (s)", main="pLBA-Choice 1")
lines(density(tmp6.3[tmp6.3$choice==1,"rt"]), col="red", lty="dashed",  lwd=1.5)

hist(tmp5.3[tmp5.3$choice==2,"rt"], breaks="fd", col="gray", freq=FALSE,
           xlab="RT (s)", main="pLBA-Choice 2")
lines(density(tmp6.3[tmp6.3$choice==2,"rt"]), col="red", lty="dashed",  lwd=1.5)
par(mfrow=c(1,1))

################
## Example 2  ##
################
pVec1 <- c(A=1.51, b=2.7, v1=3.32, v2=2.24,  w1=1.51,  w2=3.69,
           sv=1, rD=0.31, swt=0.5, t0=0.08)

pVec2 <- c(A1=1.51, A2=1.51, b1=2.7, b2=2.7, v1=3.32, v2=2.24,
           w1=1.51, w2=3.69, sv1=1, sv2=1, sw1=1, sw2=1, rD=0.31,
           swt=0.5, t0=0.08)

system.time(dat1 <- cpda::rplba1( n, pVec1))
system.time(dat2 <- cpda::rplba2( n, pVec2))
system.time(dat3 <- cpda::rplbaR1(n, pVec1))
system.time(dat4 <- cpda::rplbaR2(n, pVec2))

tmp1 <- data.frame(choice=factor(dat1[,1]), rt=dat1[,2])
tmp2 <- data.frame(choice=factor(dat2[,1]), rt=dat2[,2])
tmp3 <- data.frame(choice=factor(dat3[,1]), rt=dat3[,2])
tmp4 <- data.frame(choice=factor(dat4[,1]), rt=dat4[,2])
tmp1$fun <- "rplba1"
tmp2$fun <- "rplba2"
tmp3$fun <- "rplba1-R"
tmp4$fun <- "rplba2-R"
tmp0 <- rbind(tmp1, tmp2, tmp3, tmp4)
tmp0$fun <- factor(tmp0$fun)

## Not run: 
require(ggplot2)
ggplot(data = tmp0, aes(x = rt, fill=fun, color=fun)) +
    geom_density(alpha=0.2) +
    facet_grid(.~ choice) +
    scale_fill_manual(values=cb)

## End(Not run)

TasCL/cpda documentation built on May 3, 2019, 11:48 p.m.