I am conducting a web study where participants will be proportionately and randomly assigned to treatment groups in the form of different web pages. I have a study landing page where I plan to assign participants to different treatment groups by directing them to different pages based on a random integer within the range of the sample size. For example, for a n=100 study, this code might look like:
/// Function for randomly shuffling array
function shuffle(array) {
array.sort(() => Math.random() - 0.5);
}
const STUDY_LEN = 100; /// Study n
const arr_0 = new Array(STUDY_LEN/2).fill(0); /// Create array for treatment 1
const arr_1 = new Array(STUDY_LEN/2).fill(1); /// Create array for treatment 2
const arr_assign = arr_0.concat(arr_1); /// Concatenate treatment arrays for entire study assignment
arr_shuffle = shuffle(arr_assign); /// Randomize order of array
for (i = 0; i < STUDY_LEN-1; i++){
if (arr_shuffle[i] == 0){
//// Change hyperlink to web page for treatment 1
}
else{
//// Change hyperlink to web page for treatment 2
}
}
How can I store these variables (mainly the shuffled assignment array) across multiple visits to the web page so that I assign participants to each treatment equally (50 participants in treatment 1, 50 participants in treatment 2)? My solution doesn't seem like a very robust way to randomly assign users to different treatments, so I'm open to any/all suggestions.
Aucun commentaire:
Enregistrer un commentaire