// Numbas version: exam_results_page_options {"name": "Apply Kruskal-Wallis test", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [], "variables": {"s1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "['$\\\\bf{Ordered\\\\;\\\\; times}$']+sort(biglist)", "description": "", "name": "s1"}, "tol": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0.001", "description": "", "name": "tol"}, "ran": {"templateType": "anything", "group": "Ungrouped variables", "definition": "rk(biglist)", "description": "", "name": "ran"}, "sig1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(3..5#0.2)", "description": "", "name": "sig1"}, "n": {"templateType": "anything", "group": "Ungrouped variables", "definition": "n1+n2+n3", "description": "", "name": "n"}, "sr": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(sum(ran[x..x+6]),x,[0,6,12])", "description": "", "name": "sr"}, "sd1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(pstdev(r1),2)", "description": "", "name": "sd1"}, "corr": {"templateType": "anything", "group": "Ungrouped variables", "definition": "1-1/(n^3-n)*g", "description": "", "name": "corr"}, "m3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(mean(r3),2)", "description": "", "name": "m3"}, "n2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "6", "description": "", "name": "n2"}, "k": {"templateType": "anything", "group": "Ungrouped variables", "definition": "3", "description": "", "name": "k"}, "rs": {"templateType": "anything", "group": "Ungrouped variables", "definition": "rep(ran[18..36])", "description": "", "name": "rs"}, "mu2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(22..28#0.5)", "description": "", "name": "mu2"}, "mu1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(20..25#0.5)", "description": "", "name": "mu1"}, "sig2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sig1", "description": "", "name": "sig2"}, "ties": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(['Number of ties of size $'+x+1+'$ =', round(rs[x]/(x+1))],x,1..abs(rs)-1)", "description": "", "name": "ties"}, "kw": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(h/corr,2)", "description": "", "name": "kw"}, "dec": {"templateType": "anything", "group": "Ungrouped variables", "definition": "switch(w[0]=1,'we very strongly reject the null hypothesis at the $0.1\\\\%$ level and conclude that reaction times differ depending upon alcohol uptake.',\n w[1]=1,'we strongly reject the null hypothesis at the $1\\\\%$ level and conclude that reaction times differ depending on alcohol uptake.',\n w[2]=1,'we have evidence against the null hypothesis at the $5\\\\%$ level and we reject it',\n w[3]=1, 'we only have weak evidence against the null hypothesis at the $10\\\\%$ level so we do not reject it.',\n'there is no evidence against the null hypothesis and so we accept it.' )", "description": "", "name": "dec"}, "g": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sum(map(ran[x]^2-1,x,18..35))", "description": "", "name": "g"}, "rkt": {"templateType": "anything", "group": "Ungrouped variables", "definition": "ran[0..18]", "description": "", "name": "rkt"}, "m2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(mean(r2),2)", "description": "", "name": "m2"}, "w": {"templateType": "anything", "group": "Ungrouped variables", "definition": "switch(kw>=13.816,[1,0,0,0,0],kw >=9.210,[0,1,0,0,0],kw>=5.991,[0,0,1,0,0],kw>=4.605,[0,0,0,1,0],[0,0,0,0,1])", "description": "", "name": "w"}, "n1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "6", "description": "", "name": "n1"}, "sd3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(pstdev(r3),2)", "description": "", "name": "sd3"}, "m1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(mean(r1),2)", "description": "", "name": "m1"}, "r3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "repeat(round(normalsample(mu3,sig3)),6)", "description": "", "name": "r3"}, "tiesplus": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(['Ties of size $'+(x+1)+'$','$'+round(rs[x]/(x+1))+'$', '$\\\\,\\\\,\\\\,\\\\,\\\\, \\\\displaystyle '+round(rs[x]/(x+1))+'\\\\times \\\\displaystyle \\\\frac{'+(x+1)+'^3-'+(x+1)+'}{'+n+'^3-'+n+'}$','$'+vties[x-1]+'$'],x,1..abs(rs)-1)+[['Total',' ',' ','$T='+sum(vties)+'$']]", "description": "", "name": "tiesplus"}, "n3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "6", "description": "", "name": "n3"}, "sig3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sig1", "description": "", "name": "sig3"}, "r2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "repeat(round(normalsample(mu2,sig2)),6)", "description": "", "name": "r2"}, "s3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "['$\\\\bf{Rank}$']+ sort(rkt)", "description": "", "name": "s3"}, "biglist": {"templateType": "anything", "group": "Ungrouped variables", "definition": "r1+r2+r3", "description": "", "name": "biglist"}, "mu3": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(24..32#0.5)", "description": "", "name": "mu3"}, "r1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "repeat(round(normalsample(mu1,sig1)),6)", "description": "", "name": "r1"}, "sd2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(pstdev(r2),2)", "description": "", "name": "sd2"}, "s2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "['$\\\\bf{Index}$']+map(x,x,1..18)", "description": "", "name": "s2"}, "h": {"templateType": "anything", "group": "Ungrouped variables", "definition": "12/(n*(n+1))*sum(map(x^2/n1,x,sr))-3*(n+1)", "description": "", "name": "h"}, "vties": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(round(rs[x]/(x+1))*(((x+1)^3-(x+1))/(n^3-n)),x,1..abs(rs)-1)", "description": "", "name": "vties"}}, "ungrouped_variables": ["rkt", "sd1", "sd2", "sd3", "ran", "biglist", "vties", "mu3", "rs", "s3", "s2", "s1", "m1", "tol", "m2", "tiesplus", "m3", "sig1", "sig3", "sig2", "corr", "ties", "r1", "n3", "mu1", "g", "r2", "mu2", "h", "k", "r3", "n", "kw", "w", "sr", "n1", "n2", "dec"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Apply Kruskal-Wallis test", "functions": {"pstdev": {"type": "number", "language": "jme", "definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "parameters": [["l", "list"]]}, "rep": {"type": "list", "language": "javascript", "definition": "\nvar b=a.sort(function(c,d){return c-d});\n var M=b[a.length-1];\n var arr=[];\n for(var j=1;j<=M;j++){\nvar s=0;\nfor(var i=0;il[i]){s+=1;}\n else\nif(l[j]==l[i]){c+=1;}\n}\n out[j]=(2*s+c+1)/2;\n rep[j]=c;\n }\n return out.concat(rep);\n\n", "parameters": [["l", "list"]]}}, "showQuestionGroupNames": false, "parts": [{"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[0]", "minValue": "ran[0]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[1]", "minValue": "ran[1]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[2]", "minValue": "ran[2]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[3]", "minValue": "ran[3]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[4]", "minValue": "ran[4]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[5]", "minValue": "ran[5]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "sr[0]", "minValue": "sr[0]", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[6]", "minValue": "ran[6]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[7]", "minValue": "ran[7]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[8]", "minValue": "ran[8]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[9]", "minValue": "ran[9]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[10]", "minValue": "ran[10]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[11]", "minValue": "ran[11]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "sr[1]", "minValue": "sr[1]", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[12]", "minValue": "ran[12]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[13]", "minValue": "ran[13]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[14]", "minValue": "ran[14]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[15]", "minValue": "ran[15]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[16]", "minValue": "ran[16]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ran[17]", "minValue": "ran[17]", "correctAnswerFraction": false, "marks": 0.5, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "sr[2]", "minValue": "sr[2]", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}], "type": "gapfill", "prompt": "

Kruskal-Wallis Test

\n

First 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.

\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
Group A (0 units)$\\var{r1[0]}$$\\var{r1[1]}$$\\var{r1[2]}$$\\var{r1[3]}$$\\var{r1[4]}$$\\var{r1[5]}$ 
Rank[[0]][[1]][[2]][[3]][[4]][[5]]$R_1=\\;$[[6]]
Group B (2 units)$\\var{r2[0]}$$\\var{r2[1]}$$\\var{r2[2]}$$\\var{r2[3]}$$\\var{r2[4]}$$\\var{r2[5]}$ 
Rank[[7]][[8]][[9]][[10]][[11]][[12]]$R_2=\\;$[[13]]
Group C (4 units)$\\var{r3[0]}$$\\var{r3[1]}$$\\var{r3[2]}$$\\var{r3[3]}$$\\var{r3[4]}$$\\var{r3[5]}$ 
Rank[[14]][[15]][[16]][[17]][[18]][[19]]$R_3=\\;$[[20]]
\n

 

", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "precround(H,3)+0.001", "minValue": "precround(H,3)-0.001", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "precround(corr,3)", "minValue": "precround(corr,3)", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}, {"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "kw+0.01", "minValue": "kw-0.01", "correctAnswerFraction": false, "marks": 2, "showPrecisionHint": false}, {"displayType": "radiogroup", "choices": ["

We very strongly reject the null hypothesis at the $0.1\\%$ level and conclude that reaction times differ depending upon alcohol uptake.

", "

We strongly reject the null hypothesis at the $1\\%$ level and conclude that reaction times differ depending upon alcohol uptake.

", "

We have evidence against the null hypothesis at the $5\\%$ level and conclude that reaction times differ depending upon alcohol uptake.

", "

We only have weak evidence against the null hypothesis at the $10\\%$ level and so accept that reaction times do not depend upon alcohol uptake.

", "

We have no evidence against the null hypothesis and so accept that reaction times do not depend upon alcohol uptake.

"], "displayColumns": 1, "distractors": ["", "", "", "", ""], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "matrix": "w", "marks": 0}], "type": "gapfill", "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.

\n

Kruskal-Wallis statistic $H^*=\\;$ [[2]].   Calculate to 2 decimal places.

\n

 

\n

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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$10\\%$$5\\%$$1\\%$$0.1\\%$
$4.605$$5.991$$9.210$$13.816$
\n

Hence what can you say using the Kruskal-Wallis test about the null hypothesis that times to do the task do not depend upon the levels of alcohol?

\n

[[3]]

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

The following data arose in a comparison of the effects of alcohol on the time taken to complete a task. There were three groups of subjects; Group A had no alcohol, Group B had two units over 1 hour and Group C had 4 units over 1 hour. The responses are the times (in seconds) taken to complete a word-matching task.

\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
Group A (0 units)$\\var{r1[0]}$$\\var{r1[1]}$$\\var{r1[2]}$$\\var{r1[3]}$$\\var{r1[4]}$$\\var{r1[5]}$
Group B (2 units)$\\var{r2[0]}$$\\var{r2[1]}$$\\var{r2[2]}$$\\var{r2[3]}$$\\var{r2[4]}$$\\var{r2[5]}$
Group C (4 units)$\\var{r3[0]}$$\\var{r3[1]}$$\\var{r3[2]}$$\\var{r3[3]}$$\\var{r3[4]}$$\\var{r3[5]}$
\n

\n Apply the Kruskal-Wallis test to this data on reaction times under alcohol in order to test the null hypothesis that the alcohol consumption does not affect the mean time taken to complete the task. \n \n

 

", "tags": ["checked2015", "correction for ties", "data analysis", "hypothesis testing", "Kruskal-Wallis", "one-way Anova", "one-way ANOVA", "PSY2010", "rank", "statistics", "stats", "ties"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "\n \t\t

29/11/2012:

\n \t\t


Created question from one-way Anova question

\n \t\t

Added tags.

\n \t\t

Calculation not yet tested.

\n \t\t

Added description.

\n \t\t

Checked calculation.

\n \t\t

Kept Anova test in for comparison purposes.

\n \t\t

 

\n \t\t", "licence": "Creative Commons Attribution 4.0 International", "description": "

Kruskal-Wallis test with ties.

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

In order to find the ranks we order, in increasing order,  all of the times for the tasks 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. 

\n

For this example we have:

\n

{table([s1,s2,s3],[])}

\n

We see that there are ties as follows:

\n

{table(ties,[])}

\n

We use this information later to find the correction factor.

\n

Putting 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:

\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
Group A (0 units)$\\var{r1[0]}$$\\var{r1[1]}$$\\var{r1[2]}$$\\var{r1[3]}$$\\var{r1[4]}$$\\var{r1[5]}$ 
Rank{rkt[0]}{rkt[1]}{rkt[2]}{rkt[3]}{rkt[4]}{rkt[5]}$R_1=\\;${sr[0]}
Group B (2 units)$\\var{r2[0]}$$\\var{r2[1]}$$\\var{r2[2]}$$\\var{r2[3]}$$\\var{r2[4]}$$\\var{r2[5]}$ 
Rank{rkt[6]}{rkt[7]}{rkt[8]}{rkt[9]}{rkt[10]}{rkt[11]}$R_2=\\;${sr[1]}
Group C (4 units)$\\var{r3[0]}$$\\var{r3[1]}$$\\var{r3[2]}$$\\var{r3[3]}$$\\var{r3[4]}$$\\var{r3[5]}$ 
Rank{rkt[12]}{rkt[13]}{rkt[14]}{rkt[15]}{rkt[16]}{rkt[17]}$R_3=\\;${sr[2]}
\n

We now have enough information to start the calculation of the Kruskal-Wallis statistic.

\n

We do this in three steps:

\n

1. Calculate the statistic $H$, which assumes there are no ties.

\n

2. Find the correction factor $C$ given by the ties in the data.

\n

3. This gives the statistic $H^*=H/C$ we want, and we make a decision based on the Kruskal-Wallis table.

\n

Step 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.

\n

Step 2: Find the Correction Factor $C$.

\n

For 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$.

\n

Then $C=1-T$.

\n

So for our data we have:

\n

{table(tiesplus,[' ','Number','Contribution','Value'])}

\n

Hence $C=1-T = 1-\\var{sum(vties)}=\\var{1-sum(vties)}=\\var{precround(corr,3)}$ to 3 decimal places.

\n

Step 3: Find the Kruskal-Wallis test statistic and make a decision.

\n

The statistic is given by $\\displaystyle H^*=\\frac{H}{C}=\\frac{\\var{precround(h,3)}}{\\var{precround(corr,3)}}=\\var{kw}$ to 2 decimal places.

\n

Looking at the $\\chi^2$ table our decision is that {dec}

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$10\\%$$5\\%$$1\\%$$0.1\\%$
$4.605$$5.991$$9.210$$13.816$
\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/"}]}