General preparation

Read in code

source("rulexj_functions.R")

Set up exemplar matrix

  • columns correspond to cues, last column is criterion value
  • rows correspond to exemplars
exemplars <- matrix(
  ncol=5,byrow=TRUE,dimnames = list(NULL,c("c1","c2","c3","c4","crit")),
  data = c(
    0,0,0,1,23,
    0,0,1,0,25,
    0,1,0,0,30,
    0,1,0,1,43,
    1,0,0,0,35,
    1,0,1,1,70,
    1,1,0,1,68,
    1,1,1,0,63))

Recovery simulation

Simulate data

nsim <- 1000 # Number of simulated participants per recovery simulation
cues <- exemplars[,1:4] # Use all exemplar cue patterns as cues
sim_data_alpha_0.0  <- simulate_rulexj(n=nsim,cues=cues,exemplars=exemplars,alpha_fix=0.0,w_sum_max=100)
sim_data_alpha_0.5  <- simulate_rulexj(n=nsim,cues=cues,exemplars=exemplars,alpha_fix=0.5,w_sum_max=100)
sim_data_alpha_1.0  <- simulate_rulexj(n=nsim,cues=cues,exemplars=exemplars,alpha_fix=1.0,w_sum_max=100)
sim_data_alpha_flex <- simulate_rulexj(n=nsim,cues=cues,exemplars=exemplars,w_sum_max=100)

Fit the simulated data

rec_data_alpha_0.0  <- fit_rulexj(dataset=sim_data_alpha_0.0$judgments, exemplars=exemplars)
rec_data_alpha_0.5  <- fit_rulexj(dataset=sim_data_alpha_0.5$judgments, exemplars=exemplars)
rec_data_alpha_1.0  <- fit_rulexj(dataset=sim_data_alpha_1.0$judgments, exemplars=exemplars)
rec_data_alpha_flex <- fit_rulexj(dataset=sim_data_alpha_flex$judgments,exemplars=exemplars)
# save.image("recovery_simulations.Rdata")

Assessing the recovery performance

Alpha = 0.5

# Summary of fitted alpha values
summary(rec_data_alpha_0.5$alpha_joint)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     0.5     0.5     0.5     0.5     0.5     0.5
# Summary of sums of squares of the RulEx-J model
summary(rec_data_alpha_0.5$SS_RulExJ_joint)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 0.000e+00 4.520e-20 1.712e-19 2.125e-18 6.618e-19 1.230e-15
# Summary of differences between data generating and fitted parameters
summary(subset(sim_data_alpha_0.5$parameters,select=c(alpha:s))-
          subset(rec_data_alpha_0.5,select=c(alpha_joint:s_joint)),
        digits = 2)
##   alpha_joint          w0_joint           w1_joint           w2_joint       
##  Min.   :-2.9e-08   Min.   :-1.1e-06   Min.   :-2.0e-07   Min.   :-2.2e-07  
##  1st Qu.:-8.4e-11   1st Qu.:-3.3e-09   1st Qu.:-1.9e-09   1st Qu.:-1.7e-09  
##  Median : 1.5e-12   Median : 7.7e-11   Median :-2.9e-11   Median : 4.8e-11  
##  Mean   :-1.6e-11   Mean   : 2.4e-09   Mean   :-7.5e-10   Mean   : 1.4e-09  
##  3rd Qu.: 1.1e-10   3rd Qu.: 4.9e-09   3rd Qu.: 1.7e-09   3rd Qu.: 1.7e-09  
##  Max.   : 5.3e-09   Max.   : 8.4e-07   Max.   : 1.4e-07   Max.   : 7.1e-07  
##     w3_joint           w4_joint           s_joint        
##  Min.   :-4.1e-07   Min.   :-3.6e-07   Min.   :-2.3e-09  
##  1st Qu.:-2.1e-09   1st Qu.:-2.1e-09   1st Qu.:-6.6e-11  
##  Median :-8.0e-11   Median :-7.2e-11   Median : 6.7e-13  
##  Mean   :-2.1e-09   Mean   : 8.2e-10   Mean   : 3.7e-12  
##  3rd Qu.: 1.5e-09   3rd Qu.: 1.6e-09   3rd Qu.: 5.4e-11  
##  Max.   : 4.5e-07   Max.   : 1.7e-06   Max.   : 1.1e-08

Alpha = 0.0

Note that for this simulation the fitted alphas are not exactly 0, as in the fitting process alpha was restricted to the lower bound of .00001.

# Summary of fitted alpha values
summary(rec_data_alpha_0.0$alpha_joint,digits=5)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1e-05   1e-05   1e-05   1e-05   1e-05   1e-05
# Summary of sums of squares of the RulEx-J model
summary(rec_data_alpha_0.0$SS_RulExJ_joint)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 1.510e-09 4.248e-07 1.052e-06 1.458e-06 2.163e-06 1.089e-05
# Summary of differences between data generating and fitted s
summary(subset(sim_data_alpha_0.0$parameters,select=c(s))-
          subset(rec_data_alpha_0.0,select=c(s_joint)),
        digits = 2)
##     s_joint        
##  Min.   :-2.4e-05  
##  1st Qu.:-9.1e-06  
##  Median :-5.8e-06  
##  Mean   :-6.4e-06  
##  3rd Qu.:-3.1e-06  
##  Max.   : 8.4e-06

Alpha = 1.0

Note that for this simulation the fitted alphas are not exactly 1, as in the fitting process alpha was restricted to the upper bound of .99999.

# Summary of fitted alpha values
summary(rec_data_alpha_1.0$alpha_joint,digits=5)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       1       1       1       1       1       1
# Summary of sums of squares of the RulEx-J model
summary(rec_data_alpha_1.0$SS_RulExJ_joint)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 4.016e-10 4.016e-10 4.016e-10 4.925e-10 4.016e-10 4.822e-09
# Summary of differences between data generating and fitted weights
summary(subset(sim_data_alpha_1.0$parameters,select=c(alpha:w4))-
          subset(rec_data_alpha_1.0,select=c(alpha_joint:w4_joint)),
        digits = 2)
##   alpha_joint         w0_joint           w1_joint           w2_joint       
##  Min.   :1.0e-05   Min.   :-4.7e-04   Min.   :-6.4e-04   Min.   :-7.3e-04  
##  1st Qu.:1.0e-05   1st Qu.: 7.9e-05   1st Qu.:-1.4e-04   1st Qu.:-1.9e-04  
##  Median :1.0e-05   Median : 1.9e-04   Median :-3.9e-05   Median :-7.0e-05  
##  Mean   :1.0e-05   Mean   : 1.5e-04   Mean   :-6.8e-05   Mean   :-1.1e-04  
##  3rd Qu.:1.0e-05   3rd Qu.: 2.6e-04   3rd Qu.: 4.1e-05   3rd Qu.: 2.2e-06  
##  Max.   :1.1e-05   Max.   : 3.5e-04   Max.   : 1.7e-04   Max.   : 1.4e-04  
##     w3_joint           w4_joint       
##  Min.   :-7.5e-04   Min.   :-6.1e-04  
##  1st Qu.:-2.0e-04   1st Qu.:-1.9e-04  
##  Median :-7.2e-05   Median :-7.8e-05  
##  Mean   :-1.1e-04   Mean   :-1.1e-04  
##  3rd Qu.:-3.0e-06   3rd Qu.:-6.2e-06  
##  Max.   : 1.4e-04   Max.   : 1.5e-04

Alpha varying between 0 and 1

# Plot of data generating vs. fitted alpha
plot(sim_data_alpha_flex$parameters[,"alpha"],rec_data_alpha_flex$alpha_joint,las=1)

# Summary of sums of squares of the RulEx-J model
summary(rec_data_alpha_flex$SS_RulExJ_joint)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 0.000e+00 0.000e+00 0.000e+00 8.160e-09 0.000e+00 8.155e-06
# Summary of differences between data generating and fitted parameters:
summary(subset(sim_data_alpha_flex$parameters,select=c(alpha:s))-
          subset(rec_data_alpha_flex,select=c(alpha_joint:s_joint)),
        digits = 2)
##   alpha_joint          w0_joint          w1_joint           w2_joint      
##  Min.   :-4.3e-08   Min.   :-0.0014   Min.   :-7.0e+01   Min.   :-0.2161  
##  1st Qu.:-1.0e-10   1st Qu.: 0.0000   1st Qu.: 0.0e+00   1st Qu.: 0.0000  
##  Median : 0.0e+00   Median : 0.0000   Median : 0.0e+00   Median : 0.0000  
##  Mean   : 6.0e-07   Mean   : 0.0026   Mean   :-7.0e-02   Mean   : 0.0096  
##  3rd Qu.: 1.0e-10   3rd Qu.: 0.0000   3rd Qu.: 0.0e+00   3rd Qu.: 0.0000  
##  Max.   : 3.4e-04   Max.   : 2.4035   Max.   : 5.3e-04   Max.   : 9.8530  
##     w3_joint           w4_joint           s_joint        
##  Min.   :-5.03856   Min.   :-4.5e+01   Min.   :-8.9e-03  
##  1st Qu.: 0.00000   1st Qu.: 0.0e+00   1st Qu.: 0.0e+00  
##  Median : 0.00000   Median : 0.0e+00   Median : 0.0e+00  
##  Mean   :-0.00520   Mean   :-4.5e-02   Mean   :-1.0e-05  
##  3rd Qu.: 0.00000   3rd Qu.: 0.0e+00   3rd Qu.: 0.0e+00  
##  Max.   : 0.00042   Max.   : 7.9e-04   Max.   : 2.2e-07