// Numbas version: exam_results_page_options {"name": "Calculate mean, median and standard deviation for a sample", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"statement": "

A sample of 20 students were asked how many times they went to the cinema last year.

\n

Here is the list of their answers:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
{a[0]}
{a[1]}
{a[2]}
{a[3]}
{a[4]}
{a[5]}
{a[6]}
{a[7]}
{a[8]}
{a[9]}
{a[10]}
{a[11]}
{a[12]}
{a[13]}
{a[14]}
{a[15]}
{a[16]}
{a[17]}
{a[18]}
{a[19]}
", "functions": {}, "name": "Calculate mean, median and standard deviation for a sample", "parts": [{"prompt": "

Find the mean.

", "mustBeReduced": false, "mustBeReducedPC": 0, "allowFractions": false, "scripts": {}, "unitTests": [], "correctAnswerStyle": "plain", "correctAnswerFraction": false, "marks": 1, "showFeedbackIcon": true, "customMarkingAlgorithm": "", "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "maxValue": "mean", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true, "minValue": "mean", "type": "numberentry"}, {"prompt": "

Find the median.

", "mustBeReduced": false, "mustBeReducedPC": 0, "allowFractions": false, "scripts": {}, "unitTests": [], "correctAnswerStyle": "plain", "correctAnswerFraction": false, "marks": 1, "showFeedbackIcon": true, "customMarkingAlgorithm": "", "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "maxValue": "median", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true, "minValue": "median", "type": "numberentry"}, {"scripts": {}, "correctAnswerStyle": "plain", "mustBeReducedPC": 0, "unitTests": [], "precision": "2", "variableReplacements": [], "showFeedbackIcon": true, "precisionPartialCredit": 0, "showCorrectAnswer": true, "mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true, "minValue": "stdev", "precisionType": "dp", "marks": 1, "allowFractions": false, "strictPrecision": true, "precisionMessage": "You have not given your answer to the correct precision.", "correctAnswerFraction": false, "prompt": "

Find the standard deviation.

", "showPrecisionHint": true, "maxValue": "stdev", "customMarkingAlgorithm": "", "type": "numberentry", "notationStyles": ["plain", "en", "si-en"]}], "variablesTest": {"maxRuns": 100, "condition": ""}, "extensions": ["stats"], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

This question provides a sample of 20 data values and requires the calculation of mean, median, and standard deviation. The data are presented as a column so they can be easily copy-pasted into a spreadsheet.

"}, "preamble": {"js": "", "css": ""}, "advice": "

a)

\n

The mean is the sum of all the responses ($\\sum x$) divided by the number of responses ($n$).

\n

Here, $n = 20$.

\n

\\begin{align}
\\sum x &= \\var{a[0]} + \\var{a[1]} +\\var{a[2]} +\\var{a[3]} +\\var{a[4]} +\\var{a[5]} +\\var{a[6]} +\\var{a[7]} +\\var{a[8]} +\\var{a[9]} + \\var{a[10]} + \\var{a[11]} +\\var{a[12]} +\\var{a[13]} +\\var{a[14]} +\\var{a[15]} +\\var{a[16]} +\\var{a[17]} +\\var{a[18]} +\\var{a[19]} \\\\
&= \\var{sum(a)} \\text{.}
\\end{align}

\n

Therefore we calculate the mean

\n

\\begin{align}
\\overline{x} &= \\frac{\\sum x}{n} \\\\[0.5em]
&= \\frac{\\var{sum(a)}}{20} \\\\[0.5em]
&= \\var{mean} \\text{.}
\\end{align}

\n

 

\n

b)

\n

The median is the middle value. We need to sort the list in order:

\n

\\[ \\var{as[0]}, \\quad \\var{as[1]}, \\quad \\var{as[2]}, \\quad \\var{as[3]}, \\quad \\var{as[4]}, \\quad \\var{as[5]}, \\quad \\var{as[6]}, \\quad \\var{as[7]}, \\quad \\var{as[8]}, \\quad \\var{as[9]}, \\quad \\var{as[10]}, \\quad \\var{as[11]}, \\quad \\var{as[12]}, \\quad \\var{as[13]}, \\quad \\var{as[14]}, \\quad \\var{as[15]}, \\quad \\var{as[16]}, \\quad \\var{as[17]}, \\quad \\var{as[18]}, \\quad \\var{as[19]} \\]

\n

There is an even number of responses, so there are two numbers in the middle (10th and 11th place). To find the median, we need to find the mean of these two numbers $\\var{as[9]}$ and $\\var{as[10]}$:

\n

\\begin{align}
\\frac{\\var{as[9]} + \\var{as[10]}}{2} &=  \\frac{\\var{as[9] + as[10]}}{2} \\\\
&= \\var{median} \\text{.} 
\\end{align}

\n

 

\n

c)

\n

The mode is the value that occurs the most often in the data.

\n

To find a mode, we can look at our sorted list:

\n

$\\var{as[0]}, \\var{as[1]}, \\var{as[2]}, \\var{as[3]}, \\var{as[4]}, \\var{as[5]}, \\var{as[6]}, \\var{as[7]}, \\var{as[8]}, \\var{as[9]}, \\var{as[10]}, \\var{as[11]}, \\var{as[12]}, \\var{as[13]}, \\var{as[14]}, \\var{as[15]}, \\var{as[16]}, \\var{as[17]}, \\var{as[18]}, \\var{as[19]}$.

\n

We notice that $\\var{mode1}$ occurs the most ($\\var{modetimes[mode1]}$ times) so $\\var{mode1}$ is the mode.

\n

 

\n

d)

\n

Range is the difference between the highest and the lowest value in the data.

\n

To find this, we subtract the lowest value from the highest value:

\n

\\[ \\var{max(a)} - \\var{min(a)} = \\var{range} \\text{.}\\]

", "variables": {"as": {"templateType": "anything", "description": "

Sorted list.

", "group": "final list", "definition": "sort(a)", "name": "as"}, "mode": {"templateType": "anything", "description": "

Mode as a vector.

", "group": "final list", "definition": "mode(a)", "name": "mode"}, "range": {"templateType": "anything", "description": "", "group": "final list", "definition": "max(a) - min(a)", "name": "range"}, "modea2": {"templateType": "anything", "description": "", "group": "Ungrouped variables", "definition": "mode(a2)", "name": "modea2"}, "a1": {"templateType": "anything", "description": "

Option 1 for the list. Only used if there is only one mode.

", "group": "Ungrouped variables", "definition": "repeat(random(0..8), 20)", "name": "a1"}, "a": {"templateType": "anything", "description": "

The final list.

", "group": "final list", "definition": "if(len(modea1) = 1, a1, if(len(modea2) = 1, a2, a3))", "name": "a"}, "modetimes": {"templateType": "anything", "description": "

The vector of number of times of each value in the data.

", "group": "final list", "definition": "map(\nlen(filter(x=j,x,a)),\nj, 0..8)", "name": "modetimes"}, "mode1": {"templateType": "anything", "description": "

Mode as a value.

", "group": "final list", "definition": "mode[0]", "name": "mode1"}, "a3": {"templateType": "anything", "description": "

Option 3 for the list. Ensures there is only one mode (2) while still randomising the data.

", "group": "Ungrouped variables", "definition": "shuffle([ random(0..1),\n 2, \n random(4..6),\n random(0..3 except 2), \n random(0..3 except 2),\n random(4..6),\n 2,\n 2,\n random(4..6),\n random(7..8),\n random(0..3 except 2 except 1), \n random(4..6),\n 2,\n random(1..3 except 2), \n random(7..8),\n 2,\n random(7..8),\n random(4..6), \n random(0..3 except 2), \n 2\n])", "name": "a3"}, "median": {"templateType": "anything", "description": "", "group": "final list", "definition": "median(a)", "name": "median"}, "mean": {"templateType": "anything", "description": "", "group": "final list", "definition": "mean(a)", "name": "mean"}, "modea1": {"templateType": "anything", "description": "", "group": "Ungrouped variables", "definition": "mode(a1)", "name": "modea1"}, "stdev": {"templateType": "anything", "description": "", "group": "final list", "definition": "stdev(a,true)", "name": "stdev"}, "a2": {"templateType": "anything", "description": "

Option 2 for the list. Only used if there is only one mode and option 1 was not used.

", "group": "Ungrouped variables", "definition": "repeat(random(0..8), 20)", "name": "a2"}}, "variable_groups": [{"variables": ["a", "as", "mean", "median", "mode", "mode1", "range", "modetimes", "stdev"], "name": "final list"}], "ungrouped_variables": ["modea1", "modea2", "a1", "a2", "a3"], "tags": [], "rulesets": {}, "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Mario Orsi", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/427/"}, {"name": "Stanislav Duris", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1590/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Mario Orsi", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/427/"}, {"name": "Stanislav Duris", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1590/"}]}