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:functions:statistic [29.09.2020 17:55] – [statistic()] sophia.schaueren:create:functions:statistic [29.09.2020 18:13] sophia.schauer
Line 15: Line 15:
     * '''mean''' -- arithmetic mean of the values.     * '''mean''' -- arithmetic mean of the values.
     * '''groupmean''' -- Arithmetic mean of the values of a subgroup defined by //Option//, specified as Sting consisting of variable name and code for the cases to be counted '''AB01=2'''.     * '''groupmean''' -- Arithmetic mean of the values of a subgroup defined by //Option//, specified as Sting consisting of variable name and code for the cases to be counted '''AB01=2'''.
-    * '''filter''' -- Determines which cases should be used for further calls to the ''statistic()'' function (for details see [[#partial_evaluate_sets|down]]). xx!!+    * '''filter''' -- Determines which cases should be used for further calls to the ''statistic()'' function (for details see [[#evaluate_partial_data_sets|down]]). xx!!
  
   * //variables//\\ Determines which variable(s) the statistic should be calculated for. The IDs of the individual variables can be found in the **Variables Overview**. If the statistic requires multiple variables, these can be given as a comma-separated string or as an array.   * //variables//\\ Determines which variable(s) the statistic should be calculated for. The IDs of the individual variables can be found in the **Variables Overview**. If the statistic requires multiple variables, these can be given as a comma-separated string or as an array.
Line 25: Line 25:
 **Note:** Test data collected during the developing of the questionnaire and pretesting is only included if the current questionnaire is a part of the test as well. If the questionnaire is being carried out as part of the regular data collection, ''statistic()'' only counts data from the regular data collection. **Note:** Test data collected during the developing of the questionnaire and pretesting is only included if the current questionnaire is a part of the test as well. If the questionnaire is being carried out as part of the regular data collection, ''statistic()'' only counts data from the regular data collection.
  
 +**Note:** The data from the current interview are not considered by ''statistic()''.
 +
 +**Tip:** The function ''statistic()'' can be used to close the questionnaire after reaching a predefined quota ([[:en:survey:quota]]) and either display a message to further respondents or redirect them to the quota stop link of a panel provider.
 +
 +**Tip:** If you do not want to count all completed interviews (e.g. if dropouts were redirected to another page using ''[[:en:create:functions:redirect]]''), it makes sense to copy the variable to be counted to a [[:en:create:questions:internal]] further back in the questionnaire.
  
 ===== Frequency Count ===== ===== Frequency Count =====
Line 121: Line 126:
   <p>The ratings lie between '.$min.' und '.$max.'.</p>   <p>The ratings lie between '.$min.' und '.$max.'.</p>
 '); ');
 +</code>
 +
 +===== Evaluate partial data sets =====
 +
 +By using ''statistic('filter', ...)'' a filter can be set, which will be applied for all further calls of ''statistic()'' The second parameter can be //variables// for acceleration (optional), which are needed in subsequent calls.
 +
 +The number of cases matching the filter is returned. The fourth parameter //AllData// only affects the return value, but not the further counting.
 +
 +<code php>
 +// Statistics on female respondents only (SD02 = 1)
 +// RT variables are loaded immediately to reduce latency 
 +$n = statistic('filter', array('RT02_01', 'RT02_02', 'RT02_03'), 'SD02==1');
 +// Mean value of ratings (women only)
 +$mean1 = statistic('mean', 'RT02_01');
 +$mean2 = statistic('mean', 'RT02_02');
 +$mean3 = statistic('mean', 'RT02_03');
 +</code>
 +
 +The filter allows common comparison operators (''>'', ''>='', ''<'', ''%%<=%%'', ''!='', ''==''), brackets and and Boolean operators (''AND'', ''&&'', ''OR'', ''||'', ''NOT'', ''!'').
 +
 +**Note:** Comparisons are only possible between one variable and a constant value (a number or string), e.g. ''SD02==2'', comparisons between two variables (''SD03>SD04'') are not supported.
 +
 +<code php>
 +// Statistics only on female respondents (SD02 = 1) aged 35 and over (SD03 >= 35)
 +$n = statistic('filter', false, '(SD02==1) AND (SD03 >= 35)');
 +</code>
 +
 +Besides the variable names you can also use ''QUESTNNR'', ''CASE'' and ''LANGUAGE'' for the filter.
 +
 +<code php>
 +// Statistics only on female respondents (SD02 = 1) aged 35 and over (SD03 >= 35) in the German language version
 +$n = statistic('filter', false, '(SD02==1) AND (SD03 >= 35) AND (LANGUAGE == "ger")');
 </code> </code>
en/create/functions/statistic.txt · Last modified: 03.05.2024 09:21 by jdupont
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki