0

I am trying to do a ddm analysis with the choiceRT_ddm function in R. My dataframe (called DDM) is composed of three columns (subjID, choice, RT) with 4320 observations for 54 participants (80 obs/participants). Some observations are missing (13 to be precise).

When I try with the following code:

output <- choiceRT_ddm(data = DDM, niter = 2000, 
                       nwarmup = 1000, nchain = 4, ncore = 4)

I have the following warning and error:

The following lines of the data file have NAs in necessary columns: 1509, 1510, 1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520, 1521 (total 13 lines) These rows are removed prior to modeling the data. Error in RTu[i, 1:Nu[i]] <- subj_data$rt[subj_data$choice == 2] : the number of objects that must be replaced is not a multiple of the size of the replacement.

When I am trying to delete the NAs before, the same is happening:

DDM2 <- na.omit(DDM)
output <- choiceRT_ddm(data = DDM2, niter = 2000, 
                       nwarmup = 1000, nchain = 4, ncore = 4)

Error in RTu[i, 1:Nu[i]] <- subj_data$rt[subj_data$choice == 2] : the number of objects that must be replaced is not a multiple of the size of the replacement.

I have verified: my R version, my Rstan version and my packages version are recent enough, thus the problem is not related to that.

Could it be because I don't have the same number of responses for each participant?

Thank you so much in advance.

xilliam
  • 2,074
  • 2
  • 15
  • 27
Lea_c
  • 41
  • 3

1 Answers1

0

I was able to reproduce your error with a toy data set that had some NA values.

library(hBayesDM)

# fake data with NAs
df <- data.frame(subjID = rep(1:10, 20),
                 choice = sample(1:2, 20*10, replace = TRUE),
                 RT = sample(1:20, 20*10, replace = TRUE))

df$RT[df$RT[40:55]] <- NA
df$choice[df$choice[40:55]] <- NA

# running this code gave the same error described in the question
choiceRT_ddm(data = df, niter = 20, nwarmup = 10, nchain = 4, ncore = 3)

But the analysis runs after imputing the NA values with the mean.

# replace each NA value with the mean of that vector
df$RT[is.na(df$RT)] <- mean(df$RT, na.rm = T)
df$choice[is.na(df$choice)] <- mean(df$choice, na.rm = T)

choiceRT_ddm(data = df, niter = 20, nwarmup = 10, nchain = 4, ncore = 3)

Take away: It appears the NA values in your dataset need to be imputed. Maybe because choiceRT_ddm() expects each participant to have the same number of responses, but your NAs are confined to some of the participants? Here I imputed with the mean, but there are other strategies.

xilliam
  • 2,074
  • 2
  • 15
  • 27