This translation is older than the original page and might be outdated. See what has changed.
Translations of this page:
 

This is an old revision of the document!


statistic()

mixed statistic(string statistics, array|string variables, mixed option, [boolean AllData])

The statistic() function can be used to obtain univariate characteristic values from the data set (across all previous interviews).

  • Statistic\ Which statistic should be determined?
    • 'count' – Count the frequency of the value given as option.
    • 'percent' – Percentage of the value specified as Option.
    • 'frequencies' – frequencies for all response codes in the dataset (as an array).
    • 'crosscount' – Count the frequency of co-occurrence of two values in two variables. The two variables are to be specified as an array (or separated by a comma), as are their values specified as option.
    • 'mode' – most frequently occurring value.
    • 'min' – Smallest value.
    • 'max' – Largest value.
    • 'mean' – Arithmetic mean of the values.
    • 'groupmean' – Arithmetic mean of the values of a subgroup defined by Option, specified as a string consisting of variable name and code for the cases to be counted 'AB01=2'.
    • 'filter' – Specifies which cases to use in further calls to the function statistic() (see bottom for details).
  • Variables
    Specifies for which variable(s) the statistic is to be calculated. The identifiers of the individual variables can be found in the Variables overview. If the statistic requires several variables, these can be specified either as a comma-separated string or as an array.
  • Option\ Some statistics require or allow a third specification, which is given with this parameter (see below).
  • AllData
    This optional specification determines that not only the completed interviews but all interviews are included in the statistics.

Notes

Important: Only completed interviews are included in the calculation of statistical values if true is not explicitly specified for the parameter allData.

Important: Test data from questionnaire development and pretest are only counted if the current interview is also part of the test. If the interview is conducted as part of the regular data collection, statistic() only counts data from the regular data collection.

Note: The data from the current interview is not taken into account by statistic().

Note: The use of statistic() may be inefficient. If the questionnaire has to search the whole dataset several times in several statistic() calls, a warning will be displayed first. If there are more than 10 computationally intensive calls, statistic() will no longer return results. Use statistic('load', …) to load the data in advance to avoid this problem.

Tip: The function statistic() can be used to close the questionnaire after reaching a predefined quota (Quota) and either display a message to further participants 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 redirect()), it makes sense to copy the variable to be counted further back in the questionnaire into an Internal Variables.

Frequency Count I

As a third argument in a frequency count ('count'), you can specify for which value you want to determine the frequency. If you do not specify a third value, the number of valid answers is output. Missing data are not counted.

For example, if you have a selection for the gender (1=female, 2=male, -9=not specified), you can determine the number of women by specifying the third value 1:

$countWomen = statistic('count', 'SD01', 1); // frequency women (1)
$countMen = statistic('count', 'SD01', 2); // frequency men (2)
$countDone = statistic('count', 'SD01'); // number of valid dates 
$countAll = statistic('count', 'SD01', false, true); // All records 
html('
  <p>So far in this survey '.$countAll.' Persons
  have provided information about their gender, but the
  interview was completed only in '.$numberOf. Cases.</p>
  <p>The completed interviews include '.
  $countWomen.' Women and '.
  $anzahlMaenner.' Männer.</p>
');
question('SD01'); // Frage nach dem eigenen Geschlecht

Frequency Count II

The 'frequencies' statistic returns all possible values with one call.

Note: Note that the array only contains entries for the response codes whose responses are present at least once in the data set. Therefore, check whether the array key is present. This is possible, for example, with the ?? operator.

$freq = statistic('frequencies', 'SD01'); // frequencies
$numberWomen = ($freq[1] ?? 0);
$numberMen = ($freq[2] ?? 0);
html('
  <p>The completed interviews include '.
  $countWomen.' Women and '.
  $anzahlMaenner.' Männer.</p>
');
question('SD01'); // Frage nach dem eigenen Geschlecht
en/create/functions/statistic.1693939284.txt.gz · Last modified: 05.09.2023 20:41 by swissel.uni-mannheim
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki