// Numbas version: finer_feedback_settings {"name": "Apply Kruskal-Wallis test - Mock Test - SES2003", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"statement": "
The following data arose in a comparison of the effects of hydration on the time taken (in minutes) to complete a set of exercises. There were three groups of subjects; group 1 (fully hydrated), group 2 (partially hydrated) and group 3 (dehydrated).
\nGroup 1 (fully hydrated) | \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
---|---|---|---|---|---|---|
Group 2 (partially hydrated) | \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
Group 3 (dehydrated) | \n$\\var{r3[0]}$ | \n$\\var{r3[1]}$ | \n$\\var{r3[2]}$ | \n$\\var{r3[3]}$ | \n$\\var{r3[4]}$ | \n$\\var{r3[5]}$ | \n
Apply the Kruskal-Wallis test to this data in order to test the null hypothesis that hydration does not affect the mean time taken to complete the set of exercises.
\n", "metadata": {"description": "
Kruskal-Wallis test with ties.
", "licence": "Creative Commons Attribution 4.0 International"}, "preamble": {"js": "", "css": ""}, "functions": {"pstdev": {"definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "parameters": [["l", "list"]], "language": "jme", "type": "number"}, "rk": {"definition": "\n/*This gives the ranking of the entries in l, c counts the ties, \nrep counts the repetitions of each entry*/\nvar out = [];\nvar rep = [];\n for(var j=0;jFirst fill in this table with the appropriate values, all decimals to 1 decimal place. $R_1,\\;R_2,\\;R_3$ are the sums of the ranks in each row.
\nGroup 1 (fully hydrated) | \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\n |
---|---|---|---|---|---|---|---|
Rank | \n[[0]] | \n[[1]] | \n[[2]] | \n[[3]] | \n[[4]] | \n[[5]] | \n$R_1=\\;$[[6]] | \n
Group 2 (partially hydrated) | \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\n |
Rank | \n[[7]] | \n[[8]] | \n[[9]] | \n[[10]] | \n[[11]] | \n[[12]] | \n$R_2=\\;$[[13]] | \n
Group 3 (dehydrated) | \n$\\var{r3[0]}$ | \n$\\var{r3[1]}$ | \n$\\var{r3[2]}$ | \n$\\var{r3[3]}$ | \n$\\var{r3[4]}$ | \n$\\var{r3[5]}$ | \n\n |
Rank | \n[[14]] | \n[[15]] | \n[[16]] | \n[[17]] | \n[[18]] | \n[[19]] | \n$R_3=\\;$[[20]] | \n
"}, {"extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "type": "gapfill", "variableReplacements": [], "showFeedbackIcon": true, "sortAnswers": false, "marks": 0, "unitTests": [], "gaps": [{"extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "variableReplacements": [], "scripts": {}, "mustBeReduced": false, "allowFractions": false, "correctAnswerFraction": false, "unitTests": [], "marks": "1", "mustBeReducedPC": 0, "correctAnswerStyle": "plain", "customMarkingAlgorithm": "", "showCorrectAnswer": true, "minValue": "precround(H,3)-0.001", "showFeedbackIcon": true, "maxValue": "precround(H,3)+0.001"}, {"extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "variableReplacements": [], "scripts": {}, "mustBeReduced": false, "allowFractions": false, "correctAnswerFraction": false, "unitTests": [], "marks": 1, "mustBeReducedPC": 0, "correctAnswerStyle": "plain", "customMarkingAlgorithm": "", "showCorrectAnswer": true, "minValue": "precround(corr,3)", "showFeedbackIcon": true, "maxValue": "precround(corr,3)"}, {"extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "variableReplacements": [], "scripts": {}, "mustBeReduced": false, "allowFractions": false, "correctAnswerFraction": false, "unitTests": [], "marks": "1", "mustBeReducedPC": 0, "correctAnswerStyle": "plain", "customMarkingAlgorithm": "", "showCorrectAnswer": true, "minValue": "kw-0.01", "showFeedbackIcon": true, "maxValue": "kw+0.01"}], "customMarkingAlgorithm": "", "showCorrectAnswer": true, "scripts": {}, "prompt": "
Now calculate the Kruskal-Wallis test statistic in the following steps as in your notes:
\n$H=\\;$[[0]] (Assuming no ties). Calculate to 3 decimal places.
\n$C=\\;$[[1]] (Correction for ties). Calculate to 3 decimal places.
\nKruskal-Wallis statistic $H^*=\\;$ [[2]]. Calculate to 2 decimal places.
\n"}, {"extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "type": "1_n_2", "variableReplacements": [], "showFeedbackIcon": true, "displayColumns": "1", "marks": 0, "maxMarks": 0, "unitTests": [], "shuffleChoices": false, "minMarks": 0, "displayType": "radiogroup", "customMarkingAlgorithm": "", "matrix": "w", "choices": ["We very strongly reject the null hypothesis at the $0.1\\%$ level and conclude that times differ depending upon hydration level.", "We strongly reject the null hypothesis at the $1\\%$ level and conclude that times differ depending upon hydration level.", "We have evidence against the null hypothesis at the $5\\%$ level and conclude that times differ depending upon hydration level.", "We only have weak evidence against the null hypothesis at the $10\\%$ level and so accept that times do not depend upon hydration level.", "We have no evidence against the null hypothesis and so accept that times do not depend upon hydration level."], "showCorrectAnswer": true, "scripts": {}, "prompt": "Give the value of $H^*$ you have found, determine the significance of your result by looking up the critical values in the $\\chi^2$ table.
\n$10\\%$ | \n$5\\%$ | \n$1\\%$ | \n$0.1\\%$ | \n
$4.605$ | \n$5.991$ | \n$9.210$ | \n$13.816$ | \n
Hence what can you say using the Kruskal-Wallis test about the null hypothesis that times to do the exercises do not depend upon the level of hydration?
", "showCellAnswerState": true}], "advice": "In order to find the ranks we order, in increasing order, all of the times for the exercise set across all the three groups. We also work out the ranks for each time by including a row which simply numbers from $1$ to $\\var{n}$, this we call the index of the numbers and the last row then takes equal values in the list and gives the averages of their indices, so that they all get the same rank. So you simply add up their corresponding indices in that group and divide by the number of equal entries. So if a number is not repeated then its rank is its index.
\nFor this example we have:
\n{table([s1,s2,s3],[])}
\nWe see that there are ties as follows:
\n{table(ties,[])}
\nWe use this information later to find the correction factor.
\nPutting these ranks back into the original table gives, where $R_1,\\;R_2$ and $R_3$ are the sums of the ranks in each row:
\nGroup 1 (fully hydrated) | \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\n |
---|---|---|---|---|---|---|---|
Rank | \n{rkt[0]} | \n{rkt[1]} | \n{rkt[2]} | \n{rkt[3]} | \n{rkt[4]} | \n{rkt[5]} | \n$R_1=\\;${sr[0]} | \n
Group 2 (partially hydrated) | \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\n |
Rank | \n{rkt[6]} | \n{rkt[7]} | \n{rkt[8]} | \n{rkt[9]} | \n{rkt[10]} | \n{rkt[11]} | \n$R_2=\\;${sr[1]} | \n
Group 3 (dehydrated) | \n$\\var{r3[0]}$ | \n$\\var{r3[1]}$ | \n$\\var{r3[2]}$ | \n$\\var{r3[3]}$ | \n$\\var{r3[4]}$ | \n$\\var{r3[5]}$ | \n\n |
Rank | \n{rkt[12]} | \n{rkt[13]} | \n{rkt[14]} | \n{rkt[15]} | \n{rkt[16]} | \n{rkt[17]} | \n$R_3=\\;${sr[2]} | \n
We now have enough information to start the calculation of the Kruskal-Wallis statistic.
\nWe do this in three steps:
\n1. Calculate the statistic $H$, which assumes there are no ties.
\n2. Find the correction factor $C$ given by the ties in the data.
\n3. This gives the statistic $H^*=H/C$ we want, and we make a decision based on the Kruskal-Wallis table.
\nStep 1: Find $H$.
\n\\[\\begin{eqnarray*}H &=& \\left[\\frac{12}{N \\times (N+1)} \\times \\left(\\sum \\frac{R_i^2}{n_i}\\right)\\right]-3(N+1)\\\\&=&\\left\\{\\frac{12}{\\var{n}\\times\\var{n+1}}\\times\\left(\\frac{\\var{sr[0]}^2}{6}+\\frac{\\var{sr[1]}^2}{6}+\\frac{\\var{sr[2]}^2}{6}\\right)\\right\\}-3\\times \\var{n+1}\\\\&=&\\var{h}\\\\&=&\\var{precround(H,3)}\\end{eqnarray*}\\] to 3 decimal places.
\nStep 2: Find the Correction Factor $C$.
\nFor each tie with $g$ equal data values we calculate $\\displaystyle \\frac{g^3-g}{N^3-N}$ and add these together over all ties to get $T$.
\nThen $C=1-T$.
\nSo for our data we have:
\n{table(tiesplus,[' ','Number','Contribution','Value'])}
\nHence $C=1-T = 1-\\var{sum(vties)}=\\var{1-sum(vties)}=\\var{precround(corr,3)}$ to 3 decimal places.
\nStep 3: Find the Kruskal-Wallis test statistic and make a decision.
\nThe statistic is given by $\\displaystyle H^*=\\frac{H}{C}=\\frac{\\var{precround(h,3)}}{\\var{precround(corr,3)}}=\\var{kw}$ to 2 decimal places.
\nLooking at the $\\chi^2$ table our decision is that {dec}
\n$10\\%$ | \n$5\\%$ | \n$1\\%$ | \n$0.1\\%$ | \n
$4.605$ | \n$5.991$ | \n$9.210$ | \n$13.816$ | \n