// 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:
\nCouple | \n$\\var{obj[0]}$ | \n$\\var{obj[1]}$ | \n$\\var{obj[2]}$ | \n$\\var{obj[3]}$ | \n$\\var{obj[4]}$ | \n$\\var{obj[5]}$ | \n$\\var{obj[6]}$ | \n$\\var{obj[7]}$ | \n
---|---|---|---|---|---|---|---|---|
Wife $(X)$ | \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
Husband $(Y)$ | \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
\\[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}}\\]
\nNote that $n$ is the number of data points. In this case $\\var{n}$
", "customMarkingAlgorithm": "", "type": "information", "marks": 0, "showFeedbackIcon": true}], "extendBaseMarkingAlgorithm": true, "prompt": "Wife $(X)$ | \n$\\sum x=\\;$[[0]] | \n$\\sum x^2=\\;$[[1]] | \n
---|---|---|
Husband $(Y)$ | \n$\\sum y=\\;$[[2]] | \n$\\sum y^2=\\;$[[3]] | \n
Also find $\\sum xy=\\;$[[4]].
\nHence 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.
\nrebelmaths
", "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;j$\\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\nTo 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}}\\]
\nNote that $n$ is the number of data points. In this case $n=\\var{n}$
\n\nHence
\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/"}]}