// Numbas version: finer_feedback_settings {"questions": [], "duration": 0, "name": "Kruskal-Wallis and Friedman tests", "showQuestionGroupNames": false, "allQuestions": true, "percentPass": 0, "feedback": {"showanswerstate": true, "advicethreshold": 0, "showactualmark": true, "allowrevealanswer": true, "showtotalmark": true, "enterreviewmodeimmediately": true, "showexpectedanswerswhen": "inreview", "showpartfeedbackmessageswhen": "always", "showactualmarkwhen": "always", "showtotalmarkwhen": "always", "showanswerstatewhen": "always", "showadvicewhen": "never"}, "shuffleQuestions": false, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Apply Friedman test", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}], "variablesTest": {"condition": "", "maxRuns": 100}, "variables": {"tol": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0.01", "description": "", "name": "tol"}, "r1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(repeat(round(normalsample(mu[x],sig)),5),x,0..m-1)", "description": "", "name": "r1"}, "v": {"templateType": "anything", "group": "Ungrouped variables", "definition": "switch(fr>=16.266,[1,0,0,0,0],fr >=11.345,[0,1,0,0,0],fr>=7.815,[0,0,1,0,0],fr>=6.251,[0,0,0,1,0],[0,0,0,0,1])", "description": "", "name": "v"}, "sig": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(3..7#0.2)", "description": "", "name": "sig"}, "sun": {"templateType": "anything", "group": "Ungrouped variables", "definition": "['A','B','C','D','E']", "description": "", "name": "sun"}, "surk": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(sum(list(srk)[x]),x,0..3)", "description": "", "name": "surk"}, "rs": {"templateType": "anything", "group": "Ungrouped variables", "definition": "matrix(map(rep(rk(r[x])[4..8]),x,0..4))", "description": "", "name": "rs"}, "n": {"templateType": "anything", "group": "Ungrouped variables", "definition": "5", "description": "", "name": "n"}, "mu": {"templateType": "anything", "group": "Ungrouped variables", "definition": "[random(30..40),random(35..40),random(25..35),random(40..45),random(20..40)]", "description": "", "name": "mu"}, "fr1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "12/(n*m*(m+1))*sum(map(surk[x]^2,x,0..3))-3*n*(m+1)", "description": "", "name": "fr1"}, "disptab": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(if(scorr[x]=0,'',table(tiesplus[x],['Subject $'+sun[x]+'$','Number of Ties','Contribution','Value'])),x,0..4)", "description": "", "name": "disptab"}, "dec": {"templateType": "anything", "group": "Ungrouped variables", "definition": "switch(v[0]=1,'we very strongly reject the null hypothesis at the $0.11\\\\%$ level and conclude that the suncreams differ in their effect.',\n v[1]=1,'we strongly reject the null hypothesis at the $1\\\\%$ level and conclude that the suncreams differ in their effect.',\n v[2]=1,'we have evidence to reject the null hypothesis at the $5\\\\%$ level and conclude that the suncreams differ in their effect.',\n v[3]=1,'we only have weak evidence against the null hypothesis at the $10\\\\%$ level and we do not reject it',\n 'there is no evidence against the null hypothesis and we accept it.')", "description": "", "name": "dec"}, "vties": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(map(round(rs[y][x]/(x+1))*(((x+1)^3-(x+1))/(n*(m^3-m))),x,1..abs(rs[y])-1),y,0..4)\n", "description": "", "name": "vties"}, "tieslist": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(map(round(rs[y][x]/(x+1)),x,1..m-1),y,0..4)\n", "description": "", "name": "tieslist"}, "nties": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(sum(tieslist[x]),x,0..4)", "description": "", "name": "nties"}, "mess1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(tscorr=0, '(no ties, so $T=0$).','')", "description": "", "name": "mess1"}, "m": {"templateType": "anything", "group": "Ungrouped variables", "definition": "4", "description": "", "name": "m"}, "scorr": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(sum(vties[x]),x,0..4)", "description": "", "name": "scorr"}, "fr": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(fr1/(1-tscorr),2)", "description": "", "name": "fr"}, "tscorr": {"templateType": "anything", "group": "Ungrouped variables", "definition": "sum(scorr)", "description": "", "name": "tscorr"}, "tiesplus": {"templateType": "anything", "group": "Ungrouped variables", "definition": "map(map(['Ties of size $'+(x+1)+'$.','$'+round(rs[y][x]/(x+1))+'$', '$\\\\,\\\\,\\\\,\\\\,\\\\, \\\\displaystyle '+round(rs[y][x]/(x+1))+'\\\\times \\\\displaystyle \\\\frac{'+(x+1)+'^3-'+(x+1)+'}{'+n+'('+m+'^3-'+m+')}$','$'+vties[y][x-1]+'$'],x,1..abs(rs[y])-1),y,0..4)", "description": "", "name": "tiesplus"}, "r": {"templateType": "anything", "group": "Ungrouped variables", "definition": "list(transpose(matrix(r1)))", "description": "", "name": "r"}, "rnk": {"templateType": "anything", "group": "Ungrouped variables", "definition": "matrix(map(rk(r[x])[0..4],x,0..4))", "description": "", "name": "rnk"}, "rt": {"templateType": "anything", "group": "Ungrouped variables", "definition": "list(transpose(matrix(r)))", "description": "", "name": "rt"}, "messtab": {"templateType": "anything", "group": "Ungrouped variables", "definition": "if(tscorr=0, 'that there are no ties.','that there are ties as follows:')", "description": "", "name": "messtab"}, "srk": {"templateType": "anything", "group": "Ungrouped variables", "definition": "transpose((rnk))", "description": "", "name": "srk"}}, "ungrouped_variables": ["tieslist", "vties", "rt", "scorr", "rs", "sun", "sig", "tol", "disptab", "rnk", "tiesplus", "fr", "surk", "mess1", "messtab", "nties", "tscorr", "r1", "srk", "m", "n", "mu", "fr1", "r", "v", "dec"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "functions": {"rep": {"type": "list", "language": "javascript", "definition": "/*the list a contains natural numbers up to a maximum value M. \n This function outputs an array where arr[j]/(j+1)=number of ties of size j+1*/\n var 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"]]}}, "variable_groups": [], "showQuestionGroupNames": false, "parts": [{"scripts": {}, "gaps": [{"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[0][0]", "minValue": "srk[0][0]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[0][1]", "minValue": "srk[0][1]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[0][2]", "minValue": "srk[0][2]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[0][3]", "minValue": "srk[0][3]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[0][4]", "minValue": "srk[0][4]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "surk[0]", "minValue": "surk[0]", "showCorrectAnswer": true, "marks": 0.5}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[1][0]", "minValue": "srk[1][0]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[1][1]", "minValue": "srk[1][1]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[1][2]", "minValue": "srk[1][2]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[1][3]", "minValue": "srk[1][3]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[1][4]", "minValue": "srk[1][4]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "surk[1]", "minValue": "surk[1]", "showCorrectAnswer": true, "marks": 0.5}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[2][0]", "minValue": "srk[2][0]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[2][1]", "minValue": "srk[2][1]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[2][2]", "minValue": "srk[2][2]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[2][3]", "minValue": "srk[2][3]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[2][4]", "minValue": "srk[2][4]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "surk[2]", "minValue": "surk[2]", "showCorrectAnswer": true, "marks": 0.5}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[3][0]", "minValue": "srk[3][0]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[3][1]", "minValue": "srk[3][1]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[3][2]", "minValue": "srk[3][2]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[3][3]", "minValue": "srk[3][3]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "srk[3][4]", "minValue": "srk[3][4]", "showCorrectAnswer": true, "marks": 0.25}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "surk[3]", "minValue": "surk[3]", "showCorrectAnswer": true, "marks": 0.5}], "type": "gapfill", "prompt": "\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\n\n\n\n\n\n\n\n\n\n\n
SubjectABCDETotals
Suncream      
W$\\var{r1[0][0]}$$\\var{r1[0][1]}$$\\var{r1[0][2]}$$\\var{r1[0][3]}$$\\var{r1[0][4]}$ 
Rank[[0]][[1]][[2]][[3]][[4]]$R_1=\\;$[[5]]
X$\\var{r1[1][0]}$$\\var{r1[1][1]}$$\\var{r1[1][2]}$$\\var{r1[1][3]}$$\\var{r1[1][4]}$ 
Rank[[6]][[7]][[8]][[9]][[10]]$R_2=\\;$[[11]]
Y$\\var{r1[2][0]}$$\\var{r1[2][1]}$$\\var{r1[2][2]}$$\\var{r1[2][3]}$$\\var{r1[2][4]}$ 
Rank[[12]][[13]][[14]][[15]][[16]]$R_3=\\;$[[17]]
Z$\\var{r1[3][0]}$$\\var{r1[3][1]}$$\\var{r1[3][2]}$$\\var{r1[3][3]}$$\\var{r1[3][4]}$ 
Rank[[18]][[19]][[20]][[21]][[22]]$R_4=\\;$[[23]]
\n

Rank each column separately and enter the ranks in the table, using the method you used for the Kruskal-Wallis question. (Hence the sum of the ranks in each column should be 10). Also input the sums of the ranks $R_1,\\;R_2,\\;R_3$ and $R_4$ for each row.

", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "fr1", "minValue": "fr1", "showCorrectAnswer": true, "marks": 2}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "1-tscorr", "minValue": "1-tscorr", "showCorrectAnswer": true, "marks": 2}, {"correctAnswerFraction": false, "showPrecisionHint": false, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "fr+tol", "minValue": "fr-tol", "showCorrectAnswer": true, "marks": 1}], "type": "gapfill", "prompt": "

Next you  work out the uncorrected (for ties) Friedman statistic $\\chi_r^2$.

\n

Here:

\n

$t = \\;$ number of treatments i.e. suncreams $\\;=4$

\n

$b=\\;$ number of subjects $\\;=5$.

\n

$\\displaystyle \\chi_r^2= \\frac{12}{b\\times t \\times (t+1)}\\left[\\sum R_i^2 \\right]-\\left\\{3\\times b\\times (t+1)\\right\\}=\\;$[[0]] (Input to 2 decimal places).

\n

Now input the correction term due to the ties:

\n

$C=\\;$[[1]] (Input to 2 decimal places).

\n

Hence the corrected Friedman test statistic is:

\n

$\\chi_r^{2^*}=\\;$[[2]]  (Input to 2 decimal places).

\n

 

\n

 

", "showCorrectAnswer": true, "marks": 0}, {"displayType": "radiogroup", "choices": ["

We have very strong evidence to  reject the null hypothesis at the $0.1\\%$ level and conclude that the suncreams differ in their effect.

", "

We have strong evidence to reject the null hypothesis at the $1\\%$ level and conclude that the suncreams differ in their effect.

", "

We have evidence to reject the null hypothesis at the $5\\%$ level and conclude that the suncreams differ in their effect.

", "

We only have weak evidence against the null hypothesis at the $10\\%$ level and so we retain the null hypothesis.

", "

We have no  evidence against the null hypothesis so we retain the null hypothesis that the suncreams have the same effect.

"], "matrix": "v", "prompt": "

Give the value of $\\chi_r^{2^*}$ you have found, and the $\\chi^2$ table data:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$10\\%$$5\\%$$1\\%$$0.1\\%$
$6.251$$7.815$$11.345$$16.266$
\n

What is your decision?

\n

\n

 

", "distractors": ["", "", "", "", ""], "shuffleChoices": false, "scripts": {}, "maxMarks": 0, "type": "1_n_2", "minMarks": 0, "showCorrectAnswer": true, "displayColumns": 1, "marks": 0}], "statement": "

To test the effectiveness of sun-tan creams, five volunteers A, B, C, D, E each tried four creams W, X, Y, Z on various parts of their legs. They were then subjected to ultra-violet radiation and an estimate of the degree of burning was made (higher figures indicate greater burning). The results are given below with some totals:

\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
 WXYZ
A{r[0][0]}{r[0][1]}{r[0][2]}{r[0][3]}
B{r[1][0]}{r[1][1]}{r[1][2]}{r[1][3]}
C{r[2][0]}{r[2][1]}{r[2][2]}{r[2][3]}
D{r[3][0]}{r[3][1]}{r[3][2]}{r[3][3]}
E{r[4][0]}{r[4][1]}{r[4][2]}{r[4][3]}
\n

 

\n

Apply the Friedman test to this data in relation to the null hypothesis that there is no difference in the effectiveness of the suncreams.

", "tags": ["checked2015", "correction term", "Friedman statistic", "hypothesis testing", "PSY2010", "ranks", "statistics", "ties", "treatments"], "rulesets": {}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "", "licence": "Creative Commons Attribution 4.0 International", "description": "

Friedman test, 5 subjects, 4 treatments.

"}, "advice": "

Step 1.

\n

First we present the data as in the next table, changing rows to columns, and work out the ranks of each of the columns. So all we are doing is ranking the four numbers in each column separately. We use the method of finding ranks as explained for the Kruskal-Wallis example. Then we sum over 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\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
SubjectABCDETotals
Suncream      
W$\\var{r1[0][0]}$$\\var{r1[0][1]}$$\\var{r1[0][2]}$$\\var{r1[0][3]}$$\\var{r1[0][4]}$ 
Rank{srk[0][0]}{srk[0][1]}{srk[0][2]}{srk[0][3]}{srk[0][4]}$R_1=\\;${surk[0]}
X$\\var{r1[1][0]}$$\\var{r1[1][1]}$$\\var{r1[1][2]}$$\\var{r1[1][3]}$$\\var{r1[1][4]}$ 
Rank{srk[1][0]}{srk[1][1]}{srk[1][2]}{srk[1][3]}{srk[1][4]}$R_2=\\;${surk[1]}
Y$\\var{r1[2][0]}$$\\var{r1[2][1]}$$\\var{r1[2][2]}$$\\var{r1[2][3]}$$\\var{r1[2][4]}$ 
Rank{srk[2][0]}{srk[2][1]}{srk[2][2]}{srk[2][3]}{srk[2][4]}$R_3=\\;${surk[2]}
Z$\\var{r1[3][0]}$$\\var{r1[3][1]}$$\\var{r1[3][2]}$$\\var{r1[3][3]}$$\\var{r1[3][4]}$ 
Rank{srk[3][0]}{srk[3][1]}{srk[3][2]}{srk[3][3]}{srk[3][4]}$R_4=\\;${surk[3]}
 
Ties{nties[0]}{nties[1]}{nties[2]}{nties[3]}{nties[4]}$\\var{sum(nties)}$
\n

 

\n

 

\n

Step 2: Next we work out the uncorrected (for ties) Friedman statistic $\\chi_r^2$.

\n

Here:

\n

$t = \\;$ number of treatments i.e. suncreams $\\;=4$

\n

$b=\\;$ number of subjects $\\;=5$.

\n

\\[\\begin{eqnarray*}\\chi_r^2&=& \\frac{12}{b\\times t \\times (t+1)}\\left[\\sum R_i^2 \\right]-\\left\\{3\\times b\\times (t+1)\\right\\}\\\\&=&\\left\\{\\frac{12}{\\var{n}\\times\\var{m}\\times\\var{m+1}}\\left[\\var{surk[0]}^2+\\var{surk[1]}^2+\\var{surk[2]}^2+\\var{surk[3]}^2\\right]\\right\\}-\\left\\{3\\times\\var{n}\\times \\var{m+1}\\right\\}\\\\&=&\\var{fr}\\end{eqnarray*}\\]

\n

 Step 3: Next we calculate the Correction Factor $C$

\n

Only necessary if there are some ties, otherwise $C=1$.

\n

For each tie in a column with $g$ equal values we calculate $\\displaystyle \\frac{g^3-g}{b(t^3-t)}$.

\n

$T$ is the sum of all these values and then the Correction Factor $C= 1-T$. 

\n

So for this example we note  {messtab}

\n

{table(disptab,[])}

\n

Summing over the values {mess1} we find $T=\\var{tscorr} \\Rightarrow C=1- \\var{tscorr}=\\var{1-tscorr}$.

\n

Step 4.

\n

Next we calculate the corrected Friedman statistic allowing for ties.

\n

$ \\displaystyle \\chi_r^{2^*}=\\frac{\\chi_r^{2}}{C} = \\frac{\\var{fr1}}{\\var{1-tscorr}}=\\var{fr}$ to 2 decimal places.

\n

Step 5. Make a decision.

\n

Looking at the table in conjunction with the test statistic we have just worked out, {dec}

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$10\\%$$5\\%$$1\\%$$0.1\\%$
$6.251$$7.815$$11.345$$16.266$
"}, {"name": "Apply Kruskal-Wallis test", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}], "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}], "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

"}], "name": "", "pickQuestions": 0}], "metadata": {"notes": "", "licence": "Creative Commons Attribution 4.0 International", "description": "

Questions on Kruskal-Wallis and Friedman tests.

"}, "type": "exam", "navigation": {"onleave": {"action": "none", "message": ""}, "reverse": true, "browse": true, "showresultspage": "oncompletion", "preventleave": true, "allowregen": true, "showfrontpage": true}, "timing": {"timedwarning": {"action": "none", "message": ""}, "timeout": {"action": "none", "message": ""}, "allowPause": true}, "pickQuestions": 0, "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}], "extensions": ["stats"], "custom_part_types": [], "resources": []}