// Numbas version: exam_results_page_options {"name": "JSXGraph line of best fit plot 3", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"regfun": {"definition": "\nvar div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n {boundingBox:[-5,maxy,maxx,-5],\n axis:true,\n showNavigation:false,\n grid:false});\nvar board = div.board; \nvar names = 'ABCDEFGHIJKLMNOP';\nfor(j=0;j<8;j++){ board.create('point',[r1[j],r2[j]],{fixed:true, style:3, strokecolor:\"#0000a0\", name:'\\['+names[j]+'\\]'})};\nvar regressionPolynomial = JXG.Math.Numerics.regressionPolynomial(1, r1, r2);\nvar reg = board.create('functiongraph',[regressionPolynomial],{strokeColor:'black'}); \nfor(var i=0;i<8;i++){board.create(\"segment\",[[r1[i],r2[i]],[r1[i],regressionPolynomial(r1[i])]])};\nvar regExpression = regressionPolynomial.getTerm();\nvar regTeX = Numbas.jme.display.exprToLaTeX(regExpression,[],scope);\n\nt = board.create('text',[10,20,\n function(){ return \"\\\\[r(Y) = \" + regExpression +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nt1 = board.create('text',[10,15,\n function(){ return \"\\\\[SSE = \" + sumr +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nt2 = board.create('text',[10,10,\n function(){ return \"\\\\[R^2 = \" + rsquared +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nreturn div;\n\n", "type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["maxx", "number"], ["maxy", "number"], ["rsquared", "number"], ["sumr", "number"]], "language": "javascript"}, "pstdev": {"definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "type": "number", "parameters": [["l", "list"]], "language": "jme"}, "regressline": {"definition": "\nvar div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n {boundingBox:[-5,maxy,maxx,-5],\n axis:true,\n showNavigation:false,\n grid:false});\nvar board = div.board; \nfor (j=0;j<8;j++){ board.create('point',[r1[j],r2[j]],{fixed:true,face:'v'})};\nvar a1 = board.create('point',[minx+5,miny+5]);\nvar b1 = board.create('point',[minx+7,miny+5]);\nvar html = $(question.display.html);\nfunction updr(a,b){\n var s=0;\n for(var i=0;i<8;i++){\n s=s+Math.pow(r2[i]-a*r1[i]-b,2);}\n s=Numbas.math.niceNumber(Numbas.math.precround(s,2));\n html.find('#rsquared').text(s);}\nvar li=board.create('line',[a1,b1], {straightFirst:false, straightLast:false, fixed: true});\nvar a=0;\nvar b=0;\nfunction 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 updr(a,b);\n })};\ndr(a1);\ndr(b1);\n\nreturn div;\n\n\n", "type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["minx", "number"], ["maxx", "number"], ["miny", "number"], ["maxy", "number"]], "language": "javascript"}}, "ungrouped_variables": ["ch", "b1", "sxy", "res", "spxy", "ls", "tol", "tsqovern", "ssq", "sumr", "a1", "varreg2", "varreg1", "a", "b", "obj", "r1", "r2", "ss", "n", "t", "sc", "rsquared"], "name": "JSXGraph line of best fit plot 3", "tags": ["cr1", "data analysis", "fitted value", "graphs", "interaction", "Jsxgraph", "jsxgraph", "non interactive html tag", "regression", "residual value", "sc", "SSE", "statistics"], "advice": "", "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "parts": [{"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

{regressline(r1,r2,min(r1)-10,max(r1)+10,min(r2)-10,max(r2)+10)}

\n

SSE for interactive line:

\n

SSE for fitted regression line: {sumr}

\n

\n

\n

You are given the following information:

\n\n\n\n\n\n\n\n\n\n\n\n
First Test$(X)$$\\sum x=\\;\\var{t[0]}$$\\sum x^2=\\;\\var{ssq[0]}$
Later Score$(Y)$$\\sum y=\\;\\var{t[1]}$$\\sum y^2=\\;\\var{ssq[1]}$
\n

Also you are given $\\sum xy = \\var{sxy}$.

\n

Click on Show steps if you want more information on calculating $a$ and $b$. You will not lose any marks by doing so.

\n

 

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"allowFractions": false, "variableReplacements": [], "maxValue": "b+tol", "minValue": "b-tol", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": false, "variableReplacements": [], "maxValue": "a+tol", "minValue": "a-tol", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}], "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}}$

\n

Then $\\displaystyle a = \\frac{1}{\\var{n}}\\left[\\sum y-b \\sum x\\right]$

\n

Now go back and fill in the values for $a$ and $b$.

\n

 

\n \n\n \n", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "marks": 0, "scripts": {}, "showCorrectAnswer": true, "type": "gapfill"}, {"prompt": "

What is the predicted Later score for employee $\\var{obj[ch]}$ in the First test?

\n

Use the values of $a$ and $b$ you input above.

\n

Enter the predicted Later score here: (to 2 decimal places)

", "allowFractions": false, "variableReplacements": [], "maxValue": "ls+0.01", "minValue": "ls-0.01", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"stepsPenalty": 0, "prompt": "

Use the result above to calculate the residual value for employee $\\var{obj[ch]}$.

\n

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

\n

Residual value =  (to 2 decimal places).[[0]]

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"allowFractions": false, "variableReplacements": [], "maxValue": "res[ch]+0.01", "minValue": "res[ch]-0.01", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}], "steps": [{"prompt": "\n

The residual value is given by:

\n

RESIDUAL = OBSERVED - FITTED.

\n

In 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 \n", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "marks": 0, "scripts": {}, "showCorrectAnswer": true, "type": "gapfill"}], "statement": "

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

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Employee$\\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)$$\\var{r1[0]}$$\\var{r1[1]}$$\\var{r1[2]}$$\\var{r1[3]}$$\\var{r1[4]}$$\\var{r1[5]}$$\\var{r1[6]}$$\\var{r1[7]}$
Later Score $(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

\n

\n

{regfun(r1,r2,max(r1)+10,max(r2)+10,rsquared,sumr)}

\n

", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"css": "", "js": ""}, "variables": {"ch": {"definition": "random(0..7)", "templateType": "anything", "group": "Ungrouped variables", "name": "ch", "description": ""}, "b1": {"definition": "random(0.25..0.45#0.05)", "templateType": "anything", "group": "Ungrouped variables", "name": "b1", "description": ""}, "sxy": {"definition": "sum(map(r1[x]*r2[x],x,0..n-1))", "templateType": "anything", "group": "Ungrouped variables", "name": "sxy", "description": ""}, "res": {"definition": "map(precround(r2[x]-(a+b*r1[x]),2),x,0..n-1)", "templateType": "anything", "group": "Ungrouped variables", "name": "res", "description": ""}, "spxy": {"definition": "sxy-t[0]*t[1]/n", "templateType": "anything", "group": "Ungrouped variables", "name": "spxy", "description": ""}, "ls": {"definition": "precround(a+b*sc,2)", "templateType": "anything", "group": "Ungrouped variables", "name": "ls", "description": ""}, "tol": {"definition": "0.001", "templateType": "anything", "group": "Ungrouped variables", "name": "tol", "description": ""}, "a": {"definition": "precround(1/n*(t[1]-spxy/ss[0]*t[0]),3)", "templateType": "anything", "group": "Ungrouped variables", "name": "a", "description": ""}, "ssq": {"definition": "[sum(map(x^2,x,r1)),sum(map(x^2,x,r2))]", "templateType": "anything", "group": "Ungrouped variables", "name": "ssq", "description": ""}, "sumr": {"definition": "precround(sum(map(res[x]^2,x,0..n-1)),3)", "templateType": "anything", "group": "Ungrouped variables", "name": "sumr", "description": ""}, "a1": {"definition": "random(10..20)", "templateType": "anything", "group": "Ungrouped variables", "name": "a1", "description": ""}, "varreg2": {"definition": "rsquared*ss[1]/n", "templateType": "anything", "group": "Ungrouped variables", "name": "varreg2", "description": ""}, "varreg1": {"definition": "variance(list(vector(r2)-vector(res)))", "templateType": "anything", "group": "Ungrouped variables", "name": "varreg1", "description": ""}, "tsqovern": {"definition": "[t[0]^2/n,t[1]^2/n]", "templateType": "anything", "group": "Ungrouped variables", "name": "tsqovern", "description": ""}, "b": {"definition": "precround(spxy/ss[0],3)", "templateType": "anything", "group": "Ungrouped variables", "name": "b", "description": ""}, "obj": {"definition": "['A','B','C','D','E','F','G','H']", "templateType": "anything", "group": "Ungrouped variables", "name": "obj", "description": ""}, "r1": {"definition": "repeat(round(normalsample(67,8)),n)", "templateType": "anything", "group": "Ungrouped variables", "name": "r1", "description": ""}, "r2": {"definition": "map(round(a1+b1*x+random(-9..9)),x,r1)", "templateType": "anything", "group": "Ungrouped variables", "name": "r2", "description": ""}, "ss": {"definition": "[ssq[0]-t[0]^2/n,ssq[1]-t[1]^2/n]", "templateType": "anything", "group": "Ungrouped variables", "name": "ss", "description": ""}, "n": {"definition": "8", "templateType": "anything", "group": "Ungrouped variables", "name": "n", "description": ""}, "t": {"definition": "[sum(r1),sum(r2)]", "templateType": "anything", "group": "Ungrouped variables", "name": "t", "description": ""}, "sc": {"definition": "r1[ch]", "templateType": "anything", "group": "Ungrouped variables", "name": "sc", "description": ""}, "rsquared": {"definition": "precround(spxy^2/(ss[0]*ss[1]),3)", "templateType": "anything", "group": "Ungrouped variables", "name": "rsquared", "description": ""}}, "metadata": {"notes": "

21/12/2012:

\n

Checked rounding, OK. Added tag cr1.

\n

Possible use of scenarios, so added tag sc.

\n

The array r2 generates the regression data which has an inbuilt noise via r1[x]+random(-9..9).

\n

26/01/2013:

\n

No advice as yet.

\n

 13/11/2013:

\n

Uses Jsxgraph to create the regression line and some interaction with users.

\n

27/11/2013:

\n

Added updated SSE and also the value of $R^2$ for the fitted regression line.

\n

Uses technique from https://numbas.mathcentre.ac.uk/question/2239/update-a-non-interactive-html-tag-based-on-a-value-from-a-jsxgraph-diagram/

", "description": "

Find a regression equation.

\n

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

\n

Also includes an updated SSE to see how the sum of the squares of the residuals varies with the regression line.

", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}]}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}