Python to Javascript translation to end experiment early

For the incorrect trials, was it due to no response (ran out of time)? If so, resp.corr might be blank. You could try (in Python)

if resp.corr:
     respcorrs.append(1)
else:
     respcorrs.append(0)

You could also try print(‘Trial ‘+str(trials.thisN)+’:
‘+str(respcorrsSum)+’/’+considerNrTrials+’=’+str(accuracy)) to check it’s increasing as expected

No it wasn’t due to time, just an outright incorrect answer

Weirdly that did 32 trials even though 4 were wrong which still would have been +80% accuracy

Yeah it’s doing 32 every time!

Even if you get the first 10 wrong?

No it carries on to full number of reps when incorrect answers given, if I set min trials to 34 then if all are correct 36 will run. So it is just adding on two more trials, so I have just set the min number of trials 2 lower (34), then it will run the min number of trials I need (36)!
That’ll do for now! I’ve tested it a few times and seems to work like that.

Thank you so much for all your help. I really do appreciate it! I’m so happy it’s working for what I need! You’ve really helped me out a great deal :’)
Have a lovely evening

The reason for the 2 offset is because

  1. The first trial has trials.thisN==0

  2. It is checking for > rather than >=

Best wishes

Wakefield

Sorry to be getting back in contact again. But after testing the program multiple times I’ve seen that the code might not be working as desired. For instance, I just ran it and the routine ended after 44 trials even though only 15 trials were correct. Meaning the routine ended despite not meeting the minimum accuracy threshold.
I’m making multiple versions to counterbalance manually which I can’t imagine that would have anything to do with it. But I’ve discovered this issue when testing each version.
I had run it multiple times before and it has ended correctly at 36 (the min number trials) when accuracy is high and it has run through to the max number of trials when accuracy is low.
So I don’t know if you have any idea why there would be this inconsistency?
Many thanks,
Ellen

How many trials do you have (nReps x length of spreadsheet)?

trials.finished=True ends a loop early but if that doesn’t happen it will end when it runs out of trials.

So I’ve set the number of reps so that 48 trials is the maximum so that if the threshold isn’t reached, it will end at 48 as the maximum

Try adding thisExp.addData(‘Accuracy’,accuracy) and then run through a pilot where you alternate getting the answer correct and incorrect, and then take a look at the data to see if anything weird is happening.

Where do I put the thisExp.addData(‘Accuracy’,accuracy)?

After the calculation of accuracy would be an appropriate place.

You also need to define thisExp in code_JS if you haven’t already.

Yeah I’ve got it in the code_JS but I get this error when I synch 7014.1849 ERROR Line 1148: Unexpected token ILLEGAL in 2B-legacy-browsers.js

respcorrs.append(resp.corr);
if ((resp.length > considerNrTrials)) {
    respcorrs.pop(0);
}
respcorrsSum = (sum(respcorrs) + 0);
accuracy = (Number.parseFloat(respcorrsSum) / considerNrTrials);
if (((accuracy > minAccuracy) && (trials.thisN > minNrPractice))) {
    trials.finished = true;
}

if (resp.corr) {
    respcorrs.append(1);
} else {
    respcorrs.append(0);

thisExp.addData(‘Accuracy’,accuracy);
}

You’ve put it inside the response incorrect brackets. Put it the other side of the closing bracket.

The error is because you have a smart speech mark. You need to use plain ’ symbols.

Okay so I’ve done that, thank you.
I piloted the experiment with a mixture of correct and incorrect (it’s really hard to alternate exactly with this task). It ended after 36 trials with only 20 correct (55%).
From the spreadsheet it’s recording correct and incorrect responses correctly

Alternating exactly doesn’t matter. Please could you upload your data file?

testeheh_2B_2020-07-27_14h47.38.346.csv (14.6 KB)
I’ve highlighted the problem trials in red

Something’s definitely wrong there.

In row 26, accuracy is 1/34

After that the number of correct answers increases by 1 when the run switches from being correct to incorrect or vice versa and then increases by 0 for following incorrect answers or 2 for following correct answers.

The issue is that you have both

respcorrs.append(resp.corr);

and

if (resp.corr) {
respcorrs.append(1);
} else {
respcorrs.append(0);

Try deleting the second set of code.

Amazing thank you.
From the spreadsheet I think that’s fixed it, the accuracy increases as it should be each correct response!
Thanks so much again for your help.