jasp-stats / jasp-issues

This repository is solely meant for reporting of bugs, feature requests and other issues in JASP.
58 stars 29 forks source link

JAGS throws error in `stringr::str_count(model, chars)`: object 'model' not found #1691

Closed HamidLD closed 2 years ago

HamidLD commented 2 years ago

JASP Version

0.16.2

Commit ID

No response

JASP Module

jaspJags

What analysis are you seeing the problem on?

Model fitting

What OS are you seeing the problem on?

Win10 64bit

Bug Description

I have a behavioral data set BartC.csv , to which I want fit a cognitive model using JAGS (shown in the attached image error, but I get the following error:

This analysis terminated unexpectedly.

Error in stringr::str_count(model, chars): object 'model' not found

Stack trace doTryCatch(return(expr), name, parentenv, handler)

withCallingHandlers(expr = analysis(jaspResults = jaspResults, dataset = dataset, options = options), error = .addStackTrace)

analysis(jaspResults = jaspResults, dataset = dataset, options = options)

JAGS(...)

.JAGSrunMCMC(jaspResults, dataset, options)

jaspResults[['mainContainer']]$setError(.JAGSmodelError(e, options))

private$jaspObje

ct$setError(x)

.JAGSmodelError(e, options)

stringr::str_count(model, chars)

stri_count_fixed(string, pattern, opts_fixed = opts(pattern))

Expected Behaviour

It should produce the posterior means of parameters beta and rho for each participant, like the following: posterior

Steps to Reproduce

  1. Use the following model in the JAGS module (I've attached the data earlier) data{ for (k in 1:maxPumps){ cut[k] = k - 0.5 } } model{ for (i in 1:nParticipants){ rho[i] ~ dnorm(7, 1/5^2)T(0,) beta[i] ~ dnorm(3, 1/2^2)T(0, ) yPredTmp[i] ~ dnorm(rho[i], 1/beta[i]^2)T(0, ) yPred[i] = round(yPredTmp[i]) } for (t in 1:totalTrials){ yPrime[t] ~ dnorm(rho[participant[t]], 1/beta[participant[t]]^2)T(0, ) y[t] ~ dinterval(round(yPrime[t]), cut[1:burst[t]]) } }

  2. Select the rho and beta parameters as the output

  3. And here the error is produced.

Jasp file: BartC.zip

Log (if any)

No response

Final Checklist

amirmasoudabdol commented 2 years ago

@FBartos, any idea what's going on here?

FBartos commented 2 years ago

hmm, no idea. Maybe an issue for @vandenman to look at?

vandenman commented 2 years ago

Looks like the same issue as https://github.com/jasp-stats/INTERNAL-jasp/issues/1816

HamidLD commented 2 years ago

Looks like the same issue as https://github.com/jasp-stats/INTERNAL-jasp/issues/1816

That link doesn't work for me. ("404" error). To give you more information, here's the experiment that has done what I want to do: https://osf.io/3n98r/ I can also do it in R, but thought to give it a try with Jasp first because it's easier ha!

vandenman commented 2 years ago

@HamidLD there is an error because you need to specify initial values for some model components. But unfortunately, an error occurs when trying to show the error message...

With settings like these: image

I get the following error in jasp-stats/jaspJags#69: image

can you tell me what the correct values for these should be?

HamidLD commented 2 years ago

@HamidLD there is an error because you need to specify initial values for some model components. But unfortunately, an error occurs when trying to show the error message...

With settings like these: image

I get the following error in jasp-stats/jaspJags#69: image

can you tell me what the correct values for these should be?

I see. Those values should be: maxpumps: 116 (there is a +1 in the code, so maybe it should be 117) totalTrials: 4830 participants: 161 (each have had 30 trials) This demo file might also be useful: BARTDemo.zip

vandenman commented 2 years ago

Okay so I got the model to run with the following settings: image

The highlighted changes are:

This also works in the current release of JASP, let me know if there are any other issues!

HamidLD commented 2 years ago

@vandenman Thanks! It worked! I had almost given up on this ha. The only thing that confuses me is the number of participants. I have 161 participants, yet this gives you 180 for rho and beta, and it gives the error when you try any number other than 180.

HamidLD commented 2 years ago

I think I found out what's going on. For some reason, the model has calculated imaginary participants, producing very similarly weird numbers and CIs for them (the rho for all of them is 7 with CIs between 0 and 17), so I deleted these and total n is 161 now. Anyway, thanks again, I couldn't have figured this out without you.

vandenman commented 2 years ago

For some reason, the model has calculated imaginary participants, producing very similarly weird numbers and CIs for them (the rho for all of them is 7 with CIs between 0 and 17)

Ah yeah in that case all information is sampled from the prior distributions, so the sampled values probably do not make any sense.

HamidLD commented 2 years ago

For some reason, the model has calculated imaginary participants, producing very similarly weird numbers and CIs for them (the rho for all of them is 7 with CIs between 0 and 17)

Ah yeah in that case all information is sampled from the prior distributions, so the sampled values probably do not make any sense.

Oh yeah that makes sense, thanks!