// Numbas version: exam_results_page_options {"name": "JSXGraph line of best fit plot 2", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"ungrouped_variables": ["tsqovern", "a", "b", "obj", "r1", "r2", "ss", "res", "ssq", "n", "a1", "ch", "spxy", "ls", "tol", "sc", "sxy", "b1", "t"], "parts": [{"gaps": [{"scripts": {}, "type": "numberentry", "marks": 1, "showCorrectAnswer": true, "maxValue": "b+tol", "minValue": "b-tol", "allowFractions": false, "showPrecisionHint": false, "correctAnswerFraction": false}, {"scripts": {}, "type": "numberentry", "marks": 1, "showCorrectAnswer": true, "maxValue": "a+tol", "minValue": "a-tol", "allowFractions": false, "showPrecisionHint": false, "correctAnswerFraction": false}], "stepsPenalty": 0, "prompt": "
Calculate the equation of the best fitting regression line:
\n\\[Y = aX+b.\\] Find $a$ and $b$ to 5 decimal places, then input them below to 3 decimal places. You will use these approximate values in the rest of the question.
\n$a=\\;$[[0]], $b=\\;$[[1]] (both to 3 decimal places.)
\n \n{regressline(r1,r2,min(r1)-10,max(r1)+10,min(r2)-10,max(r2)+10)}
\n \n \n \nYou are given the following information:
\nFirst Test$(X)$ | \n$\\sum x=\\;\\var{t[0]}$ | \n$\\sum x^2=\\;\\var{ssq[0]}$ | \n
---|---|---|
Later Score$(Y)$ | \n$\\sum y=\\;\\var{t[1]}$ | \n$\\sum y^2=\\;\\var{ssq[1]}$ | \n
Also you are given $\\sum xy = \\var{sxy}$.
\nClick on Show steps if you want more information on calculating $a$ and $b$. You will not lose any marks by doing so.
\n", "type": "gapfill", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "steps": [{"prompt": "\n
To find $a$ and $b$ you first find $\\displaystyle b = \\frac{SPXY}{SSX}$ where:
\n$\\displaystyle SPXY=\\sum xy - \\frac{(\\sum x)\\times (\\sum y)}{\\var{n}}$
\n$\\displaystyle SSX=\\sum x^2 - \\frac{(\\sum x)^2}{\\var{n}}$
\nThen $\\displaystyle a = \\frac{1}{\\var{n}}\\left[\\sum y-b \\sum x\\right]$
\nNow go back and fill in the values for $a$ and $b$.
\n\n \n \n ", "type": "information", "showCorrectAnswer": true, "scripts": {}, "marks": 0}]}, {"scripts": {}, "type": "numberentry", "prompt": "\n
What is the predicted Later score for employee $\\var{obj[ch]}$ in the First test?
Use the values of $a$ and $b$ you input above.
\nEnter the predicted Later score here: (to 2 decimal places)
\n \n \n ", "marks": 1, "showCorrectAnswer": true, "correctAnswerFraction": false, "minValue": "ls-0.01", "allowFractions": false, "showPrecisionHint": false, "maxValue": "ls+0.01"}, {"gaps": [{"scripts": {}, "type": "numberentry", "marks": 1, "showCorrectAnswer": true, "maxValue": "res[ch]+0.01", "minValue": "res[ch]-0.01", "allowFractions": false, "showPrecisionHint": false, "correctAnswerFraction": false}], "stepsPenalty": 0, "prompt": "\nUse the result above to calculate the residual value for employee $\\var{obj[ch]}$.
\nClick on Show steps to see what is meant by the residual value if you have forgotten. You will not lose any marks by doing so.
\nResidual value = (to 2 decimal places).[[0]]
\n \n \n ", "type": "gapfill", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "steps": [{"prompt": "\nThe residual value is given by:
\nRESIDUAL = OBSERVED - FITTED.
\nIn this case the observed value for $\\var{obj[ch]}$ is $\\var{r2[ch]}$ and you get the fitted value by feeding the First test value $\\var{r1[ch]}$ into the regression equation.
\n\n \n \n \n ", "type": "information", "showCorrectAnswer": true, "scripts": {}, "marks": 0}]}], "showQuestionGroupNames": false, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "notes": "
21/12/2012:
\nChecked rounding, OK. Added tag cr1.
\nPossible use of scenarios, so added tag sc.
\nThe array r2 generates the regression data which has an inbuilt noise via r1[x]+random(-9..9).
\n26/01/2013:
\nNo advice as yet.
\n13/11/2013:
\nUses Jsxgraph to create the regression line and some interaction with users.
", "description": "Find a regression equation.
\nNow includes a graph of the regression line and another interactive graph gives users the opportunity to move the regression line around. Could be used for allowing users to experiment with what they think the line should be and see how this compares with the calculated line.
"}, "type": "question", "preamble": {"css": "", "js": ""}, "variablesTest": {"condition": "", "maxRuns": 100}, "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "statement": "\nTo monitor its staff appraisal methods, a personnel department compares the results of the tests carried out on employees at their first appraisal with an assessment score of the same individuals two years later. The resulting data are as follows:
\nEmployee | $\\var{obj[0]}$ | $\\var{obj[1]}$ | $\\var{obj[2]}$ | $\\var{obj[3]}$ | $\\var{obj[4]}$ | $\\var{obj[5]}$ | $\\var{obj[6]}$ | $\\var{obj[7]}$ |
---|---|---|---|---|---|---|---|---|
First Test $(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
Later Score $(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
{regfun(r1,r2,max(r1)+10,max(r2)+10)}
\n \n ", "question_groups": [{"questions": [], "name": "", "pickQuestions": 0, "pickingStrategy": "all-ordered"}], "variables": {"sc": {"definition": "r1[ch]", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "sc"}, "ss": {"definition": "[ssq[0]-t[0]^2/n,ssq[1]-t[1]^2/n]", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ss"}, "ssq": {"definition": "[sum(map(x^2,x,r1)),sum(map(x^2,x,r2))]", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ssq"}, "res": {"definition": "map(precround(r2[x]-(a+b*r1[x]),2),x,0..n-1)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "res"}, "b": {"definition": "precround(spxy/ss[0],3)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "b"}, "b1": {"definition": "random(0.25..0.45#0.05)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "b1"}, "t": {"definition": "[sum(r1),sum(r2)]", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "t"}, "sxy": {"definition": "sum(map(r1[x]*r2[x],x,0..n-1))", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "sxy"}, "spxy": {"definition": "sxy-t[0]*t[1]/n", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "spxy"}, "obj": {"definition": "['A','B','C','D','E','F','G','H']", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "obj"}, "n": {"definition": "8", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "n"}, "r1": {"definition": "repeat(round(normalsample(67,8)),n)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "r1"}, "r2": {"definition": "map(round(a1+b1*x+random(-9..9)),x,r1)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "r2"}, "ch": {"definition": "random(0..7)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ch"}, "tol": {"definition": "0.001", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tol"}, "ls": {"definition": "precround(a+b*sc,2)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ls"}, "tsqovern": {"definition": "[t[0]^2/n,t[1]^2/n]", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tsqovern"}, "a": {"definition": "precround(1/n*(t[1]-spxy/ss[0]*t[0]),3)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "a"}, "a1": {"definition": "random(10..20)", "templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "a1"}}, "name": "JSXGraph line of best fit plot 2", "variable_groups": [], "advice": "{regressline(r1,r2,min(r1)-10,max(r1)+10,min(r2)-10,max(r2)+10)}
", "functions": {"regfun": {"definition": "\n var div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n {boundingBox:[-5,maxy,maxx,-5],\n axis:true,\n showNavigation:false,\n grid:false});\n var board = div.board; \n var names = 'ABCDEFGHIJKLMNOP';\n for (j=0;j<8;j++){ board.create('point',[r1[j],r2[j]],{fixed:true, style:3, strokecolor:\"#0000a0\", name:'\\['+names[j]+'\\]'})};\n var regressionPolynomial = JXG.Math.Numerics.regressionPolynomial(1, r1, r2);\n var reg = board.create('functiongraph',[regressionPolynomial],{strokeColor:'black'}); \n for(var i=0;i<8;i++){board.create(\"segment\",[[r1[i],r2[i]],[r1[i],regressionPolynomial(r1[i])]])};\n var regExpression = regressionPolynomial.getTerm();\n var regTeX = Numbas.jme.display.exprToLaTeX(regExpression,[],scope);\n \n t = board.create('text',[10,10,\n function(){ return \"\\\\[r(Y) = \" + regExpression +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \n return div;\n ", "type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["maxx", "number"], ["maxy", "number"]], "language": "javascript"}, "pstdev": {"definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "type": "number", "parameters": [["l", "list"]], "language": "jme"}, "regressline": {"definition": "\n var div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n {boundingBox:[-5,maxy,maxx,-5],\n axis:true,\n showNavigation:false,\n grid:false});\n var board = div.board; \n for (j=0;j<8;j++){ board.create('point',[r1[j],r2[j]],{fixed:true,face:'v'})};\n var a1 = board.create('point',[minx+5,miny+5]);\n var b1 = board.create('point',[minx+7,miny+5]);\n var li=board.create('line',[a1,b1], {straightFirst:false, straightLast:false});\n var a=0;\n var b=0;\n function dr(p){\n p.on('drag',function(){\n a = Numbas.math.niceNumber((b1.Y()-a1.Y())/(b1.X()-a1.X()));\n b = Numbas.math.niceNumber((a1.Y()*b1.X()-a1.X()*b1.Y())/(b1.X()-a1.X()));\n Numbas.exam.currentQuestion.parts[0].gaps[0].display.studentAnswer(a);\n Numbas.exam.currentQuestion.parts[0].gaps[1].display.studentAnswer(b);\n \n })};\n dr(a1);\n dr(b1);\n \n return div;\n \n ", "type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["minx", "number"], ["maxx", "number"], ["miny", "number"], ["maxy", "number"]], "language": "javascript"}}, "tags": ["Jsxgraph", "cr1", "data analysis", "fitted value", "graphs", "interaction", "jsxgraph", "regression", "residual value", "sc", "statistics"], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}