// Numbas version: finer_feedback_settings {"name": "Perform a paired t-test", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Perform a paired t-test", "tags": [], "metadata": {"description": "
Paired t-test to see if there is a difference between times taken to complete a task.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "The following data was obtained from $\\var{n}$ right-handed participants. The observations consist of the time taken in seconds for each participant to complete a dexterity task by firstly using their right hand and secondly using their left hand.
\n| {object} | \nA | \nB | \nC | \nD | \nE | \nF | \nG | \nH | \nI | \nJ | \nK | \nL | \n
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Right hand | \n$\\var{r1[0]}$ | \n$\\var{r1[1]}$ | \n$\\var{r1[2]}$ | \n$\\var{r1[3]}$ | \n$\\var{r1[4]}$ | \n$\\var{r1[5]}$ | \n$\\var{r1[6]}$ | \n$\\var{r1[7]}$ | \n$\\var{r1[8]}$ | \n$\\var{r1[9]}$ | \n$\\var{r1[10]}$ | \n$\\var{r1[11]}$ | \n
| Left hand | \n$\\var{r2[0]}$ | \n$\\var{r2[1]}$ | \n$\\var{r2[2]}$ | \n$\\var{r2[3]}$ | \n$\\var{r2[4]}$ | \n$\\var{r2[5]}$ | \n$\\var{r2[6]}$ | \n$\\var{r2[7]}$ | \n$\\var{r2[8]}$ | \n$\\var{r2[9]}$ | \n$\\var{r2[10]}$ | \n$\\var{r2[11]}$ | \n
Carry out a paired $t$-test to test whether there is evidence of a difference in the average times to complete the task for the left and right hands.
", "advice": "The table of differences is given by:
\n| {object} | \nA | \nB | \nC | \nD | \nE | \nF | \nG | \nH | \nI | \nJ | \nK | \nL | \n
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Right | \n$\\var{r1[0]}$ | \n$\\var{r1[1]}$ | \n$\\var{r1[2]}$ | \n$\\var{r1[3]}$ | \n$\\var{r1[4]}$ | \n$\\var{r1[5]}$ | \n$\\var{r1[6]}$ | \n$\\var{r1[7]}$ | \n$\\var{r1[8]}$ | \n$\\var{r1[9]}$ | \n$\\var{r1[10]}$ | \n$\\var{r1[11]}$ | \n
| Left | \n$\\var{r2[0]}$ | \n$\\var{r2[1]}$ | \n$\\var{r2[2]}$ | \n$\\var{r2[3]}$ | \n$\\var{r2[4]}$ | \n$\\var{r2[5]}$ | \n$\\var{r2[6]}$ | \n$\\var{r2[7]}$ | \n$\\var{r2[8]}$ | \n$\\var{r2[9]}$ | \n$\\var{r2[10]}$ | \n$\\var{r2[11]}$ | \n
| Differences $(d_i)$ | \n$\\var{d[0]}$ | \n$\\var{d[1]}$ | \n$\\var{d[2]}$ | \n$\\var{d[3]}$ | \n$\\var{d[4]}$ | \n$\\var{d[5]}$ | \n$\\var{d[6]}$ | \n$\\var{d[7]}$ | \n$\\var{d[8]}$ | \n$\\var{d[9]}$ | \n$\\var{d[10]}$ | \n$\\var{d[11]}$ | \n
We test the following hypothesis:
\n$H_0:\\;\\mu_d=0$
\n$H_1:\\;\\mu_d\\neq 0$
\nThe mean of the differences is given by
\n\\begin{align}
\\bar{x}_d
&= \\frac{\\sum{d_i}}{n} \\\\
&= \\frac{\\var{d[0]}+ \\var{d[1]}+ \\var{d[2]}+ \\var{d[3]}+ \\var{d[4]}+ \\var{d[5]}+ \\var{d[6]}+ \\var{d[7]}+ \\var{d[8]}+ \\var{d[9]}+ \\var{d[10]}+ \\var{d[11]}}{\\var{n}} \\\\
&=\\var{dpformat(meandiff,3)}.
\\end{align}
The standard deviation of the differences is given by
\n\\begin{align}
s_d&= \\sqrt{\\frac{\\sum(d_i-\\bar{x}_d)^2}{n-1}}\\\\
&= \\sqrt{\\frac{(\\var{d[0]}-\\var{dpformat(meandiff,3)})^2+(\\var{d[1]}-\\var{dpformat(meandiff,3)})^2+...+(\\var{d[11]}-\\var{dpformat(meandiff,3)})^2}{\\var{n}-1}}\\\\
&=\\var{dpformat(stdiff,3)}.
\\end{align}
The paired test statistic is given by:
\n\\begin{align}
T &=\\frac{\\bar{x}_{d}-\\mu_d}{s_d/\\sqrt{n}}\\\\
&=\\frac{\\var{dpformat(meandiff,3)}-0}{\\var{dpformat(stdiff,3)}/\\sqrt{\\var{n}}}\\\\
&=\\var{dpformat(tvalue,3)}.
\\end{align}
For a paired sample $t$-test, we look up $t$ values on, $n-1 = \\var{n}-1 = 11$, degrees of freedom.
\nFrom looking at $t$ tables, we obtain the following values
\n\\[\\begin{array}{r|rrrrr}&0.20&0.10&0.05&0.01&0.001\\\\\\hline11&1.363&1.796&2.201&3.106&4.437\\end{array}\\]
\nWe see that the test statistic {msg[t]} and from the table we can see that the $p$ value {pmsg[t]}.
\nTherefore, there is {cmsg1[t]} evidence of a difference between the average scores of the two groups. Hence we conclude that we {cmsg[t]} the null hypothesis.
", "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "extensions": ["stats"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"msg": {"name": "msg", "group": "Choices", "definition": "['is greater than $\\\\var{t999}$','lies between $\\\\var{t99}$ and $\\\\var{t999}$','lies between $\\\\var{t95}$ and $\\\\var{t99}$','lies between $\\\\var{t90}$ and $\\\\var{t95}$','is less than $\\\\var{t90}$']", "description": "", "templateType": "anything", "can_override": false}, "d": {"name": "d", "group": "Summary Statistics of the difference", "definition": "list(vector(r2)-vector(r1))", "description": "Difference between left and right hand, (Left-Right).
", "templateType": "anything", "can_override": false}, "r2": {"name": "r2", "group": "Data given in question", "definition": "repeat(round(normalsample(mu2,sig2)),12)", "description": "Data for the \"left hand\".
", "templateType": "anything", "can_override": false}, "t": {"name": "t", "group": "Ungrouped variables", "definition": "switch(v[0]=1,0,v[1]=1,1,v[2]=1,2,v[3]=1,3,4)", "description": "", "templateType": "anything", "can_override": false}, "cmsg1": {"name": "cmsg1", "group": "Choices", "definition": "['very strong','strong','slight','no','no']", "description": "", "templateType": "anything", "can_override": false}, "t999": {"name": "t999", "group": "t-values", "definition": "4.437", "description": "", "templateType": "number", "can_override": false}, "t95": {"name": "t95", "group": "t-values", "definition": "2.201", "description": "", "templateType": "number", "can_override": false}, "n": {"name": "n", "group": "Data given in question", "definition": "12", "description": "Sample size.
", "templateType": "number", "can_override": false}, "stdiff": {"name": "stdiff", "group": "Summary Statistics of the difference", "definition": "precround(pstdev(d),3)", "description": "Standard deviation of the difference of the left and right.
", "templateType": "anything", "can_override": false}, "t90": {"name": "t90", "group": "t-values", "definition": "1.796", "description": "", "templateType": "number", "can_override": false}, "r1": {"name": "r1", "group": "Data given in question", "definition": "repeat(round(normalsample(mu1,sig1)),12)", "description": "Data for the \"right hand\".
", "templateType": "anything", "can_override": false}, "sig2": {"name": "sig2", "group": "Data given in question", "definition": "random(2..4#0.2)", "description": "", "templateType": "anything", "can_override": false}, "tvalue": {"name": "tvalue", "group": "Summary Statistics of the difference", "definition": "abs(meandiff*sqrt(n)/stdiff)", "description": "The test statistic of the difference between left and right.
", "templateType": "anything", "can_override": false}, "meandiff": {"name": "meandiff", "group": "Summary Statistics of the difference", "definition": "precround(mean(d),3)", "description": "Mean of the difference between left and right.
", "templateType": "anything", "can_override": false}, "sig1": {"name": "sig1", "group": "Data given in question", "definition": "random(2..3#0.2)", "description": "", "templateType": "anything", "can_override": false}, "object": {"name": "object", "group": "Ungrouped variables", "definition": "'Participant'", "description": "", "templateType": "anything", "can_override": false}, "mu2": {"name": "mu2", "group": "Data given in question", "definition": "mu1+random(2..5#0.1)", "description": "", "templateType": "anything", "can_override": false}, "pmsg": {"name": "pmsg", "group": "Choices", "definition": "[' is less than $0.001$',' lies between $0.001$ and $0.01$',' lies between $0.01$ and $0.05$',' lies between $0.05$ and $0.1$',' is greater than $0.1$']", "description": "", "templateType": "anything", "can_override": false}, "mu1": {"name": "mu1", "group": "Data given in question", "definition": "random(18..25#0.5)", "description": "", "templateType": "anything", "can_override": false}, "pvalue": {"name": "pvalue", "group": "Ungrouped variables", "definition": "precround(ttest(0,d,2),3)", "description": "", "templateType": "anything", "can_override": false}, "t99": {"name": "t99", "group": "t-values", "definition": "3.106", "description": "", "templateType": "number", "can_override": false}, "cmsg": {"name": "cmsg", "group": "Choices", "definition": "['do reject','do reject','do not reject','do not reject','do not reject']", "description": "", "templateType": "anything", "can_override": false}, "v": {"name": "v", "group": "Ungrouped variables", "definition": "if(tvalue>=t999,[1,0,0,0,0],if(tvalue>=t99,[0,1,0,0,0],if(tvalue>=t95,[0,0,1,0,0],if(tvalue>=t90,[0,0,0,1,0],[0,0,0,0,1]))))", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["object", "t", "v", "pvalue"], "variable_groups": [{"name": "t-values", "variables": ["t90", "t95", "t99", "t999"]}, {"name": "Data given in question", "variables": ["mu1", "mu2", "n", "r1", "r2", "sig1", "sig2"]}, {"name": "Summary Statistics of the difference", "variables": ["d", "meandiff", "stdiff", "tvalue"]}, {"name": "Choices", "variables": ["cmsg1", "cmsg", "msg", "pmsg"]}], "functions": {"pstdev": {"parameters": [["l", "list"]], "type": "number", "language": "jme", "definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "Calculate the paired differences for left attempt times – right attempt times. Make sure you take the differences this way round.
\n| {object} | \nA | \nB | \nC | \nD | \nE | \nF | \nG | \nH | \nI | \nJ | \nK | \nL | \n
| \n Differences \n$(d_i)$ \n | \n[[0]] | \n[[1]] | \n[[2]] | \n[[3]] | \n[[4]] | \n[[5]] | \n[[6]] | \n[[7]] | \n[[8]] | \n[[9]] | \n[[10]] | \n[[11]] | \n
Find the mean and standard deviations of the difference between left and right attempts.
\nMean of differences $\\bar{x}{_d}$ = [[0]]
\nStandard deviation of differences $s_d$ = [[1]]
", "gaps": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": "1", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "{meandiff}", "maxValue": "{meandiff}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "precisionType": "dp", "precision": "3", "precisionPartialCredit": 0, "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": false, "customName": "", "marks": "1", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [{"variable": "meandiff", "part": "p0g0", "must_go_first": true}], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "{stdiff}", "maxValue": "{stdiff}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "precisionType": "dp", "precision": "3", "precisionPartialCredit": 0, "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}, {"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "Calculate the test statistic $T$ using the rounded values that you have calculated above, and input the absolute value $|T|$ here: [[0]]
\n", "stepsPenalty": 0, "steps": [{"type": "information", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "For a paired $t$-test, the test statistic is given by:
\n\\[ T = \\frac{\\bar{x}_{d}-\\mu_d}{s_d/\\sqrt{n}}. \\]
\nHere, $\\mu_d=0$ because our null hypothesis is that the mean difference between the pairs is $0$.
"}], "gaps": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": "2", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [{"variable": "meandiff", "part": "p0g0", "must_go_first": true}, {"variable": "stdiff", "part": "p0g1", "must_go_first": true}], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "tvalue", "maxValue": "tvalue", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "precisionType": "dp", "precision": "3", "precisionPartialCredit": 0, "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}, {"type": "1_n_2", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "Given the value of the test statistic you have found, choose the range for the $p$-value by looking at the test statistic table values provided below.
\n\\[\\begin{array}{r|rrrrr}&0.20&0.10&0.05&0.01&0.001\\\\\\hline11&1.363&1.796&2.201&3.106&4.437\\end{array}\\]
", "minMarks": 0, "maxMarks": 0, "shuffleChoices": false, "displayType": "radiogroup", "displayColumns": 0, "showCellAnswerState": true, "choices": ["$p$ less than $0.1 \\%$
", "$p$ lies between $0.1\\%$ and $1 \\%$
", "$p$ lies between $1 \\%$ and $5\\%$
", "$p$ lies between $5 \\%$ and $10\\%$
", "$p$ is greater than $10\\%$
"], "matrix": "v"}, {"type": "1_n_2", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "Given the range of the $p$-value, what is the strength of evidence against the null hypothesis that there is no difference in the average times for the left and right hands, and what decision should be made?
", "minMarks": 0, "maxMarks": 0, "shuffleChoices": false, "displayType": "radiogroup", "displayColumns": 0, "showCellAnswerState": true, "choices": ["Very strong evidence - we reject the null hypothesis.
", "Strong evidence - we reject the null hypothesis.
", "Evidence - we reject the null hypothesis.
", "Weak Evidence - we don't reject the null hypothesis but consider further investigation.
", "No Evidence - we don't reject the null hypothesis.
"], "matrix": "v"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Vicky Hall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/659/"}, {"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Lauren Frances Desoysa", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2490/"}, {"name": "Aamir Khan", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4537/"}, {"name": "Tom Lowe", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/9601/"}], "resources": []}]}], "contributors": [{"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Vicky Hall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/659/"}, {"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}, {"name": "Lauren Frances Desoysa", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2490/"}, {"name": "Aamir Khan", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4537/"}, {"name": "Tom Lowe", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/9601/"}]}