// Numbas version: finer_feedback_settings {"name": "BES220 : Linear regression (employe test scores)", "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('400px','400px',\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,['all'],scope);\n\nt = board.create('text',[10,50,\n function(){ return \"\\\\[r(Y) = \" + regTeX +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nt1 = board.create('text',[10,45,\n function(){ return \"\\\\[SSE = \" + sumr +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nt2 = board.create('text',[10,40,\n function(){ return \"\\\\[R^2 = \" + rsquared +'\\\\]';}\n ],\n {strokeColor:'black',fontSize:18}); \nreturn div;\n\n", "type": "html", "language": "javascript", "parameters": [["r1", "list"], ["r2", "list"], ["maxx", "number"], ["maxy", "number"], ["rsquared", "number"], ["sumr", "number"]]}, "pstdev": {"definition": "sqrt(abs(l)/(abs(l)-1))*stdev(l)", "type": "number", "language": "jme", "parameters": [["l", "list"]]}, "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[1].display.studentAnswer(a);\n Numbas.exam.currentQuestion.parts[0].gaps[0].display.studentAnswer(b);\n updr(a,b);\n })};\ndr(a1);\ndr(b1);\n\nreturn div;\n\n\n", "type": "html", "language": "javascript", "parameters": [["r1", "list"], ["r2", "list"], ["minx", "number"], ["maxx", "number"], ["miny", "number"], ["maxy", "number"]]}}, "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", "x_bar", "y_bar", "s_x", "s_y", "R", "b_1", "b_0"], "name": "BES220 : Linear regression (employe test scores)", "tags": [], "preamble": {"css": "", "js": ""}, "advice": "", "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "parts": [{"prompt": "

Manually fit the best fitting regression line:

\n

\\[\\hat{y} = b_{0} + b_{1}x\\]

\n

by clicking-on and dragging the points marked I and J in the figure below. The objective is to minimise the sum of the residuals squared (SSE), which is shown below the figure for your fitted line.

\n

Met die hand pas die beste regressielyn:

\n

\\[\\hat{y} = b_{0} + b_{1}x\\]

\n

deur op die punte gemerk I en J in die figuur hieronder te druk en dit rond te sleep. Die doel is om die som van die residue kwadraat (SSE), wat onder die figuur vir jou toegerus lyn getoon word te minimeer.

\n

$b_0=\\;$[[0]]   ,   $b_1=\\;$[[1]]  

\n

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

\n

SSE for interactive line:

\n

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"allowFractions": false, "variableReplacements": [], "maxValue": "b_0+0.5", "minValue": "b_0-0.5", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": "1", "type": "numberentry"}, {"allowFractions": false, "variableReplacements": [], "maxValue": "b_1+0.5", "minValue": "b_1-0.5", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": "1", "type": "numberentry"}], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "gapfill"}, {"prompt": "

Calculate the correlation cofficient, $R$, between the first and second test score for the eigth employees using the following formula:

\n

$R = \\frac{1}{n-1}\\sum_{i=1}^{n}\\frac{x_i - \\bar{x}}{s_x}\\frac{y_i - \\bar{y}}{s_y}$.

\n

First calculate the average, $\\bar{x}$, and standard deviation, $s_x$, for the first score, $x$, then calculate the average, $\\bar{y}$, and standard deviation, $s_y$, for the second score, $y$. Thereafter calculate the correlation cofficient $R$.

\n

Bereken die korrelasie gebeurlikheidskoëffisiënt, $R$, tussen die eerste en tweede toetstelling vir die agt werknemers met behulp van die volgende formule:

\n

$R = \\frac{1}{n-1}\\sum_{i=1}^{n}\\frac{x_i - \\bar{x}}{s_x}\\frac{y_i - \\bar{y}}{s_y}$.

\n

Bereken eers die gemiddelde, $\\bar{x}$, en standaardafwyking, $s_x$, vir die eerste telling, $x$, bereken dan die gemiddelde, $\\bar{y}$, en standaardafwyking, $s_y$, vir die tweede telling, $y$. Daarna bereken die korrelasie gebeurlikheidskoëffisiënt $R$.

\n

$\\bar{x} =$ [[0]] , $s_x =$ [[1]]

\n

$\\bar{y} =$ [[2]] , $s_y =$ [[3]]

\n

$R =$ [[4]]

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [], "maxValue": "x_bar + tol", "strictPrecision": false, "minValue": "x_bar - tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "1", "showPrecisionHint": true, "type": "numberentry"}, {"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [], "maxValue": "s_x + tol", "strictPrecision": false, "minValue": "s_x - tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "1", "showPrecisionHint": true, "type": "numberentry"}, {"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [], "maxValue": "y_bar + tol", "strictPrecision": false, "minValue": "y_bar - tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "1", "showPrecisionHint": true, "type": "numberentry"}, {"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [], "maxValue": "s_y + tol", "strictPrecision": false, "minValue": "s_y - tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "1", "showPrecisionHint": true, "type": "numberentry"}, {"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [{"variable": "x_bar", "part": "p1g0", "must_go_first": false}, {"variable": "s_x", "part": "p1g1", "must_go_first": false}, {"variable": "y_bar", "part": "p1g2", "must_go_first": false}, {"variable": "s_y", "part": "p1g3", "must_go_first": false}], "maxValue": "R + tol", "strictPrecision": false, "minValue": "R - tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "2", "showPrecisionHint": true, "type": "numberentry"}], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "gapfill"}, {"stepsPenalty": 0, "prompt": "

Calculate the equation of the best fitting regression line:

\n

\\[\\hat{y} = b_{0} + b_{1}x.\\]

\n

Find $b_0$ and $b_1$. 

\n

Click on Show steps if you want more information on calculating $b_0$ and $b_1$. You will not lose any marks by doing so, and be sure to check your results against your manually fitted line from Part a.

\n

Bereken die vergelyking van die beste pas regressielyn:

\n

\\[\\hat{y} = b_{0} + b_{1}x.\\]

\n

Vind $b_0$ en $b_1$ tot vyf desimale plekke, en gee jou antwoord tot 3 desimale plekke. Jy sal hierdie benaderde waardes gebruik in die res van die vraag.

\n

Klik op \"Show steps\" as jy meer inligting oor die berekening van $b_0 $ en $b_1$ benodig. Jy sal geen punte verloor deur dit te doen nie, en maak seker om jou uitslae teen jou hand toegepaste lyn van Deel A te vergelyk.

\n

$b_1=\\;$[[0]]    ,   $b_0=\\;$[[1]] 

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "steps": [{"prompt": "

To find $b_0$ and $b_1$, use the following formulas:

\n

Om $b_0$ en $b_1$ te kry gebruik die volgende formules. Bereken dan die parameters soos volg:

\n

$b_1 = \\frac{s_y}{s_x}R$ 

\n

$b_0 = \\bar{y} - b_1\\bar{x}$ 

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "gaps": [{"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [{"variable": "R", "part": "p1g4", "must_go_first": false}, {"variable": "s_x", "part": "p1g1", "must_go_first": false}, {"variable": "s_y", "part": "p1g3", "must_go_first": false}], "maxValue": "b_1+tol", "strictPrecision": false, "minValue": "b_1-tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "2", "showPrecisionHint": true, "type": "numberentry"}, {"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [{"variable": "x_bar", "part": "p1g0", "must_go_first": false}, {"variable": "y_bar", "part": "p1g2", "must_go_first": false}, {"variable": "b_1", "part": "p2g0", "must_go_first": false}], "maxValue": "b_0+tol", "strictPrecision": false, "minValue": "b_0-tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "2", "showPrecisionHint": true, "type": "numberentry"}], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "gapfill"}, {"precisionType": "dp", "prompt": "

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

\n

Use your best fitted regression line from the previous part.

\n

Wat is die voorspelde \"Later score\" vir werknemer $\\var{obj[ch]}$ gebaseer op die eerste toets?

\n

Gebruik jou best gepaste regressielyn van die vorige deel.

", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [{"variable": "b_0", "part": "p2g1", "must_go_first": false}, {"variable": "b_1", "part": "p2g0", "must_go_first": false}], "maxValue": "ls+tol", "strictPrecision": false, "minValue": "ls-tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": 1, "showPrecisionHint": true, "type": "numberentry"}, {"stepsPenalty": 0, "prompt": "

Calculate the residual value for employee $\\var{obj[ch]}$. Note that if Part (d) is incorrect, this part will also be incorrect.

\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

Bereken die reswaarde vir werknemer $\\var{obj[ch]}$. Let op dat indien Deel (d) verkeerd is, die deel ook verkeerd gemerk sal word.

\n

Klik op \"Show steps\" om te sien wat bedoel word met die reswaarde as jy vergeet het. Jy sal geen punte verloor deur dit te doen nie.

\n

Residual value/reswaarde =  [[0]]

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "steps": [{"prompt": "

The residual of the $i^\\text{th}$ value is given by:

\n

$e_{i} = y_i - \\hat{y}_i$.

\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

Diereswaarde van die$i^\\text{th}$ waarde word gegee deur:

\n

$e_{i} = y_i - \\hat{y}_i$.

\n

In hierdie geval is die waargeneem waarde vir $\\var{obj[ch]}$ gelyk aan $\\var{r2[ch]}$ en mens kry die toegerusde waarde deur die \"First test\" waarde $\\var{r2[ch]}$ in die regressievergelyking in te voer.

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "gaps": [{"precisionType": "dp", "precisionMessage": "

You have not given your answer to the correct precision.

", "allowFractions": false, "variableReplacements": [{"variable": "b_1", "part": "p2g0", "must_go_first": false}, {"variable": "b_0", "part": "p2g1", "must_go_first": false}], "maxValue": "res[ch]+tol", "strictPrecision": false, "minValue": "res[ch]-tol", "variableReplacementStrategy": "originalfirst", "precisionPartialCredit": 0, "correctAnswerFraction": false, "showCorrectAnswer": true, "precision": "3", "scripts": {}, "marks": "2", "showPrecisionHint": true, "type": "numberentry"}], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "gapfill"}], "extensions": ["stats", "jsxgraph"], "statement": "

To monitor its staff appraisal methods, the personnel department of {company_name} 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

Om sy personeel evaluering metodes te monitor, vergelyk die personeel departement van {company_name} die resultate van toetse wat werknemers by hul eerste beoordeling uitgevoer het met 'n aanslag telling van dieselfde individue twee jaar later. Die gevolglike data is soos volg:

\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

Answer all the following questions, and unless otherwise stated, round your answer to THREE (3) decimal values.

\n

Beantwoord al die volgende vrae, en tensy anders vermeld, rond jou antwoord tot DRIE (3) desimale waardes.

", "variable_groups": [{"variables": ["company_names", "company_name"], "name": "Unnamed group"}], "variablesTest": {"maxRuns": 100, "condition": ""}, "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": ""}, "b_1": {"definition": "s_y/s_x*R", "templateType": "anything", "group": "Ungrouped variables", "name": "b_1", "description": ""}, "b_0": {"definition": "y_bar - b_1*x_bar", "templateType": "anything", "group": "Ungrouped variables", "name": "b_0", "description": ""}, "sxy": {"definition": "sum(map(r1[x]*r2[x],x,0..n-1))", "templateType": "anything", "group": "Ungrouped variables", "name": "sxy", "description": ""}, "y_bar": {"definition": "mean(r2)", "templateType": "anything", "group": "Ungrouped variables", "name": "y_bar", "description": ""}, "s_y": {"definition": "stdev(r2,true)", "templateType": "anything", "group": "Ungrouped variables", "name": "s_y", "description": ""}, "res": {"definition": "map(r2[x]-(b_0+b_1*r1[x]),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": ""}, "company_name": {"definition": "random(company_names)", "templateType": "anything", "group": "Unnamed group", "name": "company_name", "description": ""}, "tol": {"definition": "0.01", "templateType": "anything", "group": "Ungrouped variables", "name": "tol", "description": ""}, "ls": {"definition": "b_0+b_1*sc", "templateType": "anything", "group": "Ungrouped variables", "name": "ls", "description": ""}, "a": {"definition": "1/n*(t[1]-spxy/ss[0]*t[0])", "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": ""}, "R": {"definition": "1/(n-1)*sum(map((r1[x] - x_bar)/s_x*(r2[x] - y_bar)/s_y,x,0..n-1))", "templateType": "anything", "group": "Ungrouped variables", "name": "R", "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": "spxy/ss[0]", "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": ""}, "x_bar": {"definition": "mean(r1)", "templateType": "anything", "group": "Ungrouped variables", "name": "x_bar", "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": ""}, "s_x": {"definition": "stdev(r1,true)", "templateType": "anything", "group": "Ungrouped variables", "name": "s_x", "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": ""}, "company_names": {"definition": "[ \"Hardwork, Inc.\", \"Thriftforth\\'s\", \"Pennykeep & Co.\", \"I. Save and Sons\" ]", "templateType": "list of strings", "group": "Unnamed group", "name": "company_names", "description": ""}}, "metadata": {"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": "Elias Jakobus Willemse", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/846/"}]}]}], "contributors": [{"name": "Elias Jakobus Willemse", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/846/"}]}