// Numbas version: finer_feedback_settings {"name": "Brad's copy of Perform chi-squared test for differences in preferences", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"metadata": {"description": "

Uses the $\\chi^2$ test to see if there is any significant difference in preferences.

", "licence": "Creative Commons Attribution 4.0 International"}, "advice": "\n

Step 3

\n

 

\n

Completing the table we have $E= \\var{t}/5=\\var{t/5}$ for all brands.

\n

We do the last column calculations for brand A.

\n

$\\displaystyle \\frac{(O -E) ^ 2}{ E} = \\frac{(\\var{a} -\\var{e1}) ^ 2} {\\var{e1}} = \\var{x[0]}$

\n

to 2 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 \n \n \n \n \n \n \n
 $O$$E$$\\displaystyle \\frac{(O-E)^2}{E}$
A$\\var{a}$$\\var{e1}$$\\var{x[0]}$
B$\\var{b}$$\\var{e1}$$\\var{x[1]}$
C$\\var{c}$$\\var{e1}$$\\var{x[2]}$
D$\\var{d}$$\\var{e1}$$\\var{x[3]}$
E$\\var{f}$$\\var{e1}$$\\var{x[4]}$
   $\\chi^2=\\;\\var{chi}$
\n

The test statistic is then:

\n

\\[\\displaystyle \\chi ^ 2 = \\sum \\frac{(O -E)^2}{E} = \\var{x[0]} + \\var{x[1]} + \\var{x[2]} + \\var{x[3]} + \\var{x[4]} = \\var{chi}\\]

\n

Step 4:

\n

The degrees of freedom is given by: $\\nu$= no. of categories $- 1 = 5-1=4$

\n

The following are the critical values for $\\nu=4$.

\n

{table1([['Critical Value',{crit[0]},{crit[1]},{crit[2]}]],['p-value','10%','5%','1%'],false,false,false,false)}

\n

Looking at this test statistic we see that the p-range {choices[pval]}.

\n

The conclusion we come to is that {correctc} Hence {correcth}

\n ", "extensions": ["stats"], "preamble": {"js": "", "css": ""}, "statement": "

Some marketing research studies indicate the \"positive impact of store brand penetration on store profitability as measured by market share\" (Lal,M.C.(2000). Building Store Loyalty Through Store Brands, Journal of Marketing Research, 37, no. 3, pp281). 

\n

The manager of a local supermarket that sells four national brands (A, B, C and D) and one store brand (E) of {this} wants to find out whether or not customers have a preference for a particular brand. Over the course of a {thislong}, the number of customers buying each brand of {this} was noted; the results are shown in the table below:

\n

{table1([['A',{a}],['B',{b}],['C',{c}],['D',{d}],['E',{f}]],['Brand','No. of Customers'],true,false,false,true)}

\n

Test the null hypothesis that, in fact, customers at this supermarket do not have a preference for a particular brand of {this}.

\n

 

", "variables": {"choices": {"definition": "['is greater than $10$%','lies between $10$% and $5$%','lies between $5$% and $1$%','is smaller than $1$%']", "name": "choices", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "mm": {"definition": "switch(pval=0,[1,0,0,0],pval=1,[0,1,0,0],pval=2,[0,0,1,0],[0,0,0,1])", "name": "mm", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "w": {"definition": "random(1,-1)", "name": "w", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "pval": {"definition": "switch(chi1,\"there is evidence to suggest that customers have a preference between the brands.\",\"there is no evidence to suggest that customers have a preference between the brands.\")", "name": "correctc", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "dh": {"definition": "['Retain','Reject']", "name": "dh", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "c": {"definition": "random(50..69)", "name": "c", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "dmm": {"definition": "if(pval < 2,[1,0],[0,1])", "name": "dmm", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "correcth": {"definition": "if(pval>1,\"we reject the null hypothesis.\",\"we retain the null hypothesis. \")", "name": "correcth", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "a": {"definition": "random(60..90)", "name": "a", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "e1": {"definition": "t/5", "name": "e1", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "n": {"definition": "5", "name": "n", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "chi": {"definition": "sum(x)", "name": "chi", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "b": {"definition": "random(60..90)", "name": "b", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "x": {"definition": "map(precround((5*y-t)^2/(5*t),2),y,[a,b,c,d,f])", "name": "x", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "thislong": {"definition": "random(\"month\",\"week\",\"fortnight\")", "name": "thislong", "templateType": "anything", "description": "", "group": "Ungrouped variables"}, "f": {"definition": "a+w*random(10..15)", "name": "f", "templateType": "anything", "description": "", "group": "Ungrouped variables"}}, "functions": {"table2": {"type": "html", "parameters": [["data", "list"], ["headers", "list"], ["rtot", "boolean"], ["ctot", "boolean"]], "definition": "\n /* create table element */\n var table = $('
');\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(record[j])); \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 ", "language": "javascript"}, "tableformat": {"type": "html", "parameters": [["table", "html"], ["data", "list"], ["c", "boolean"], ["r", "boolean"], ["rtot", "boolean"], ["ctot", "boolean"]], "definition": "\n if(c){table.find('td').css('border-right','1px solid').css('border-left','1px solid');}\n \n if(r){table.find('td').css('border-bottom','1px solid');}\n /* Put a border below the headers */\n table.find('thead').css('border-bottom','1px solid');\n /*if row totals, then split off via gridlines*/\n if(rtot){table.find('tr').find('td:last').css('border-right','1px solid').css('border-left','1px solid');}\n \n /* put a border on the right and left of the first column, assuming there are row labels. */\n table.find('tr').find('td:first').css('border-right','1px solid').css('border-left','1px solid'); \n table.find('tr').find('td:last').css('border-right','1px solid'); \n /*make sure there is a border at the bottom*/\n table.find('tr:last').css('border-bottom','1px solid'); \n \n return table;\n \n \n ", "language": "javascript"}, "table1": {"type": "html", "parameters": [["data", "list"], ["headers", "list"], ["c", "boolean"], ["r", "boolean"], ["rtot", "boolean"], ["ctot", "boolean"]], "definition": "tableformat(table2(data,headers,rtot,ctot),data,c,r,rtot,ctot)", "language": "jme"}}, "name": "Brad's copy of Perform chi-squared test for differences in preferences", "tags": [], "rulesets": {}, "ungrouped_variables": ["pval", "crit", "n", "chi", "tol", "correctc", "dh", "correcth", "fac", "e1", "a", "evi", "c", "b", "d", "f", "mm", "dmm", "thislong", "choices", "this", "t", "w", "v", "x"], "parts": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "customName": "", "unitTests": [], "prompt": "\n

Step 1: Null hypothesis

\n

$\\operatorname{H}_0:\\;$ Customers do not have a preference for a particular brand of {this}.

\n

Step 2: Alternative hypothesis

\n

$\\operatorname{H}_1:\\;$ Customers do have a preference for a particular brand of {this}.

\n

 

\n ", "type": "information", "scripts": {}, "customMarkingAlgorithm": "", "showFeedbackIcon": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "showCorrectAnswer": true}, {"sortAnswers": false, "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "customName": "", "unitTests": [], "prompt": "\n

Step 3: Test statistic

\n

Complete the following table: (input all values in the  expected column $E$  as exact decimals and input in the last column to 2 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 \n \n
 $O$$E$$\\displaystyle \\frac{(O-E)^2}{E}$
A$\\var{a}$[[0]][[1]]
B$\\var{b}$[[2]][[3]]
C$\\var{c}$[[4]][[5]]
D$\\var{d}$[[6]][[7]]
E$\\var{f}$[[8]][[9]]
\n

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

\n

Input  the test statistic to 2 decimal places.

\n ", "type": "gapfill", "scripts": {}, "customMarkingAlgorithm": "", "gaps": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "e1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "e1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.2, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "x[0]-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "x[0]+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.6, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "e1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "e1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.2, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "x[1]-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "x[1]+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.6, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "e1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "e1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.2, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "x[2]-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "x[2]+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.6, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "e1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "e1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.2, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "x[3]-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "x[3]+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.6, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "e1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "e1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.2, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "x[4]-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "x[4]+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0.6, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "chi-tol", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "chi+tol", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 1, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}], "showFeedbackIcon": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "showCorrectAnswer": true}, {"sortAnswers": false, "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "customName": "", "unitTests": [], "prompt": "\n

Step 4:  p-value range

\n

Calculate , the degrees of freedom, for this test: $\\nu=\\;?$[[0]]

\n

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

\n

[[1]]

\n ", "type": "gapfill", "scripts": {}, "customMarkingAlgorithm": "", "gaps": [{"variableReplacements": [], "extendBaseMarkingAlgorithm": true, "minValue": "n-1", "customName": "", "unitTests": [], "correctAnswerStyle": "plain", "type": "numberentry", "correctAnswerFraction": false, "scripts": {}, "customMarkingAlgorithm": "", "maxValue": "n-1", "mustBeReduced": false, "mustBeReducedPC": 0, "showFeedbackIcon": true, "showFractionHint": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 1, "notationStyles": ["plain", "en", "si-en"], "showCorrectAnswer": true, "allowFractions": false}, {"minMarks": 0, "choices": ["{choices[0]}", "{choices[1]}", "{choices[2]}", "{choices[3]}"], "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "shuffleChoices": false, "customName": "", "unitTests": [], "type": "1_n_2", "scripts": {}, "customMarkingAlgorithm": "", "matrix": "mm", "displayType": "radiogroup", "showCellAnswerState": true, "showFeedbackIcon": true, "maxMarks": 0, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "displayColumns": 0, "showCorrectAnswer": true}], "showFeedbackIcon": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "showCorrectAnswer": true}, {"sortAnswers": false, "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "customName": "", "unitTests": [], "prompt": "\n

Step 5: Conclusion

\n

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

\n

[[0]]

\n

Your Decision in relation to the null hypothesis:

\n

[[1]]

\n

Conclusion:

\n

 [[2]]

\n ", "type": "gapfill", "scripts": {}, "customMarkingAlgorithm": "", "gaps": [{"minMarks": 0, "choices": ["{evi[0]}", "{evi[1]}", "{evi[2]}", "{evi[3]}"], "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "shuffleChoices": false, "customName": "", "unitTests": [], "type": "1_n_2", "scripts": {}, "customMarkingAlgorithm": "", "matrix": "mm", "displayType": "radiogroup", "showCellAnswerState": true, "showFeedbackIcon": true, "maxMarks": 0, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "displayColumns": 0, "showCorrectAnswer": true}, {"minMarks": 0, "choices": ["Retain", "Reject"], "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "shuffleChoices": false, "customName": "", "unitTests": [], "type": "1_n_2", "scripts": {}, "customMarkingAlgorithm": "", "matrix": "dmm", "displayType": "radiogroup", "showCellAnswerState": true, "showFeedbackIcon": true, "maxMarks": 0, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "displayColumns": 0, "showCorrectAnswer": true}, {"minMarks": 0, "choices": ["{fac}", "{correctc}"], "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "shuffleChoices": true, "customName": "", "unitTests": [], "type": "1_n_2", "scripts": {}, "customMarkingAlgorithm": "", "matrix": [0, 1], "displayType": "radiogroup", "showCellAnswerState": true, "showFeedbackIcon": true, "maxMarks": 0, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "displayColumns": 0, "distractors": ["", ""], "showCorrectAnswer": true}], "showFeedbackIcon": true, "useCustomName": false, "variableReplacementStrategy": "originalfirst", "marks": 0, "showCorrectAnswer": true}], "variablesTest": {"condition": "", "maxRuns": 100}, "variable_groups": [], "type": "question", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Brad Allison", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3394/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Brad Allison", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3394/"}]}