This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
en:create:questions:random [30.07.2019 22:23] – Update admin | en:create:questions:random [11.03.2021 17:21] – sophia.schauer | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Random | + | ====== Random |
- | The random generator | + | **Tip:** This page explains in detail how to create a random generator and when such a generator |
- | The random generator | + | The random generator |
- | The extensive examples in the chapter [[: | + | By default, the random |
- | **Hint:** If the random variation | + | **Tip:** If the random variation |
+ | There are several ways how to use a random generator. This are some functions which the random generator can execute: | ||
+ | * Two values are available for the drawn note: First, the numeric code and second, the entered text for the slip -- this can be, for example, the filename of an image (e.g. [[en: | ||
+ | * The random generator can draw multiple slips within an interview (option //Codes drawn per interview// | ||
+ | * The random generator returns only one value (and its label) per slip. But combinations can also be implemented using randomization (see [[en: | ||
- | ===== Differences between random generator and urn function ===== | ||
- | * For the second drawn ballot two kinds of values are available: first the numeric code and second the inscribed text for the ballot (e.g. the file name of a image, as seen in the example below) | + | ===== Create |
- | * The random generator | + | Here is explained how to create a simple |
- | * The random generator | + | |
+ | ====Step 1: Add a Random Generator==== | ||
- | ===== Example: Varying screen-stimulus ===== | + | The random generator as a functional building block is created as a new question in a rubric ([[en:create: |
- | This example describes the use of the random | + | {{: |
+ | You need the question ID in following PHP-codes. | ||
- | ===== Preperations ===== | + | ====Step 2: Add Contents==== |
+ | In the next step you enter the //Codes (Contents)// | ||
- | * Upload the 3 image stimuli | + | For example, if you want to randomize |
- | | + | |
+ | Group 1 | ||
+ | Group 2 | ||
+ | Control group | ||
+ | By saving | ||
+ | Example: | ||
+ | 1= Group 1 | ||
+ | 2= Group 2 | ||
+ | 3= Control group | ||
- | < | + | Now, when the random number generator is placed in the questionnaire, |
- | 1 = stimulusA.jpg | + | |
- | 2 = stimulusB.jpg | + | |
- | 3 = stimulusC.jpg | + | |
- | 4 = control_group | + | |
- | </ | + | |
- | ===== Application ===== | + | ====Step 3: More Settings==== |
+ | In some cases it is necessary to optimize the random generator: | ||
- | Under **Create a Questionnaire** you can drag and drop the random generator to the page you want the picture to appear. Now place (s. also [[:en:create:php]]) the following PHP code beneath (!) the random generator: | + | |
+ | | ||
+ | * Display contents:\\ it is also possible to already specify file names as slips and to include them directly on the questionnaire page using //show content// (see [[en: | ||
- | <code php> | ||
- | // Retrieve the numeric codes (1 bis 4) | ||
- | $code = value(' | ||
- | // The control group has to be treated differently | ||
- | if ($code == 4) { | ||
- | // Kontrollgruppe - nichts anzeigen | ||
- | } else { | ||
- | // The inscription is saved as a value label – in this example the image name | ||
- | $img = value(' | ||
- | // The HTML-Tag <img> shows an image, the filename will be shown with src | ||
- | html(' | ||
- | <div style=" | ||
- | <img src="' | ||
- | </ | ||
- | '); | ||
- | } | ||
- | </ | ||
+ | ====Step 4: Placing the Random Generator==== | ||
+ | Depending on the further use of the values of the random generator, it must be placed appropriately in the questionnaire. To do this, the question must be dragged to one side when **Compose Questionnaire**. In any case, the value must be placed __before__ a PHP code where the value is to be read. Once the value of the random generator has been drawn, this value can be read out again in the questionnaire at any time. | ||
- | //in case your image width does not display properly, you can include this coding for width for the html code: | + | =====Using |
- | html(' | + | The random generator is needed as a basis for some dynamic content in SoSci Survey. This includes: |
- | <img src="' | + | * [[en: |
- | </ | + | * [[en: |
- | | + | * [[en: |
+ | | ||
- | ==== Addition 1 ==== | + | ===== Readjust Drawings ===== |
- | Not every experimental | + | If one works with many experimental |
- | This time the filename for the image will not be saved directly into the random generator | + | |
- | <code php> | + | **Attention: |
- | // Retrieving | + | Imagine an experiment with 4 groups, where the participants are all invited on a certain day. After 2/3 of the participants have completed the questionnaire, one notices |
- | $code = value(' | + | |
- | // The control group must (here to) be treated differently | + | |
- | if ($code == 4) { | + | |
- | | + | |
- | } else { | + | |
- | // Array, that saves an image for every group | + | |
- | $bilder = array( | + | |
- | | + | |
- | 2 => ' | + | |
- | 3 => ' | + | |
- | ); | + | |
- | // With the square brackets | + | |
- | $bild = $bilder[$code]; | + | |
- | // Display oft he image as above | + | |
- | html(' | + | |
- | <div style=" | + | |
- | <img src="' | + | |
- | </ | + | |
- | '); | + | |
- | } | + | |
- | </ | + | |
- | **Note:** This PHP-code only works, if at an earlier time in the same interview another page with a random generator question was used. If you start the interview for testing directly on the page with the PHP-code (but without a random generator, which occurs earlier in the interview), you will receive an error message. | + | **Tip:** In case you cannot adjust the random draw afterwards, you can use a [[: |
- | ==== Addition 2 ==== | + | If the conditions for readjustment (see above) are met, the procedure is as follows: |
- | + | - The preliminary | |
- | Instead of an image also a question or a text module can be integrated. The following PHP code displays an individual text module (create under **Text Elements and Labels** -- and in groups 1 and 2 the question '' | + | - A frequency table is created over the variable |
- | + | ||
- | <code php> | + | |
- | // Retrieving of the numeric codes (1 to 4) | + | |
- | $code = value(' | + | |
- | // Varriing the text modules | + | |
- | if ($code == 1) { | + | |
- | text(' | + | |
- | } elseif ($code == 2) { | + | |
- | text(' | + | |
- | } elseif ($code == 3) { | + | |
- | text(' | + | |
- | } elseif ($code == 4) { | + | |
- | text(' | + | |
- | } | + | |
- | // Variing the questions | + | |
- | if (($code == 1) or ($code == 2)) { | + | |
- | question(' | + | |
- | } else { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | **Note:** view in addition to '' | + | |
- | + | ||
- | + | ||
- | ===== Example: Show multiple images ===== | + | |
- | In this example participants should rate 300 images. To achieve this each participant has to rate 20 different pictures - each on a different page. | + | |
- | + | ||
- | ==== Preperation ==== | + | |
- | * Upload all images to **Images and Media Data** | + | |
- | * Create a new question of the „random generator“ type (in the following case the question is named ZG03). | + | |
- | * Enter the file names of the images as ballots into the question, one filename per line. You don’t have to put numbers ahead, they will be provided automatically after saving. | + | |
- | * For the option //Number of ballots per interview//, | + | |
- | * For the ratings create 20 questions with ID’s ranging from '' | + | |
- | + | ||
- | ==== Application ==== | + | |
- | Create one (!) page to display the images and the corresponding questions using **Create a Questionnaire**. Place the random generator on this page and beneath it the following PHP code (s. also [[: | + | |
- | + | ||
- | <code php> | + | |
- | // loopPage(20) provides a number between 0 and 19 (plus one at every repetition) | + | |
- | $i = loopPage(20); | + | |
- | // Show the chosen picture | + | |
- | $varID = ' | + | |
- | $img = value($varID, | + | |
- | // The HTML-Tag <img> shows one image, the filename will be shown with src | + | |
- | html(' | + | |
- | <div style=" | + | |
- | <img src="' | + | |
- | </ | + | |
- | '); | + | |
- | // Create the fitting question ID and show the question using question() | + | |
- | question(id(' | + | |
- | </ | + | |
- | + | ||
- | If you didn’t create 20 questions ('' | + | |
- | + | ||
- | <code php> | + | |
- | // Shows the item fitting to the question using question() | + | |
- | question(' | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== Example: Rate multiple political parties ===== | + | |
- | + | ||
- | In the following example the participants have to evaluate political parties using many different criteria. Altogether 6 parties have to be evaluated – but every participant should only have to evaluate two of them chosen randomly. | + | |
- | + | ||
- | ==== Option 1 ==== | + | |
- | + | ||
- | This Option will always save the answers to the first drawn party in the same variable. If you use e.g. 20 variables per party, your dataset will have 40 variables for party evaluations. This is overseeable, | + | |
- | + | ||
- | * Create a category (e.g. “P1”) in your questionnaire, | + | |
- | * Create a copy of the category, by downloading the category as an XML-file (Arrow down symbol in the toolbar above the question) and importing the file under //New category//. In this example the label '' | + | |
- | * Create a questionnaire under ** Create a Questionnaire ** and place the questions from '' | + | |
- | * Create a question of the type " | + | |
- | + | ||
- | < | + | |
- | 1 = CDU/CSU | + | |
- | 2 = SPD | + | |
- | 3 = Die Grünen | + | |
- | 4 = Die Linke | + | |
- | 5 = Piraten | + | |
- | 6 = AfD | + | |
- | </ | + | |
- | + | ||
- | Place the random generator under ** Create a Questionnaire ** on the first page with a '' | + | |
- | + | ||
- | <code php> | + | |
- | $name = value(' | + | |
- | replace(' | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | From there on the placeholder '' | + | |
- | + | ||
- | Place the following PHP-code on the first page with a „P2“-question: | + | |
- | + | ||
- | <code php> | + | |
- | $name = value(' | + | |
- | replace(' | + | |
- | </ | + | |
- | + | ||
- | If you want to mix the questions about the two parties, and if you have therefore used the placeholders '' | + | |
- | + | ||
- | <code php> | + | |
- | $name1 = value(' | + | |
- | replace(' | + | |
- | $name2 = value(' | + | |
- | replace(' | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Option 2 ==== | + | |
- | + | ||
- | It’s also possible to create own questions for every party. If you ask for 20 variables per party, the dataset will sum up to 120 variables – but therefore the evaluations of a party will always be saved into the same variables. The creation of that many questions might be more effortful but it’s also way easier to analyse. | + | |
- | + | ||
- | * Create a category (e.g. “P1”) in your questionnaire, | + | |
- | * In this option you can enter the party name directly into the question (and change it in every copy manually) or | + | |
- | * Instead of entering the party name you can enter the [[: | + | |
- | * Create 5 copies of the category by downloading the category as an XML-file (Arrow down symbol in the toolbar above the question) and subsequently import it multiple times using //New Category//. In this example the copys will be labelled '' | + | |
- | * Create a question of the type " | + | |
- | + | ||
- | < | + | |
- | 1 = CDU/CSU | + | |
- | 2 = SPD | + | |
- | 3 = Die Grünen | + | |
- | 4 = Die Linke | + | |
- | 5 = Piraten | + | |
- | 6 = AfD | + | |
- | </ | + | |
- | + | ||
- | Place the random generator under ** Create a Questionnaire ** on or before the first party question. | + | |
- | + | ||
- | If you are working with the placeholder '' | + | |
- | + | ||
- | <code php> | + | |
- | $name = value(' | + | |
- | replace(' | + | |
- | </ | + | |
- | + | ||
- | The questions have the labels '' | + | |
- | + | ||
- | Place the following PHP-code where the corresponding question should be asked. So if you have 9 questions per party, place the code 9 times in the first partys block and 9 times in the second partys block. In the second block '' | + | |
- | + | ||
- | === PHP-code with assembly === | + | |
- | + | ||
- | <code php> | + | |
- | $code = value(' | + | |
- | $kennung = ' | + | |
- | question($kennung); | + | |
- | </ | + | |
- | + | ||
- | === PHP-code with filters === | + | |
- | + | ||
- | <code php> | + | |
- | $code = value(' | + | |
- | if ($code == 1) { | + | |
- | question(' | + | |
- | } elseif ($code == 2) { | + | |
- | question(' | + | |
- | } elseif ($code == 3) { | + | |
- | question(' | + | |
- | } elseif ($code == 4) { | + | |
- | question(' | + | |
- | } elseif ($code == 5) { | + | |
- | question(' | + | |
- | } elseif ($code == 6) { | + | |
- | question(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Option 3 ==== | + | |
- | + | ||
- | Another option would be to place all questions to all parties in the questionnaire and to give labels to the pages (s. bellow e.g. " | + | |
- | + | ||
- | This variant is more vulnerable to errors (e.g. that somebody forgets to answer a question) and makes the questionnaire confusing. The command '' | + | |
- | + | ||
- | Due to the limited use, we only present some example PHP code on this option. If you still decide for this option, place the following PHP-code on the last page of the generic part (the part everybody has to answer the same way before the branching occurs). He will display the two party blocks separated by an intermediate part between them (" | + | |
- | + | ||
- | <code php> | + | |
- | $pages = array(); | + | |
- | // Numeric code of the first party | + | |
- | $code1 = value(' | + | |
- | // Write the fitting pages into the array | + | |
- | if ($code1 == 1) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code1 == 2) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code1 == 3) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code1 == 4) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code1 == 5) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code1 == 6) { | + | |
- | $pages[] = ' | + | |
- | } | + | |
- | // Complement the pages fort he intermediarry part | + | |
- | $pages[] = ' | + | |
- | // Numeric code of the second party | + | |
- | $code2 = value(' | + | |
- | // Write the pages for the second party into the array | + | |
- | if ($code2 == 1) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code2 == 2) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code2 == 3) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code2 == 4) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code2 == 5) { | + | |
- | $pages[] = ' | + | |
- | } elseif ($code2 == 6) { | + | |
- | $pages[] = ' | + | |
- | } | + | |
- | // Determine where it shall continue | + | |
- | $pages[] = ' | + | |
- | // Set the page order | + | |
- | setPageOrder($pages); | + | |
- | </ | + | |
- | + | ||
- | Also this PHP-code can be written more compact if the labels for the pages are " | + | |
- | + | ||
- | <code php> | + | |
- | $code1 = value(' | + | |
- | $code2 = value(' | + | |
- | setPageOrder( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ); | + | |
- | </ | + | |
- | + | ||
- | ===== Example: Varying page sequence ===== | + | |
- | The questionaire of this example belongs to the “Within-Subject” experimental design. This means the questionnaire has a generic part, followed by some pages containing the first stimulus, followed by some puffer pages and some pages with the second stimulus. The sequence of the two units of stimuli should vary randomly. | + | |
- | ==== Preperation ==== | + | |
- | * Create a new question of the „random generator“ type (in the following case the question is named ZG02). Enter the following ballots (Note that file names can deviate from case to case.) into the question: | + | |
- | < | + | |
- | 1 = experimentalgroup 1 | + | |
- | 2 = experimentalgroup 2 | + | |
- | </ | + | |
- | * Give ID’s to the pages of the questionnaire using ** Create a questionnaire** ([[: | + | |
- | * The first Page which belongs to stimulus A receives the ID “beginA”. | + | |
- | * The last Page which belongs to stimulus A receives the ID “endA”. | + | |
- | * The first Page which belongs to the puffer pages receives the ID “beginMiddle”. | + | |
- | * The last Page which belongs to the puffer pages receives the ID “endMiddle”. | + | |
- | * The first Page which belongs to stimulus B receives the ID “beginB”. | + | |
- | * The last Page which belongs to stimulus B receives the ID “endB”. | + | |
- | * The first Page of the final part (which follows directly to “endB”) receives the ID “final”. | + | |
- | + | ||
- | + | ||
- | ==== Application ==== | + | |
- | + | ||
- | Under **Create a Questionnaire** drag and drop the random generator to the last page of the generic part. The following page should respectively have the ID „beginA“. | + | |
- | + | ||
- | Place the following PHP-code beneath the random generator (s. auch [[: | + | |
- | + | ||
- | <code php> | + | |
- | $code = value(' | + | |
- | if ($code == 1) { | + | |
- | // Keeps the normal sequence – it is possible to omit this order... | + | |
- | setPageOrder(' | + | |
- | } else { | + | |
- | // Reverse sequence of the units A and B | + | |
- | setPageOrder(' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== Readjust the Drawings ===== | + | |
- | + | ||
- | If one works with many experimental groups, it is possible that the actually successful equal distribution is lost due to removals required by data cleaning. Especially if the number of cases per group is very small, the cases that have to be removed (e.g. as a result of the manipulation check) may cause a substantial tilt. Then it may be necessary to adjust the random number generator slightly during the survey. | + | |
- | + | ||
- | **Warning: | + | |
- | + | ||
- | **Tip:** In a situation where you can't adjust the random drawing afterwards, you can use an [[: | + | |
- | + | ||
- | If the conditions for readjustment (see above) are fulfilled, the procedure is as follows: | + | |
- | + | ||
- | - The preliminary | + | |
- | - A frequency table of the random generator | + | |
- This frequency table is converted into a format '' | - This frequency table is converted into a format '' | ||
- | - This list is drawn into the field // | + | - This list is entered in the random generator |
- After saving, the list is automatically sorted and further random draws are made in such a way that previous inequalities are compensated. | - After saving, the list is automatically sorted and further random draws are made in such a way that previous inequalities are compensated. | ||
- | The list of codes and usable cases can look like this: | + | For example, the list of codes and usable cases may look like the following: |
< | < | ||
Line 399: | Line 92: | ||
</ | </ | ||
- | In Excel or OpenOffice Calc, such a list is created | + | In Excel or OpenOffice Calc, you create |
<code excel> | <code excel> | ||
- | =CONCAT(A1; ": "; B1) | + | =CONCATENATE(A1; ": "; B1) |
</ | </ | ||
| | ||
- | In GNU R you can output | + | In GNU R you can output frequency table and list as follows (if the variable of the random generator is called |
<code r> | <code r> | ||
Line 411: | Line 104: | ||
cat(paste(paste(names(tmp), | cat(paste(paste(names(tmp), | ||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ |