Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
en:create:randomization [06.06.2017 12:52] – [Drawing of a Random Number] adminen:create:randomization [06.06.2017 13:14] – update admin
Line 16: Line 16:
   * An option to the random generator is [[:en:create:random_urns]]. These may draw combinations of multiple values and are therefore especially useful for multi-factor experiments and conjoint analyses.   * An option to the random generator is [[:en:create:random_urns]]. These may draw combinations of multiple values and are therefore especially useful for multi-factor experiments and conjoint analyses.
   * 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.   * 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 ''value()'' to get the previously drawn random value. Note, that ''​value()''​ works already on the same page for random values, and on any later page. This allows to present different parts of the stimulus and/or related questions on different pages.
  
  
Line 42: Line 44:
 This example shows graphic "stimulus1.png", "stimulus2.png", "stimulus3.png" or "stimulus4.png" at random. As an example, a question evaluating the picture could be displayed below this. This example shows graphic "stimulus1.png", "stimulus2.png", "stimulus3.png" or "stimulus4.png" at random. As an example, a question evaluating the picture could be displayed below this.
  
-Instead of using ''html()'' to display text or a graphic, ''[[:en:create:functions:text|text()]]'' can also be used to show a longer text, integrate a video or show a question with ''[[:en:create:functions:question|question()]]''+Instead of using ''html()'' to display text or a graphic, ''[[:en:create:functions:text|text()]]'' can also be used to show a longer text, integrate a video or show a question with ''[[:en:create:functions:question|question()]]''. 
 + 
 +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 ''​%filename%''​ and the funktion ''​[[:​en:​create:​functions:​replace]]''​. 
 +<code php> 
 +$code = value('​RG01'​); ​ // Auslesen der gezogenen Zufallszahl 
 + 
 +// Grafikdatei in Abhängigkeit von der Zufallszahl in einen Platzhalter schreiben 
 +if ($code == 1) { 
 +  replace('​%filename%',​ '​stimulus1.png'​);​ 
 +} elseif ($code == 2) { 
 +  replace('​%filename%',​ '​stimulus2.png'​);​ 
 +} elseif ($code == 3) { 
 +  replace('​%filename%',​ '​stimulus3.png'​);​ 
 +} elseif ($code == 4) { 
 +  replace('​%filename%',​ '​stimulus4.png'​);​ 
 +
 +// The HTML code may be embedded via html() 
 +// or (not shown here) as text element 
 +html('<​p><​img src="​%filename%"></​p>'​);​ 
 +</​code>​ 
 + 
 +**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 ''​$number''​ and ''​$code''​) is chosen arbitraryly. See also [[en:​create:​variables#​php-variables|PHP variables]]. 
 + 
 +If your stimuli require extensive HTML code (e.g., videos), when there are substantial differences in the experiment groups' HTML codes, or when a [[:​en:​create:​multilang|multilingual questionnaire]] is employed, then create four texts in the list of questions (e.g., "​RG02"​ to "​RG05",​ //​Layout//​ must be HTML code) and use one of them, depending on the random number: 
 + 
 +<code php> 
 +$code = value('​RG01'​); ​ // Getting the previously drawn random number 
 + 
 +// Embed text or HTML code 
 +if ($code == 1) { 
 +  text('​RG02'​);​ 
 +} elseif ($code == 2) { 
 +  text('​RG03'​);​ 
 +} elseif ($code == 3) { 
 +  text('​RG04'​);​ 
 +} elseif ($code == 4) { 
 +  text('​RG05'​);​ 
 +
 +</​code>
  
  
Line 50: Line 92:
  
 <code php> <code php>
 +$number = value('​RG01'​);
 +
 // enter complete HTML code every time  // enter complete HTML code every time 
 if ($number == 1) { if ($number == 1) {
Line 58: Line 102:
 </code> </code>
  
-<code>+<code php> 
 +$number = value('​RG01'​);​ 
 // only determine the image's name in the filter ... // only determine the image's name in the filter ...
 if ($number == 1) { if ($number == 1) {
Line 74: Line 120:
  
 <code php> <code php>
 +$number = value('​RG01'​);
 +
 if ($number == 1) { if ($number == 1) {
   text('stimulusA');   text('stimulusA');
Line 106: Line 154:
  
 <code php> <code php>
 +$number = value('​RG01'​);
 +
 if ($number == 1) { if ($number == 1) {
   text('stimulusA');   text('stimulusA');
Line 127: Line 177:
  
 <code php> <code php>
 +$number = value('​RG01'​);
 +
 +// Display one question or another
 if ($number == 1) { if ($number == 1) {
   question('AB01');   question('AB01');
Line 137: Line 190:
  
 <code php> <code php>
-// show the one or the other question 
 $number = value('RG01');  // Retrieve the random number drawn by RG01 $number = value('RG01');  // Retrieve the random number drawn by RG01
 +
 +// Display one question or another
 if ($number == 1) { if ($number == 1) {
   question('AB01');  // assessment of politician   question('AB01');  // assessment of politician
Line 148: Line 202:
 <code php> <code php>
 $number = value('RG01'); $number = value('RG01');
 +
 if ($number == 1) { if ($number == 1) {
   question('AB02');  // assessment of party   question('AB02');  // assessment of party
Line 163: Line 218:
 <code php> <code php>
 $number = value('RG01');  // Must have drawn a random number with RG01 $number = value('RG01');  // Must have drawn a random number with RG01
 +
 if ($number == 1) { if ($number == 1) {
   setPageOrder('q1','q2','mainStart-mainEnd','q3');   setPageOrder('q1','q2','mainStart-mainEnd','q3');
Line 173: Line 229:
  
 You can find further explanations and examples in the section ''[[:en:create:functions:setpageorder|setPageOrder()]]''. You can find further explanations and examples in the section ''[[:en:create:functions:setpageorder|setPageOrder()]]''.
 +
 +
 +==== 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 ''RG01''), it's available on any subsequent page via ''value()''. This means that a random generator or ''urnDraw()'' needs being placed on a single page, only. Usually immediately before the first filter.
 +
 +<code php>
 +// PHP code in the page with the stimulus
 +$number = value('​RG01'​);
 +
 +if ($number == 1) {
 +  text('​stimulusA'​);
 +} elseif ($number == 2) {
 +  text('​stimulusB'​);
 +} elseif ($number == 3) {
 +  text('​stimulusC'​);
 +} elseif ($number == 4) {
 +  text('​stimulusD'​);
 +}
 +</​code>
 +
 +<code php>
 +// PHP code on a later page that displays the question
 +$number = value('​RG01'​);
 +
 +if ($number == 1) {
 +  question('​AB01'​);
 +} elseif ($number == 2) {
 +  question('​AB01'​);
 +} elseif ($number == 3) {
 +  question('​AB02'​);
 +} elseif ($number == 4) {
 +  question('​AB02'​);
 +}
 +</​code>
 +
 +**Note:​** This solution if, of course, __not__ required if the question is the same, independently from the stimulus.
 +
 +**Tip:** This variable also allows the distribution of a stimulus (e.g., pages 1 to 3 of a newspaper article) on different pages.
  
  
Line 332: Line 427:
  
 ===== Draw Multiples out of Urns ===== ===== Draw Multiples out of Urns =====
 +
 +**Important:​** If you would like to draw multiple options with an interview, but none of the options must be drawn twice, then use a [[:ene:​create:​questions:​random]] instead of an urn. Please also read the advice at the end of this section.
  
 If you want to draw from different urns you also need several questions with the type "Internal Variables" -- in this example there are three of these types of question "IV01", "IV02" und "IV03". If you want to draw from different urns you also need several questions with the type "Internal Variables" -- in this example there are three of these types of question "IV01", "IV02" und "IV03".
en/create/randomization.txt · Last modified: 20.04.2021 20:33 by sophia.schauer
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki