Jspsych & jatos: Selecting one component from a list of components
Hi,
I have designed an experiment in jspsych in which every 100 max-diff items are allocated to one component added in jatos. I have therefore 100 components and i want to share them by one general multiple link so that each component is selected randomly from the remaining incomplete components. Each component must be done once. How can I do this?
This is the code
<!doctype html>
<html>
<head>
<script src="libs/jquery-3.1.1.min.js"></script>
<script src="jatos.js"></script>
<link rel="stylesheet" href="css/pure-release-0.6.0/pure-min.css">
<link rel="stylesheet" href="css/sort.css">
</head>
<body>
<p>سلام. از اینکه وقت ارزشمند خود را در اختیار ما گذاشتهاید و ما را در این پژوهش برای توسعه و غنی سازی منابع زبان فارسی یاری میکنید، سپاسگزاریم. برای آشنایی با نحوه انجام آزمون دکمه ادامه را بزنید.</p>
<button id="continueButton" class="pure-button">Continue</button>
</body>
<script type="text/javascript">
const components = [
'd0',
'd1',
// ... add more components here
'd2'
];
// Create an array to keep track of completed components
const completedComponents = [];
// Function to check if all components have been completed
function allComponentsCompleted() {
return completedComponents.length === components.length;
}
// Function to randomly choose one component
function chooseComponent() {
// Filter out completed components from the list
const remainingComponents = components.filter(component => !completedComponents.includes(component));
// Randomly choose one component from the remaining list
const chosenComponent = remainingComponents[Math.floor(Math.random() * remainingComponents.length)];
// Run the chosen component online in JATOS
jatos.startStudyComponent(chosenComponent);
}
// Check if all components have been completed
if (allComponentsCompleted()) {
// All components have been completed, do something else
} else {
// Choose a component and run it
chooseComponent();
}
</script>
</html>
Comments
Hi!
I'm not sure I understand your experiment. First, when you are talking about 'components', are you talking about JATOS components or something else?
Then I had a glimpse at your code and saw
jatos.startStudyComponent
. This function does not exist in jatos.js or is this something you defined yourself? If you want to start a certain (JATOS) component you might find jatos.startComponent or jatos.startComponentByPos useful.Best,
Kristian
Hi Kristian,
Yes, I mean JATOS components. I want to have one introductory component in JATOS and 100 components to choose from randomly and only once: each component for one participant. I also want JATOS to keep track of completed components that have saved results, to make sure all the components are chosen. I didn't know how to do the coding, and have arrived at the above code through search, but it didn't work. I also looked at the sample experiment randomize order between workers, but I could not figure how to change it so that rather than randomizing the order of presentation, I randomize the selection of one component. Any pointer to a demo or code is highly appreciated.
Hi,
Your code probably didn't work for a few different reasons. First, some of the functions you're calling don't exist.
But also, the approach of having 100 different components seems really cumbersome. It means that you need to create each of these 100 components by hand in the JATOS GUI I guess, and manually indicate the name of each of the corresponding 100 different HTML files. If you wanted to change something in the script, you would need to do it individually for each of those 100 HTML files.
So my first question: what is exactly the difference between these scripts? Is there a way that you could condense them all into a single JATOS component, with 100 possible different conditions? Is it just the order of stimuli you're presenting?
Then, on to your question - to keep track of what a participants are doing, the best is to use the Batch Session Data. This recent post has an example code of how to do it for two conditions https://forum.cogsci.nl/discussion/8675/counterbalancing-with-batch-session-data#latest
In our docs we have an example of how to counterbalance participants, directing them to different components (as you want to do). Search in this page for the study "randomize tasks between workers". https://www.jatos.org/Example-Studies
You could use the same logic to use the batch session data to determine a condition, and instead of starting the corresponding component with the condition, you could:
Hope this helps
Elisa
Hi Elisa and many thanks. Feeling very embarrassed, I should confess 😳 I didn't know how to set the condition so that each of the js files containing items would be selected each time the experiment is run, up to the time that no condition is left out. So I have created all the 300 components for the three experiments. Here is the code for each component:
Hi Fatemeh,
(just a hint, you can maintain code format when you write here, it makes everything easier to read. I've formatted your message above)
I didn't understand what the difference is between all your 100 or 300 versions. Is it only the line:
In that case, you would need to replace the number (1) that you coded with a variable. I can tell you how, but first need to be sure I understand what all your different versions differ on.
Hi Elisa,
The only code in which the files are different is this and in thecsecon file it is 1.js and the third it is 3.js and so on:
Taken from the heading:
Hi Elisa,
I went for the option of selecting files randomly rather than components and added this code to replace the commented code, but it didn't work either. The js file of the experiment with .txt extension is attached.
Hi, sorry - I still don't understand :)
What is the difference between the code in the scrips:
0.js
and1.js
?Hi Elisa, The only difference is the name of js file as each js file contains 100 items
Hi Fatemeh,
Sorry, with my question I meant to ask: What are you doing differently within those 100 different .js files? As I understand it each of those files calls different stimuli. Is there no way you can define that list of stimuli within your main js code in your script? I mean, instead of calling 100 different scrips, define an array of stimuli that you might want to load, and randomly select the element in the array? (If you don't know how to do it, that might be a question for jsPsych).
If you really want to load those scripts depending on the condition, you could try loading scrips dynamically. https://stackoverflow.com/questions/14521108/dynamically-load-js-inside-js
But here, I really would ask jspsych. Now that we agree that having 100 different components is not the best alternative, it becomes a purely js-question, not a JATOS-question :)
Best
Elisa