// Numbas version: finer_feedback_settings {"name": "Simon's copy of Pearson1", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"tags": [], "variables": {"spxy": {"description": "", "templateType": "anything", "name": "spxy", "definition": "sxy-t[0]*t[1]/n", "group": "Ungrouped variables"}, "ssd": {"description": "", "templateType": "anything", "name": "ssd", "definition": "sum(map(x^2,x,d))", "group": "Ungrouped variables"}, "rr1": {"description": "", "templateType": "anything", "name": "rr1", "definition": "rk(r1)", "group": "Ungrouped variables"}, "vs": {"description": "", "templateType": "anything", "name": "vs", "definition": "switch(spcoef >=0.952,[1,0,0,0,0],spcoef>=0.881,[0,1,0,0,0],spcoef>=0.738,[0,0,1,0,0],spcoef>=0.643,[0,0,0,1,0],[0,0,0,0,1])", "group": "Ungrouped variables"}, "spcoef": {"description": "", "templateType": "anything", "name": "spcoef", "definition": "precround(6*ssd/(n*(n^2-1)),3)", "group": "Ungrouped variables"}, "t": {"description": "", "templateType": "anything", "name": "t", "definition": "[sum(r1),sum(r2)]", "group": "Ungrouped variables"}, "d": {"description": "", "templateType": "anything", "name": "d", "definition": "list(vector(rr1)-vector(rr2))", "group": "Ungrouped variables"}, "ss": {"description": "", "templateType": "anything", "name": "ss", "definition": "[ssq[0]-t[0]^2/n,ssq[1]-t[1]^2/n]", "group": "Ungrouped variables"}, "rr2": {"description": "", "templateType": "anything", "name": "rr2", "definition": "rk(r2)", "group": "Ungrouped variables"}, "tsqovern": {"description": "", "templateType": "anything", "name": "tsqovern", "definition": "[t[0]^2/n,t[1]^2/n]", "group": "Ungrouped variables"}, "obj": {"description": "", "templateType": "anything", "name": "obj", "definition": "['A','B','C','D','E','F','G','H']", "group": "Ungrouped variables"}, "k": {"description": "", "templateType": "anything", "name": "k", "definition": "3", "group": "Ungrouped variables"}, "ssq": {"description": "", "templateType": "anything", "name": "ssq", "definition": "[sum(map(x^2,x,r1)),sum(map(x^2,x,r2))]", "group": "Ungrouped variables"}, "sxy": {"description": "", "templateType": "anything", "name": "sxy", "definition": "sum(map(r1[x]*r2[x],x,0..n-1))", "group": "Ungrouped variables"}, "corrcoef": {"description": "", "templateType": "anything", "name": "corrcoef", "definition": "precround(spxy/sqrt(ss[0]*ss[1]),2)", "group": "Ungrouped variables"}, "r2": {"description": "", "templateType": "anything", "name": "r2", "definition": "tesarr(r1,darr(n,m,[random(1..m)]),9,m)", "group": "Ungrouped variables"}, "tol": {"description": "", "templateType": "anything", "name": "tol", "definition": "0.01", "group": "Ungrouped variables"}, "r1": {"description": "", "templateType": "anything", "name": "r1", "definition": "darr(n,m,[random(1..20)])", "group": "Ungrouped variables"}, "m": {"description": "", "templateType": "anything", "name": "m", "definition": "20", "group": "Ungrouped variables"}, "n": {"description": "", "templateType": "anything", "name": "n", "definition": "8", "group": "Ungrouped variables"}, "v": {"description": "", "templateType": "anything", "name": "v", "definition": "switch(corrcoef >=0.905,[1,0,0,0,0],corrcoef>=0.834,[0,1,0,0,0],corrcoef>=0.707,[0,0,1,0,0],corrcoef>=0.621,[0,0,0,1,0],[0,0,0,0,1])", "group": "Ungrouped variables"}}, "statement": "

It is well known that similarity in attitudes, beliefs and interests plays an important role in interpersonal attraction. A researcher developed a questionnaire which was completed by 8 married couples. One question sought to place each individual on a 20 point scale in which low scores represent liberal attitudes and high scores represent conservative attitudes. The data were:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Couple$\\var{obj[0]}$$\\var{obj[1]}$$\\var{obj[2]}$$\\var{obj[3]}$$\\var{obj[4]}$$\\var{obj[5]}$$\\var{obj[6]}$$\\var{obj[7]}$
Wife $(X)$$\\var{r1[0]}$$\\var{r1[1]}$$\\var{r1[2]}$$\\var{r1[3]}$$\\var{r1[4]}$$\\var{r1[5]}$$\\var{r1[6]}$$\\var{r1[7]}$
Husband $(Y)$$\\var{r2[0]}$$\\var{r2[1]}$$\\var{r2[2]}$$\\var{r2[3]}$$\\var{r2[4]}$$\\var{r2[5]}$$\\var{r2[6]}$$\\var{r2[7]}$
\n

", "parts": [{"gaps": [{"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "maxValue": "t[0]", "showCorrectAnswer": true, "variableReplacements": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "minValue": "t[0]", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "extendBaseMarkingAlgorithm": true, "unitTests": [], "type": "numberentry", "marks": "1", "showFeedbackIcon": true}, {"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "maxValue": "ssq[0]", "showCorrectAnswer": true, "variableReplacements": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "minValue": "ssq[0]", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "extendBaseMarkingAlgorithm": true, "unitTests": [], "type": "numberentry", "marks": "1", "showFeedbackIcon": true}, {"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "maxValue": "t[1]", "showCorrectAnswer": true, "variableReplacements": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "minValue": "t[1]", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "extendBaseMarkingAlgorithm": true, "unitTests": [], "type": "numberentry", "marks": "1", "showFeedbackIcon": true}, {"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "maxValue": "ssq[1]", "showCorrectAnswer": true, "variableReplacements": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "minValue": "ssq[1]", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "extendBaseMarkingAlgorithm": true, "unitTests": [], "type": "numberentry", "marks": "1", "showFeedbackIcon": true}, {"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "maxValue": "sxy", "showCorrectAnswer": true, "variableReplacements": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "minValue": "sxy", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "extendBaseMarkingAlgorithm": true, "unitTests": [], "type": "numberentry", "marks": "1", "showFeedbackIcon": true}, {"mustBeReduced": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "showCorrectAnswer": true, "precisionPartialCredit": 0, "correctAnswerFraction": false, "precision": "2", "notationStyles": ["plain", "en", "si-en"], "unitTests": [], "precisionType": "dp", "precisionMessage": "You have not given your answer to the correct precision.", "marks": "2", "minValue": "corrcoef", "type": "numberentry", "maxValue": "corrcoef", "showFeedbackIcon": true, "variableReplacements": [], "customMarkingAlgorithm": "", "mustBeReducedPC": 0, "scripts": {}, "allowFractions": false, "extendBaseMarkingAlgorithm": true, "strictPrecision": true, "showPrecisionHint": false}], "variableReplacementStrategy": "originalfirst", "stepsPenalty": 0, "showCorrectAnswer": true, "sortAnswers": false, "variableReplacements": [], "customMarkingAlgorithm": "", "scripts": {}, "steps": [{"scripts": {}, "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "unitTests": [], "showCorrectAnswer": true, "extendBaseMarkingAlgorithm": true, "prompt": "

\\[r=\\frac{n\\Sigma xy -\\Sigma x \\Sigma y}{\\sqrt{n\\Sigma x^2-(\\Sigma x)^2}\\sqrt{n\\Sigma y^2-(\\Sigma y)^2}}\\]

\n

Note that $n$ is the number of data points. In this case $\\var{n}$

", "customMarkingAlgorithm": "", "type": "information", "marks": 0, "showFeedbackIcon": true}], "extendBaseMarkingAlgorithm": true, "prompt": "\n\n\n\n\n\n\n\n\n\n\n\n\n
Wife $(X)$$\\sum x=\\;$[[0]]$\\sum x^2=\\;$[[1]]
Husband $(Y)$$\\sum y=\\;$[[2]]$\\sum y^2=\\;$[[3]]
\n

Also find $\\sum xy=\\;$[[4]]. 

\n

Hence calculate the Pearson correlation coefficient $r$ correct to 2 decimal places:

\n

$r=\\;$[[5]]

\n

 

", "unitTests": [], "type": "gapfill", "marks": 0, "showFeedbackIcon": true}], "variable_groups": [], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "metadata": {"description": "

Calculate the Pearson correlation coefficient on paired data and comment on the significance.

\n

rebelmaths

", "licence": "Creative Commons Attribution 4.0 International"}, "functions": {"marr": {"type": "number", "language": "jme", "definition": "if(length(a)=2,max(a[0],a[1]),max(a[0],marr(a[1..length(a)])))", "parameters": [["a", "list"]]}, "rk": {"type": "list", "language": "javascript", "definition": "\n\t\t\t /*This gives the ranking of the entries in a, c counts the ties */\n\t\t\t var out = [];\n\t\t\t for(var j=0;ja[i]){s+=1;}\n\t\t\t else\n\t\t\t if(a[j]==a[i]){c+=1;}\n\t\t\t }\n\t\t\t out[j]=(2*s+c+1)/2;\n\t\t\t }\n\t\t\t return out;\n\t\t\t \n\t\t\t", "parameters": [["a", "list"]]}, "darr": {"type": "list", "language": "jme", "definition": "if(n=1,a,darr(n-1,m,[random(1..m except a)]+a))", "parameters": [["n", "number"], ["m", "number"], ["a", "list"]]}, "pstdev": {"type": "number", "language": "jme", "definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "parameters": [["l", "list"]]}, "tesarr": {"type": "list", "language": "jme", "definition": "if(marr(map(abs(x),x,list(vector(a)-vector(b))))$\\sum x = \\var{r1[0]}+\\var{r1[1]}+\\var{r1[2]}+ ... = \\var{t[0]}$

\n

$\\sum x^2 = \\var{r1[0]}^2+\\var{r1[1]}^2+\\var{r1[2]}^2+ ... = \\var{ssq[0]}$

\n

$\\sum y = \\var{r2[0]}+\\var{r2[1]}+\\var{r2[2]}+ ... = \\var{t[1]}$

\n

$\\sum y^2 = \\var{r2[0]}^2+\\var{r2[1]}^2+\\var{r2[2]}^2+ ... = \\var{ssq[1]}$

\n

$\\sum xy = (\\var{r1[0]}\\times\\var{r2[0]})+(\\var{r1[1]}\\times\\var{r2[1]})+(\\var{r1[2]}\\times\\var{r2[2]})+...=\\var{sxy}$

\n

\n

\n

To calculate the Pearson correlation coefficient $r$ we use the formula:

\n

\\[r=\\frac{n\\Sigma xy -\\Sigma x \\Sigma y}{\\sqrt{n\\Sigma x^2-(\\Sigma x)^2}\\sqrt{n\\Sigma y^2-(\\Sigma y)^2}}\\]

\n

Note that $n$ is the number of data points. In this case $n=\\var{n}$

\n

\n

Hence

\n

$r=\\frac{n\\Sigma xy -\\Sigma x \\Sigma y}{\\sqrt{n\\Sigma x^2-(\\Sigma x)^2}\\sqrt{n\\Sigma y^2-(\\Sigma y)^2}}$

\n

$r=\\frac{\\var{n}\\times\\var{sxy} -\\var{t[0]}\\times\\var{t[1]}}{\\sqrt{\\var{n}\\times\\var{ssq[0]}-(\\var{t[0]})^2}\\sqrt{\\var{n}\\times\\var{ssq[1]}-(\\var{t[1]})^2}} = \\var{corrcoef}$

\n

", "preamble": {"js": "", "css": ""}, "variablesTest": {"maxRuns": 100, "condition": ""}, "extensions": ["stats"], "name": "Simon's copy of Pearson1", "type": "question", "contributors": [{"name": "Julie Crowley", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/113/"}, {"name": "Simon Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3148/"}]}]}], "contributors": [{"name": "Julie Crowley", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/113/"}, {"name": "Simon Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3148/"}]}