Error when running choiceRT_ddm

151 views
Skip to first unread message

Wei Ler Koo

unread,
Jun 22, 2023, 1:38:28 AM6/22/23
to hbayesdm-users
Hello everyone,

I'm in the midst of trying to fit my data to a DDM model and found this package.
The data is from an experimental task that includes binary choices (left/right) and response time is measured.

When running the line
output1 = gng_m1(data="example", niter=2000, nwarmup=1000, nchain=4, ncore=4)
from https://ccs-lab.github.io/hBayesDM/articles/getting_started.html#how-to-use-hbayesdm (running choiceRT_ddm instead of gng_m1), I came across this error output below
Error.png

When I try to run this with my data instead, it returns a different error
Error.png

I'm fairly new to r and coding in general (about 6 months in). I kind of understand what the 2nd error is implying but I have checked through the data and the 3 necessary columns have the same number of items.

When I was searching for similar errors that other users have encountered, I came across this discussion https://github.com/CCS-Lab/hBayesDM/issues/153 .
For context to that discussion, I'm currently using R version 4.2.3.

Much appreciated for helping!

Regards,
Wei Ler

franzis...@gmail.com

unread,
Jun 22, 2023, 2:42:02 AM6/22/23
to hbayesdm-users

Hello, 
I have exactly the same problem after updating to the newer version of RStudio (Version 2023.06.0+421 (2023.06.0+421)). None of my models is running anymore, on data which I successfully modelled before.
When calling:
output_one = prl_fictitious_multipleB(complete.cases(data), niter = 4000, nwarmup = 1000, ncore = 8, nchain = 4, adapt_delta = 0.99)
This is what I get, but the model doesn't even start.
Error in is.null(data) || is.na(data) :
  'length = 10000' in coercion to 'logical(1)'
Is there a work around, other than reinstalling an old version of r and r studio?
Thanks a lot!!
Franziska

wooyou...@gmail.com

unread,
Jun 27, 2023, 10:40:51 PM6/27/23
to hbayesdm-users
Hi Franziska,

I think hBayesDM (actually RStan) isn't properly installed. Could you fist install rstan properly by carefully following its tutorial?

Best,
Young

franzis...@gmail.com

unread,
Jun 28, 2023, 11:59:38 AM6/28/23
to hbayesdm-users
Hello Young,
thanks for getting back. I am not sure that is it, as I had been following this tutorial.

******
Installing RStan

To be on the safe side, it is sometimes necessary to remove any existing RStan via

remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData")

Then, restart R.

If you are using R version 3.x on a Mac, go to here. Otherwise, you can usually simply type (exactly like this)

Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1) # only necessary for Linux without the nodejs library / headers install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

Verifying Installation

To verify your installation, you can run the RStan example/test model:

example(stan_model, package = "rstan", run.dontrun = TRUE)

*****

The model for the verification ran without any problems, but I am still getting this error when running any of the hbayesdm models:

Error in is.null(data) || is.na(data) : 'length = 60000' in coercion to 'logical(1)'

Any idea?

Thanks.

Franziska


Wei Ler Koo

unread,
Jun 29, 2023, 11:59:50 AM6/29/23
to hbayesdm-users
Hello Young,

Appreciate the response on installation for RStan, that helped and I was able to run output1 = gng_m1(data="example", niter=2000, nwarmup=1000, nchain=4, ncore=4) properly and obtained the "model fitting is completed" message.

I tried to run choiceRT_ddm and receive the following error as attached previously and also below
Error.png
To clarify my dataset, it has 20260 trial level data with subjID, choice (-1,1), and RT (seconds).

Could you advise how to resolve this error as I notice Franziska seems to be encountering a similar problem.

Regards,
Wei Ler

franzis...@gmail.com

unread,
Jun 29, 2023, 3:34:54 PM6/29/23
to hbayesdm-users
Hello all,
I have been using the tool box for quite some time now and I never had this problem, scripts that were working perfectly well before don't work anymore using exactly the same data files. I used to read in csv files or created a dataframe within r and then run the model on that data, and it worked perfectly.

Now the only way I get the models to run is by reading in the full path for the txt-file, egg.:

ts_par6("~/Dropbox/TwoStepTask_OCD/Data/OCD_2step_in_corr.txt", niter=4000, nwarmup=2000, nchain=4, ncore=8, adapt_delta = 0.99)

AND, the txt file needs to have a specific formate - I need to save it as a Macintosh Plain txt in excel; any of the write.table r commands won't produce a format and will always produce an error 

Why does it not work anymore to read in a dataframe??

I used to do it like this
ocd<-read.delim("~/Dropbox/TwoStepTask_OCD/Data/OCD_2step_in_corr.txt") #and here I could read in csvs or create a df
ts_par6(ocd, niter=4000, nwarmup=2000, nchain=4, ncore=8, adapt_delta = 0.99)

Thanks for the help
Best, Franziska

Wei Ler Koo

unread,
Jun 30, 2023, 12:12:17 AM6/30/23
to hbayesdm-users
Hello all, 

I have followed Franziska's advise of working with a txt file instead and there was a different error encountered.
I have fed in a tab-delimited txt file and it returned the following error instead for choiceRT_ddm
Error in RTl[i, 1:Nl[i]] <- subj_data$rt[subj_data$choice == 1] : number of items to replace is not a multiple of replacement length

However, as I was fiddling around with the data frame yesterday, I could get an output when I feed in my data with a maximum of 2 unique subjID.
DDM output.jpg
Similar errors were encountered even with increasing iterations and warmups. 
Interestingly I could get the 4 parameters for DDM itself albeit only at a maximum of 2 unique subjID.


So to go back to the first point in this reply, I then written an output of tab-delimited text files with 2 unique subjID and reduce the amount of iterations and warmup just to check if I could get an output.
This time round I did not encounter the same error as the first attempt
Error in RTl[i, 1:Nl[i]] <- subj_data$rt[subj_data$choice == 1] : number of items to replace is not a multiple of replacement length
Instead, I managed to get the 4 parameters as well albeit with similar warning messages as the previous attempt with a data frame.
DDM parameters.png

Seems like my issue in successfully running the model fitting is when I have 3 or more unique subjID.

Regards,
Wei Ler

Gregory Fonzo

unread,
Jun 30, 2023, 2:19:29 AM6/30/23
to Wei Ler Koo, hbayesdm-users
The error seems to be occurring in the preprocessing of the behavioral data (see https://github.com/CCS-Lab/hBayesDM/blob/develop/R/R/preprocess_funcs.R).

choiceRT_preprocess_func <- function(raw_data, general_info, RTbound = 0.1) {
  # Use raw_data as a data.frame
  raw_data <- as.data.frame(raw_data)

  # Use general_info of raw_data
  subjs   <- general_info$subjs
  n_subj  <- general_info$n_subj

  # Number of upper and lower boundary responses
  Nu <- with(raw_data, aggregate(choice == 2, by = list(y = subjid), FUN = sum)[["x"]])
  Nl <- with(raw_data, aggregate(choice == 1, by = list(y = subjid), FUN = sum)[["x"]])

  # Reaction times for upper and lower boundary responses
  RTu <- array(-1, c(n_subj, max(Nu)))
  RTl <- array(-1, c(n_subj, max(Nl)))
  for (i in 1:n_subj) {
    subj <- subjs[i]
    subj_data <- subset(raw_data, raw_data$subjid == subj)

    if (Nu[i] > 0)
      RTu[i, 1:Nu[i]] <- subj_data$rt[subj_data$choice == 2]  # (Nu/Nl[i]+1):Nu/Nl_max will be padded with 0's
    if (Nl[i] > 0)
      RTl[i, 1:Nl[i]] <- subj_data$rt[subj_data$choice == 1]  # 0 padding is skipped in likelihood calculation
  }


It seems that the placement of the behavioral data for certain subjects into the RTl matrix across subjects (RTl for lower bound responses) here....: RTl[i, 1:Nl[i]] <- subj_data$rt[subj_data$choice == 1]  # 0 padding is skipped in likelihood calculation

....is throwing the error.  It seems there may be more choices attempting to be placed than there are values in the matrix?

Best,
Greg

--
You received this message because you are subscribed to the Google Groups "hbayesdm-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbayesdm-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbayesdm-users/e44ea387-afee-4b4f-b1c1-9cc7e40f2d10n%40googlegroups.com.


--

GREG FONZO, PhD

Assistant Professor 

Co-Director, Center for Psychedelic Research and Therapy

Department of Psychiatry and Behavioral Sciences


Dell Medical School | The University of Texas at Austin

o: 512-495-5296 |  gfo...@austin.utexas.edu   |  https://UTHealthAustin.zoom.us/my/gregfonzophd


Health Discovery Building (HDB)

1601 Trinity Street, Bldg. B, Z0600

Austin, TX 78712


https://sites.utexas.edu/fonzolab

https://dellmed.utexas.edu/units/center-for-psychedelic-research-and-therapy

Eunhwi Lee

unread,
Jun 30, 2023, 5:46:25 AM6/30/23
to hbayesdm-users
Hi Wei Ler, 

As Greg mentioned, could you please check your raw data and its structure? Codes might not run properly if the input dataset has inappropriate values. And consider manually running the preprocessing function code (https://github.com/CCS-Lab/hBayesDM/blob/develop/R/R/preprocess_funcs.R) to check if the data preprocessing is done properly. 

Tell me if it helps and please don't hesitate to ask further questions!

Best,
Eunhwi
2023년 6월 30일 금요일 오후 3시 19분 29초 UTC+9에 gregor...@gmail.com님이 작성:
Reply all
Reply to author
Forward
0 new messages