Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
en:create:functions:statistic [02.12.2014 23:02] – alexander.ritter | en:create:functions:statistic [29.09.2020 18:13] – sophia.schauer |
---|
''mixed **statistic**(string //statistic//, array|string //variables//, mixed //option//, [boolean //alldata//])'' | ''mixed **statistic**(string //statistic//, array|string //variables//, mixed //option//, [boolean //alldata//])'' |
| |
The function statistic() can determine specific univariate data from the data record (across all previous interviews). | The function statistic() can determine specific univariate data from the data record (across all previous questionnaires). |
| |
| |
* '''max''' -- highest value. | * '''max''' -- highest value. |
* '''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'''. |
| * '''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. |
* //option//\\ Some statistics call for or allow a third entry which is set with this parameter (see below). | * //option//\\ Some statistics call for or allow a third entry which is set with this parameter (see below). |
* //alldata//\\ This entry is optional and determines that all interviews be entered into the statistics; not just those that have been completed. | * //alldata//\\ This entry is optional and determines that all questionnaires be entered into the statistics; not just those that have been completed. |
| |
| **Note:** If ''true'' is not explicitly specified for the parameter //alldata//, only completed questionnaires are included when calculating the statistical values. |
| |
| **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:** If ''true'' is not explicitly specified for the parameter //alldata//, only completed interviews are included when calculating the statistical values. | **Note:** The data from the current interview are not considered by ''statistic()''. |
| |
**Note:** Test data collected during the developing of the questionnaire and pretesting is only included if the current interview is a part of the test as well. If the interview is being carried out as part of the regular data collection, ''statistic()'' only counts data from the regular data collection. | **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 ===== |
html(' | html(' |
<p>So far,'.$numberall.' people | <p>So far,'.$numberall.' people |
specified their gender in this survey, but the interview was | specified their gender in this survey, but the questionnaire was |
only completed in '.$numbercompleted.' cases.</p> | only completed in '.$numbercompleted.' cases.</p> |
<p>The completed interviews are made up of '. | <p>The questionnaires completed are made up of '. |
$numberwomen.' women and '. | $numberwomen.' women and '. |
$numbermen.' men.</p> | $numbermen.' men.</p> |
} else { | } else { |
// answer options text (statistic() only provides the numeric code) | // answer options text (statistic() only provides the numeric code) |
$text = getValuetext('AB01_02', $mode); | $text = getValueText('AB01_02', $mode); |
html(' | html(' |
<p>The most common answer for this question was: '.$text.'.</p> | <p>The most common answer for this question was: '.$text.'.</p> |
<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> |