This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
en:create:randomization [06.07.2020 11:30] – [Step 2: Presentation of the Stimulus] iah601 | en:create:randomization [11.02.2021 16:47] – sophia.schauer | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Randomization ====== | ====== Randomization ====== | ||
- | Randomization is used to assign a participant at random to an experimental group (random sampling). | + | There are different types of randomization, |
- | This is different to [[rotation|rotation]], in which the order of questions or items is varied in order to reduce bias that might be introduced by the order in which questions/ | + | - [[: |
+ | - [[: | ||
+ | - [[: | ||
+ | - [[: | ||
- | Tip: Read the chapters [[php|Introduction to PHP]] and [[array|Introduction to Arrays]] for a better understanding of the complex example codes shown below. | ||
+ | **Tip:** To understand the more complex code examples, read the chapters [[php|Introduction to PHP Code]] and [[array|Introduction to Arrays]]. | ||
- | ===== General Usage ===== | + | **Tip:** Also check out the [[https:// |
- | The experimental logic (between-subject) assumes that the participants of an experiment are divided into experimental groups. Depending on the group assignment, a question, text, image or video (the treatment or stimulus) | + | **Note:** In distinction to randomization there is also [[en: |
- | Even if your goal " | ||
+ | ===== Special Applications ===== | ||
- | ==== Step 1: Assignment to experimental groups ==== | + | |
- | + | * [[: | |
- | Create a question of type [[: | + | |
- | + | ||
- | < | + | |
- | Control Group | + | |
- | Positive Exemplars | + | |
- | Negative Exemplars | + | |
- | </ | + | |
- | + | ||
- | After saving, SoSci Survey adds a numeric code for each group, e.g. | + | |
- | + | ||
- | < | + | |
- | 1 = Control Group | + | |
- | 2 = Positive Exemplars | + | |
- | 3 = Negative Exemplars | + | |
- | </ | + | |
- | + | ||
- | With the //Type of drawing// you can decide whether you want to select "Equal distribution in completed questionnaires" | + | |
- | + | ||
- | For //Codes drawn per interview// leave the value 1. Thus, the participant is only assigned to one of the experimental conditions/ | + | |
- | + | ||
- | + | ||
- | ==== Step 2: Presentation of the Stimulus ==== | + | |
- | + | ||
- | In **Combine Questionnaire**, | + | |
- | + | ||
- | The random generator will now randomly draw one of the defined groups and store its code in a variable with the random generator' | + | |
- | + | ||
- | Place an element " | + | |
- | + | ||
- | If the stimulus is a question (i.e. in group A another question from the **List of Questions** is to be displayed than in group B), the function '' | + | |
- | + | ||
- | The following PHP code would display the question " | + | |
- | + | ||
- | <code php> | + | |
- | if (value(' | + | |
- | question(' | + | |
- | } elseif (value(' | + | |
- | question(' | + | |
- | } else { | + | |
- | // You may omit the else part, | + | |
- | // nothing happens here | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | The function '' | + | |
- | + | ||
- | The other sections of this manual explain various areas of application of randomization. | + | |
- | + | ||
- | + | ||
- | ===== Drawing of a Random Number ===== | + | |
- | + | ||
- | The random event -- drawing a random number -- lies at the core of every randomization. Generally, there are two possibilities when randomly selecting a stimulus, question, sequence etc: drawing " | + | |
- | + | ||
- | Once a random number has been drawn for the first time, the continued use is independent of " | + | |
- | + | ||
- | * Often, the best solution for drawing a random number is a functional question of type [[: | + | |
- | * An option to the random generator is [[: | + | |
- | * Very rarely, the different variants of the questionnaire are so diverse that using filters is impractical. If this is the case, the participant can be allocated at random to different questionnaires ([[random_questionnaire|Random Selection for Questionnaires]]). Drawing with replacement is always used when a questionnaire is selected at random. Therefore, the resulting group sizes may vary considerably. | + | |
- | + | ||
- | **Tip:** Use '' | + | |
- | + | ||
- | + | ||
- | ===== Randomize Stimulus ===== | + | |
- | + | ||
- | Particularly in experiments, | + | |
- | + | ||
- | The follow example shows how one of 4 pictures can be shown by using [[php|PHP code]]. The prerequisite, | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | // display graphic depending on the number | + | |
- | // (HTML code used for this) | + | |
- | if ($number == 1) { | + | |
- | html('< | + | |
- | } elseif ($number == 2) { | + | |
- | html('< | + | |
- | } elseif ($number == 3) { | + | |
- | html('< | + | |
- | } elseif ($number == 4) { | + | |
- | html('< | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | This example shows graphic " | + | |
- | + | ||
- | Instead of using '' | + | |
- | + | ||
- | The following PHP code presents the same image like the avove PHP code. Yet, this code does not use the full HTML code for each image, but a placeholder '' | + | |
- | <code php> | + | |
- | $code = value(' | + | |
- | + | ||
- | // Grafikdatei in Abhängigkeit von der Zufallszahl in einen Platzhalter schreiben | + | |
- | if ($code == 1) { | + | |
- | replace(' | + | |
- | } elseif ($code == 2) { | + | |
- | replace(' | + | |
- | } elseif ($code == 3) { | + | |
- | replace(' | + | |
- | } elseif ($code == 4) { | + | |
- | replace(' | + | |
- | } | + | |
- | // The HTML code may be embedded via html() | + | |
- | // or (not shown here) as text element | + | |
- | html('< | + | |
- | </ | + | |
- | + | ||
- | **Tip:** Placeholders are especially helpful if the stimulus requires more HTML code then shown in the example above (e.g., to embed videos). | + | |
- | + | ||
- | **Tip:** The name of the PHP variable (the examples use '' | + | |
- | + | ||
- | If your stimuli require extensive HTML code (e.g., videos), when there are substantial differences in the experiment groups' | + | |
- | + | ||
- | <code php> | + | |
- | $code = value(' | + | |
- | + | ||
- | // Embed text or HTML code | + | |
- | if ($code == 1) { | + | |
- | text(' | + | |
- | } elseif ($code == 2) { | + | |
- | text(' | + | |
- | } elseif ($code == 3) { | + | |
- | text(' | + | |
- | } elseif ($code == 4) { | + | |
- | text(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Pictures, Texts, Films, HTML ==== | + | |
- | + | ||
- | In this chapter, several example codes describe how pictures can be rotated or randomized. A HTML tag ''< | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | // enter complete HTML code every time | + | |
- | if ($number == 1) { | + | |
- | html('< | + | |
- | } elseif ($number == 2) { | + | |
- | html('< | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | // only determine the image' | + | |
- | if ($number == 1) { | + | |
- | $image = ' | + | |
- | } elseif ($number == 2) { | + | |
- | $image = ' | + | |
- | } | + | |
- | // ... and only after this generate HTML code | + | |
- | html('< | + | |
- | </ | + | |
- | + | ||
- | Other content -- e.g. films, stimulus texts etc. -- can be integrated as HTML code in exactly the same way. In addition, see [[media|Media Files in Questionnaires]] for more information. | + | |
- | + | ||
- | It is best to enter HTML codes to integrate film and audio files (stimulus texts) as text elements in **Text Elements and Labels** ([[texts|Texts in Questionnaire]]). These text elements can be integrated using the function '' | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | text(' | + | |
- | } elseif ($number == 2) { | + | |
- | text(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | **Note:** The examples above only show excerpts of PHP code that are required to show the stimulus. A random number still has to be drawn and sorted beforehand. (see above). | + | |
- | + | ||
- | **Tip:** You can indeed combine multiple elements in a text element -- for instance, a picture with text next to it. | + | |
- | + | ||
- | < | + | |
- | <table cellspacing=" | + | |
- | < | + | |
- | <col width=" | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | <td style=" | + | |
- | < | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Stimulus and Question Together ==== | + | |
- | + | ||
- | Do you require one question for one part of the stimuli and another question for the rest? | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | text(' | + | |
- | question(' | + | |
- | } elseif ($number == 2) { | + | |
- | text(' | + | |
- | question(' | + | |
- | } elseif ($number == 3) { | + | |
- | text(' | + | |
- | question(' | + | |
- | } elseif ($number == 4) { | + | |
- | text(' | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== Randomization | + | |
- | + | ||
- | Entire questions are randomized primarily in method experiments --- this is also easy to do with filters. In principle, the process is the same as when a stimulus is randomized: | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | // Display one question or another | + | |
- | if ($number == 1) { | + | |
- | question(' | + | |
- | } elseif ($number == 2) { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | It gets a little more tricky if the questions should appear on different pages in the questionnaire. If this is the case, you have to filter in two places: | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | // Display one question or another | + | |
- | if ($number == 1) { | + | |
- | question(' | + | |
- | } else { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | question(' | + | |
- | } else { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | In this example, either question AB01 will be shown first and then AB02 later at random -- or the other way round. | + | |
- | + | ||
- | ===== Randomization of Pages ===== | + | |
- | + | ||
- | If the page order should be more varied more complexly, then filters can quickly become confusing -- as shown in the example above. The PHP function '' | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | setPageOrder(' | + | |
- | } elseif ($number == 2) { | + | |
- | setPageOrder(' | + | |
- | } else { | + | |
- | setPageOrder(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | You can find further explanations and examples in the section '' | + | |
- | + | ||
- | + | ||
- | ==== Stimuli and Questions on different pages ==== | + | |
- | + | ||
- | If there is a distinct question for each stimulus variant, and both shall be presented on different pages, use a filter on both pages. As soon as a random number has been drawn once (e.g., as variable '' | + | |
- | + | ||
- | <code php> | + | |
- | // PHP code in the page with the stimulus | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | text(' | + | |
- | } elseif ($number == 2) { | + | |
- | text(' | + | |
- | } elseif ($number == 3) { | + | |
- | text(' | + | |
- | } elseif ($number == 4) { | + | |
- | text(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | // PHP code on a later page that displays the question | + | |
- | $number = value(' | + | |
- | + | ||
- | if ($number == 1) { | + | |
- | question(' | + | |
- | } elseif ($number == 2) { | + | |
- | question(' | + | |
- | } elseif ($number == 3) { | + | |
- | question(' | + | |
- | } elseif ($number == 4) { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | **Note: | + | |
- | + | ||
- | **Tip:** This variable also allows the distribution | + | |
- | + | ||
- | + | ||
- | ===== Random Selection of Questions ===== | + | |
- | + | ||
- | Do you want to show 3 questions out of 10 at random, in order to distribute your stimulus across several participants? | + | |
- | + | ||
- | ==== Selection with Replacement ==== | + | |
- | + | ||
- | If it does not matter which combination the questions are shown in __and__ if there the number of cases per question is big enough to cope with statistical fluctuations, | + | |
- | + | ||
- | <code php> | + | |
- | // make sure page will not be redrawn when reloaded | + | |
- | if (!isset($questions)) { | + | |
- | | + | |
- | $questions = array( | + | |
- | ' | + | |
- | ' | + | |
- | ); | + | |
- | // shuffle list | + | |
- | shuffle($questions); | + | |
- | // and save variable for a new display of the page | + | |
- | registerVariable(' | + | |
- | } | + | |
- | // show question, which ranks first after shuffling | + | |
- | question($questions[0]); | + | |
- | // and the questions in second and third place | + | |
- | question($questions[1]); | + | |
- | question($questions[2]); | + | |
- | </ | + | |
- | + | ||
- | **Tip:** If questions should be shown on separate pages, simply place the lines with '' | + | |
- | + | ||
- | **Take care:** If you use several types of these selections in the questionnaire, | + | |
- | + | ||
- | ==== Selection without Replacement ==== | + | |
- | + | ||
- | If you have to make sure that all questions are shown equally often, you need an urn that contains the possible question IDs in combinations of three. You have to create these combinations beforehand, e.g. in Excel. | + | |
- | + | ||
- | < | + | |
- | AB01, AB02, AB04 | + | |
- | AB01, AB02, AB05 | + | |
- | ... | + | |
- | AB05, AB03, AB04 | + | |
- | AB05, AB04, AB03 | + | |
- | </ | + | |
- | + | ||
- | Indeed, there are 60 combinations possible with just 5 questions. If you have distinctly more combinations than participants then you have might have to remove a portion of the combinations systematically -- otherwise it is not guaranteed that the questions will be shown equally often. | + | |
- | + | ||
- | In the questionnaire you now draw one of the combinations out of the urn and use the IDs drawn as they are in the '' | + | |
- | + | ||
- | <code php> | + | |
- | urnDraw(' | + | |
- | question(value(' | + | |
- | question(value(' | + | |
- | question(value(' | + | |
- | </ | + | |
- | + | ||
- | You can also distribute the '' | + | |
- | + | ||
- | + | ||
- | ==== Lots of Stimuli ==== | + | |
- | + | ||
- | If possible, you would like a greater number of objects to be evaluated. Instead of using an '' | + | |
- | + | ||
- | <code php> | + | |
- | $number = value(' | + | |
- | if ($number == 1) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 2) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 3) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 4) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 5) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 6) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 7) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 8) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 9) { | + | |
- | $src = ' | + | |
- | } elseif ($number == 10) { | + | |
- | $src = ' | + | |
- | } | + | |
- | html(' | + | |
- | <div style=" | + | |
- | <img src="' | + | |
- | </ | + | |
- | '); | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | urnDraw(' | + | |
- | switch (value(' | + | |
- | case 1 : $src = ' | + | |
- | case 2 : $src = ' | + | |
- | case 3 : $src = ' | + | |
- | case 4 : $src = ' | + | |
- | case 5 : $src = ' | + | |
- | case 6 : $src = ' | + | |
- | case 7 : $src = ' | + | |
- | case 8 : $src = ' | + | |
- | case 9 : $src = ' | + | |
- | case 10 : $src = ' | + | |
- | } | + | |
- | html(' | + | |
- | <div style=" | + | |
- | <img src="' | + | |
- | </ | + | |
- | '); | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== Combinations ===== | + | |
- | + | ||
- | You are also able to draw an entire combination with an urn, not just a random number. This means it is easy to implement multi-factorial experiments or conjoint analyses. | + | |
- | + | ||
- | This example uses 3 internal variables ('' | + | |
- | + | ||
- | < | + | |
- | 1, 1, 1 | + | |
- | 1, 1, 2 | + | |
- | 1, 2, 1 | + | |
- | 1, 2, 2 | + | |
- | 2, 1, 1 | + | |
- | 2, 1, 2 | + | |
- | 2, 2, 1 | + | |
- | 2, 2, 2 | + | |
- | </ | + | |
- | + | ||
- | In this example, a combination of three is always drawn. Each of the three variables is denoted as either 1 or 2. By using an array, text is assigned to the numbers. In doing so, the value drawn (1 or 2) serves as a key -- this is indicated in square brackets, in order to select the respective element of the array. See [[: | + | |
- | + | ||
- | <code php> | + | |
- | urnDraw(' | + | |
- | // the numbers program three features - text is assigned to them here | + | |
- | $price = array( | + | |
- | 1 => '5 euros', | + | |
- | 2 => '10 euros', | + | |
- | ); | + | |
- | $quality = array( | + | |
- | 1 => ' | + | |
- | 2 => ' | + | |
- | ); | + | |
- | $deliverytime = array( | + | |
- | 1 => ' | + | |
- | 2 => ' | + | |
- | ); | + | |
- | html(' | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | '); | + | |
- | </ | + | |
- | + | ||
- | ===== Draw Multiples out of Urns ===== | + | |
- | + | ||
- | **Important: | + | |
- | + | ||
- | If you want to draw from different urns you also need several questions with the type " | + | |
- | + | ||
- | <code php> | + | |
- | urnDraw(' | + | |
- | urnDraw(' | + | |
- | urnDraw(' | + | |
- | // ballots will not stored until the participant | + | |
- | // reaches the end of the questionnaire - and so drop outs will not be counted in the draw | + | |
- | + | ||
- | // now there is age, first name and sex in the " | + | |
- | // this is merged as "age (first name, sex)" | + | |
- | $description1 = value(' | + | |
- | $description2 = value(' | + | |
- | // now in the description there is | + | |
- | // e.g. " | + | |
- | // now it states in the third ballot, what the relationship is | + | |
- | // between the two of them, and a description of the situation | + | |
- | // is thus created like so: | + | |
- | $complete = $description1.' | + | |
- | // e.g. " | + | |
- | // of course, the text could also be integrated in the question via placeholder | + | |
- | html($complete); | + | |
- | </ | + | |
- | + | ||
- | Now onto an even more complicated example which shows how random numbers can be transformed in text elements. | + | |
- | + | ||
- | < | + | |
- | 11, 21 | + | |
- | 11, 22 | + | |
- | 11, 23 | + | |
- | 11, 24 | + | |
- | 12, 21 | + | |
- | 12, 22 | + | |
- | ... | + | |
- | 16, 23 | + | |
- | 16, 24</ | + | |
- | + | ||
- | <code php> | + | |
- | // draw a combination out of the " | + | |
- | // do not store ballot yet | + | |
- | urnDraw(' | + | |
- | // values now saved under A101_01 and A101_02 | + | |
- | // the first value can be 11-16, the second 21-24 | + | |
- | // saves texts in variables $text1 and $text2 | + | |
- | switch (value(' | + | |
- | case 11: $text1 = '500 euros'; | + | |
- | case 12: $text1 = '1000 euros'; | + | |
- | case 13: $text1 = '1500 euros'; | + | |
- | case 14: $text1 = '2000 euros'; | + | |
- | case 15: $text1 = '2500 euros'; | + | |
- | case 16: $text1 = '3000 euros'; | + | |
- | default: $text1 = ' | + | |
- | } | + | |
- | switch (value(' | + | |
- | case 21: $text2 = 'a friend'; | + | |
- | case 22: $text2 = 'a relative'; | + | |
- | case 23: $text2 = 'a colleague'; | + | |
- | case 24: $text2 = 'your boss'; break; | + | |
- | default: $text1 = ' | + | |
- | } | + | |
- | $situation = $text2.' | + | |
- | // save in placeholder %situation% | + | |
- | replace(' | + | |
- | // question regarding situation (with placeholder %situation%) | + | |
- | question(' | + | |
- | </ | + | |
- | + | ||
- | When all relevant information has been requested the ballot will be stored on a later page: | + | |
- | + | ||
- | <code php> | + | |
- | urnPutAway(' | + | |
- | // or in this case also simply just | + | |
- | urnPutAway(); | + | |
- | </ | + | |
- | + | ||
- | **Note:** When drawing out of multiple urns, an equal distribution of the individual | + | |
- | + | ||
- | **Note:** If you draw out of the same urn twice, then you can get two of the same ballots in the process of doing so. To avoid this, only work with one of the urns that contains all the necessary combinations. | + | |
- | + | ||
- | ===== Urns for Subgroup I ===== | + | |
- | + | ||
- | It may be the case that you need to ensure equal distribution of experimental groups in two subgroups -- for instance, if you have 3 stimuli and both the women in the study, as well as the men, should be equally divided between all three conditions. | + | |
- | + | ||
- | To do so, you require an internal variable and two urns (with the same content). The following example assumes that the sex was queried on an earlier page in the multiple-choice question SD02. Also, that you have set up two urns with the IDs " | + | |
- | + | ||
- | <code php> | + | |
- | if (value(' | + | |
- | urnDraw(' | + | |
- | } else { | + | |
- | urnDraw(' | + | |
- | } | + | |
- | + | ||
- | // show stimulus | + | |
- | $z = value(' | + | |
- | if ($z == 1) { | + | |
- | text(' | + | |
- | } elseif ($z == 2) { | + | |
- | text(' | + | |
- | } elseif ($z == 3) { | + | |
- | text(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== Urns for Subgroup II ===== | + | |
- | + | ||
- | If possible, the different subpopulations (e.g. men and women) should also get given different stimuli. A simple solution would be to put different numbers in the urns. | + | |
- | + | ||
- | For the following example, you need an " | + | |
- | + | ||
- | Apart from that, the PHP code is largely identical with the previous example. | + | |
- | + | ||
- | <code php> | + | |
- | if (value(' | + | |
- | urnDraw(' | + | |
- | } else { | + | |
- | urnDraw(' | + | |
- | } | + | |
- | + | ||
- | // show stimulus | + | |
- | $z = value(' | + | |
- | if ($z == 1) { | + | |
- | text(' | + | |
- | } elseif ($z == 2) { | + | |
- | text(' | + | |
- | } elseif ($z == 3) { | + | |
- | text(' | + | |
- | } elseif ($z == 4) { | + | |
- | text(' | + | |
- | } elseif ($z == 5) { | + | |
- | text(' | + | |
- | } elseif ($z == 6) { | + | |
- | text(' | + | |
- | } | + | |
- | </ | + |