// Numbas version: finer_feedback_settings {"name": "Perform chi-squared test to see if data follows Poisson distribution", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [], "variables": {"ex5": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(x5*thismany,2)", "description": "", "name": "ex5"}, "few1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(few=3,\"two\",\" \")", "description": "", "name": "few1"}, "thismany": {"templateType": "anything", "group": "Ungrouped variables", "definition": "a+b+c+d+f+t", "description": "", "name": "thismany"}, "f1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "m*random(0.6..1.6#0.05)", "description": "", "name": "f1"}, "ch99": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(few=2,11.34,9.21)", "description": "", "name": "ch99"}, "cat": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(few=3,\"categories\",\"category\")", "description": "", "name": "cat"}, "x5": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(1-sum(x),3)", "description": "", "name": "x5"}, "pval": {"templateType": "anything", "group": "Ungrouped variables", "definition": "switch(ch');\n /* add headers */\n for(var i=0;i').html(headers[i]));\n }\n if(rtot){ table.find('thead').append('Totals');}\n \n /*for each record in data, add a row to the table*/\n for(var i=0;i');\n var record = data[i];\n var s=0;\n for(var j=0;j').html(cell)); \n }\n for(var j=1;j').html(s));}\n table.find('tbody').append(row);\n }\n \n /* this function adds a row of totals to the bottom of the table created by the `table` function */\n \n /* compute the totals */\n var row = $('');\n var ctotals=[];\n for(var i=0;iTotals');\n var s=0;\n for(var j=1;j').html(ctotals[j]);\n s+=ctotals[j];\n row.append(cell);\n }\n if(rtot){cell= $('').html(s); row.append(cell);}\n /* add a border to the top and bottom of the totals row */\n row.css('border-top','1px solid');\n row.css('border-bottom','1px solid');\n /* add the totals row to the table */\n table.find('tbody').append(row);\n }\n return table;\n \n \n ", "parameters": [["data", "list"], ["headers", "list"], ["rtot", "boolean"], ["ctot", "boolean"]]}}, "showQuestionGroupNames": false, "parts": [{"type": "information", "prompt": "\n

Step 1: Null hypothesis

\n

$\\operatorname{H}_0$: The number of calls per minute follows a Poisson distribution.

\n

Step 2: Alternative hypothesis

\n

$\\operatorname{H}_1$: The number of calls per minute does not follow a Poisson distribution.

\n ", "showCorrectAnswer": true, "scripts": {}, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "v", "minValue": "v", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x[0]+tol1", "minValue": "x[0]-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x[1]+tol1", "minValue": "x[1]-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x[2]+tol1", "minValue": "x[2]-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x[3]+tol1", "minValue": "x[3]-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x[4]+tol1", "minValue": "x[4]-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "x5+tol1", "minValue": "x5-tol1", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex[0]+tol", "minValue": "ex[0]-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex[1]+tol", "minValue": "ex[1]-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex[2]+tol", "minValue": "ex[2]-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex[3]+tol", "minValue": "ex[3]-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex[4]+tol", "minValue": "ex[4]-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ex5+tol", "minValue": "ex5-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "few", "minValue": "few", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ch+tol", "minValue": "ch-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}], "type": "gapfill", "prompt": "\n

Step 3: Test statistic

\n

(a) Calculate the Poisson rate parameter to 2 decimal places  

\n

$\\lambda=\\;$?[[0]]

\n

(b) Calculate the Poisson probabilities for each category using the value for $\\lambda$  you have just calculated.

\n

Calculate all probabilities to 3 decimal places.

\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
$P(X=0)$[[1]]
$P(X=1)$[[2]]
$P(X=2)$[[3]]
$P(X=3)$[[4]]
$P(X=4)$[[5]]
$P(X \\gt 4)$[[6]]
\n

 

\n

(Calculate $P(X \\gt 4)$ as $1-P(X=0)-P(X=1)-P(X=2)-P(X=3) - P(X=4)$  using the probabilities you have found).

\n

c) Calculate the expected frequencies to 2 decimal places using the probabilities you have just calculated.

\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
Observed FrequenciesExpected Frequencies
$\\var{a}$[[7]]
$\\var{b}$[[8]]
$\\var{c}$[[9]]
$\\var{d}$[[10]]
$\\var{f}$[[11]]
$\\var{t}$[[12]]
\n

How many categories need to be pooled to make sure that the expected frequency for each category is $\\geq 5$  ?  [[13]]

\n

Hence the test statistic is: $\\chi^2=\\;$?[[14]]

\n

Input the test statistic to 2 decimal places.

\n ", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "5-{few}", "minValue": "5-{few}", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"displayType": "radiogroup", "choices": ["

$p$ is bigger than $10 \\%$

", "

$p$ lies between $10 \\%$ and $5 \\%$

", "

$p$ lies between $5 \\%$ and $1 \\%$

", "

$p$ is less than $1 \\%$

"], "displayColumns": 0, "distractors": ["", "", "", ""], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "matrix": "Mm", "marks": 0}], "type": "gapfill", "prompt": "\n

Step 4:  p-value range

\n

After pooling, calculate , the degrees of freedom, for this test: . 

\n

$\\nu =\\;$?[[0]]

\n

Use tables to find a range for your -value.  Choose the correct choice below. 

\n

[[1]]

\n

 

\n ", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"displayType": "radiogroup", "choices": ["None", "Slight", "Moderate", "Strong"], "displayColumns": 0, "distractors": ["", "", "", ""], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "matrix": "Mm", "marks": 0}, {"displayType": "radiogroup", "choices": ["Retain $\\operatorname{H}_0$", "Reject $\\operatorname{H}_0$"], "displayColumns": 0, "distractors": ["", ""], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "matrix": "Mc", "marks": 0}, {"displayType": "radiogroup", "choices": ["No evidence to suggest that the number of calls does not follow a Poisson distribution", "There is evidence to suggest that the number of calls does not follow a Poisson distribution"], "displayColumns": 0, "distractors": ["", ""], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "matrix": "Mc", "marks": 0}], "type": "gapfill", "prompt": "\n

Step 5: Conclusion

\n

 

\n

Given the  $p$- value and the range you have found what is the strength of evidence against the null hypothesis?

\n

[[0]]

\n

Your Decision:

\n

 [[1]]

\n

Conclusion:

\n

 [[2]]

\n ", "showCorrectAnswer": true, "marks": 0}], "statement": "

You are employed as a business analyst for the NHS European Health Insurance Card (EHIC) division.

\n

Before launching a new automatic telephone application system, you are required to find out whether the number of calls made to the department, per minute, follows a Poisson distribution. 

\n

Over a period of {thismany} minutes, the following information was obtained:

\n

{table1([['0',{a}],['1',{b}],['2',{c}],['3',{d}],['4',{f}],['5+',{t}]],['No. of Calls (X)','Frequency per minute'],true,true,false,false)}

", "tags": ["checked2015", "MAS1403"], "rulesets": {}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "", "licence": "Creative Commons Attribution 4.0 International", "description": "

Find out whether the data presented in this question follows a Poisson distribution. Uses the $\\chi^2$ test.

"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "

Step 3.

\n

a) $\\lambda$  is the mean of the data i.e.

\n

\\[\\lambda = \\frac{0 \\times \\var{a}+1\\times \\var{b}+2\\times\\var{c}+3\\times\\var{d}+4\\times\\var{f}+5\\times \\var{t}}{\\var{thismany}} = \\var{v}\\] to 2 decimal places.

\n

b) This is the value of $\\lambda$ we use to calculate the probabilities, to 3 decimal places,  assuming that the data is from a Poisson distribution with this parameter.

\n

For example, $ \\displaystyle P(X=2)=\\frac{e^{-\\lambda}\\lambda^2}{2!}=\\frac{e^{-\\var{v}}\\times \\var{v}^2}{2}=\\var{x[2]}$

\n

to 3 decimal places.

\n

The next table shows the values to 3 decimal places you should have obtained:

\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
$P(X=0)$$\\var{x[0]}$
$P(X=1)$$\\var{x[1]}$
$P(X=2)$$\\var{x[2]}$
$P(X=3)$$\\var{x[3]}$
$P(X=4)$$\\var{x[4]}$
$P(X \\gt 4)$$\\var{x5}$
\n

c) Using this probability then the expected number of occurences of 2 calls in a minute is \\[P(X=2) \\times \\var{thismany} = \\var{x[2]}\\times \\var{thismany}=\\var{ex[2]}\\]  to 2 decimal places.

\n

In the same way we find all the expected frequencies assuming that it is a Poisson distribution with parameter $\\lambda=\\var{v}$.

\n

The following table shows the actual observed frequencies and the expected frequencies, to 2 decimal places, under this assumption.

\n

{table1([[{a},{ex[0]}],[{b},{ex[1]}],[{c},{ex[2]}],[{d},{ex[3]}],[{f},{ex[4]}],[{t},{ex5}]],['No. of Calls (X) Observed','Expected Frequency '],true,true,false,false)}

\n

The expected frequencies in the last {few} categories need to be pooled as the {sumofthe}  expected {freq} for the last {few1} {cat} is less than 5.

\n

Hence we obtain the following table used to calculate the test statistic:

\n

{table1([[{a},{ex[0]}],[{b},{ex[1]}],[{c},{ex[2]}],[{dp},{ep4}],[{fq},{eq5}]],['No. of Calls (X) Observed','Expected Frequency '],true,true,false,false)}

\n

We now use the last table to calculate the $\\chi^2$ statistic to see if there is a reasonable match between the observed and expected frequencies. 

\n

We have:

\n

\\[\\chi ^ 2 = \\simplify[all,!collectNumbers]{({a} -{ex[0]}) ^ 2 / {ex[0]} + ({b} -{ex[1]}) ^ 2 / {ex[1]} + ({c} -{ex[2]}) ^ 2 / {ex[2]} + ({dp} -{ep4}) ^ 2 / {ep4} + {z} * (({fp} -{ep5}) ^ 2 / {ep5}) = {ch}}\\] to 2 decimal places.

\n

Step 4:

\n

The degrees of freedom is given by:  $\\nu=\\;$no. of pooled categories $- 2 =\\var{6-few+1}-2=\\var{5-few}$

\n

(We have to take away $2$ from the number of pooled categories as we have estimated the parameter $\\lambda$ .)

\n

The following are the critical values for $\\nu=\\var{5-few}$:

\n

{table1([['Critical Value',{ch90},{ch95},{ch99}]],['p-Value','10%','5%','1%'],false,false,false,false)}

\n

Comparing these values with the the test statistic we see that the  $p$-value {Correct}.

\n

Step 5: Conclusion

\n

Hence there is {evi[pval]} evidence against and so we {cho} the null hypothesis that the number of calls per minute follows a Poisson distribution.

\n

 

\n

 

", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}