-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_data.R
75 lines (61 loc) · 2.23 KB
/
make_data.R
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
### Script for making simulated LBA data ###
# Clear workspace
rm(list = ls())
# Set working directory to the top-level folder containing the dmc and tutorial subfolders
getwd()
# Load packages and model functions
source("dmc/dmc.R")
load_model(dir_name = "LBA", model_name = "lba_B.R")
# Build model
model <- model.dmc(p.map = list(A = "1",
B = "I",
t0 = "1",
mean_v = c("D", "M"),
sd_v = "M",
st0="1"),
match.map = list(M = list(left = "L", right = "R")),
factors = list(S = c("left", "right"),
D = c("easy", "hard"),
I = c("acc", "spd")),
constants = c(sd_v.false = 1, st0 = 0),
responses = c("L", "R"),
type = "norm"
)
# Set parameter mean values
p.vector <- c(A = .4,
B.acc = .8, B.spd = .6,
t0 = .3,
mean_v.easy.true = 1.5, mean_v.hard.true = 1,
mean_v.easy.false = 0, mean_v.hard.false = 0,
sd_v.true = .25
)
# Show mapping from parameters to design cells
print.cell.p(p.vector, model)
# Creat priors object
p.prior <- prior.p.dmc(
dists = rep("tnorm", 9),
p1 = p.vector,
p2 = c(rep(.2, 9)),
lower = c(0, rep(0,2), .1, rep(NA,4), 0),
upper = c(NA, rep(NA,2), 1, rep(NA,4), 1)
)
length(p.prior)
# Simulate data (single subject)
dat <- simulate.dmc(p.vector = p.vector, model = model, n = 80)
head(dat)
# Simulate data (multiple subjects)
hdat <- h.simulate.dmc(model = model, ps = p.vector, ns = 30, n = 80)
head(hdat)
# Summarise accuracy
dat %>%
group_by(I, D) %>% # factors to group by
summarise(accuracy = mean(C)) # compute accuracy
# Summarise mean RT, standard deviation, and cell counts
dat %>%
group_by(I, D, C) %>% # factors to group by
summarise(mean.RT = mean(RT), # compute mean RT
sd.RT = sd(RT), # compute std. dev.
n.obs = n()) # get cell counts
# Save data
write.csv(dat, file="dat.csv", row.names=FALSE)
write.csv(hdat, file="hdat.csv", row.names=FALSE)