// Numbas version: finer_feedback_settings {"name": "Gareth's copy of BES220: Find regression equation and correlation coefficient", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"ungrouped_variables": ["ch", "prediction", "b1", "owner", "sxy", "res", "spxy", "ls", "tol", "tcorr", "tsqovern", "ssq", "sumr", "thisval", "a1", "pub", "corr", "a", "b", "obj", "r1", "r2", "ss", "tol1", "n", "beverage", "t", "sc", "rsquared"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "advice": "

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

", "metadata": {"description": "

Find a regression equation given 12 months data on temperature and sales of a drink. 

", "licence": "Creative Commons Attribution 4.0 International"}, "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"css": "", "js": ""}, "parts": [{"scripts": {}, "type": "gapfill", "marks": 0, "gaps": [{"notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "marks": 1, "showFeedbackIcon": true, "correctAnswerStyle": "plain", "minValue": "corr-tol1", "variableReplacementStrategy": "originalfirst", "allowFractions": false, "scripts": {}, "variableReplacements": [], "maxValue": "corr+tol1", "correctAnswerFraction": false, "showCorrectAnswer": true}], "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "prompt": "

Calculate the sample correlation coefficient $r$ for these data:

\n

$r=\\;$[[0]] (enter to 2 decimal places).

", "variableReplacements": []}, {"scripts": {}, "type": "gapfill", "marks": 0, "gaps": [{"notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "marks": 1, "showFeedbackIcon": true, "correctAnswerStyle": "plain", "minValue": "b-tol", "variableReplacementStrategy": "originalfirst", "allowFractions": false, "scripts": {}, "variableReplacements": [], "maxValue": "b+tol", "correctAnswerFraction": false, "showCorrectAnswer": true}, {"notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "marks": 1, "showFeedbackIcon": true, "correctAnswerStyle": "plain", "minValue": "a-tol", "variableReplacementStrategy": "originalfirst", "allowFractions": false, "scripts": {}, "variableReplacements": [], "maxValue": "a+tol", "correctAnswerFraction": false, "showCorrectAnswer": true}], "showFeedbackIcon": true, "stepsPenalty": 0, "steps": [{"scripts": {}, "type": "information", "marks": 0, "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "prompt": "

To find $\\beta_0$ and $\\beta_1$ you first find  $\\displaystyle \\beta_1 = \\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 \\beta_0 = \\frac{1}{\\var{n}}\\left[\\sum y-\\beta_1 \\sum x\\right]$

\n

Now go back and fill in the values for $\\beta_0$ and $\\beta_1$.

", "variableReplacements": []}], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "prompt": "

Calculate the equation of the best fitting regression line.

\n

\\[Y = \\beta_0 + \\beta_1X.\\] Find $\\beta_0$ and $\\beta_1$ 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

$\\beta_1=\\;$[[0]],      $\\beta_0=\\;$[[1]] (enter both to 3 decimal places).

\n

You can experiment by dragging the points A and B around to see if you can get close to the regression line. 

\n

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

\n

\n

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

\n

 

", "variableReplacements": []}, {"scripts": {}, "type": "gapfill", "marks": 0, "gaps": [{"notationStyles": ["plain", "en", "si-en"], "type": "numberentry", "marks": 1, "showFeedbackIcon": true, "correctAnswerStyle": "plain", "minValue": "prediction-1", "variableReplacementStrategy": "originalfirst", "allowFractions": false, "scripts": {}, "variableReplacements": [], "maxValue": "prediction+1", "correctAnswerFraction": false, "showCorrectAnswer": true}], "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "prompt": "

Next month, the average temperature in {owner}'s town is forecast to be  {thisval} Celsius. Use the regression equation in the second part to predict sales of the {beverage} in that month.

\n

What is the predicted value of sales (in hundreds of pounds) ?

\n

Use the values of $\\beta_0$ and $\\beta_1$ you input above to 3 decinal places.

\n

Enter the predicted sales here:  [[0]] (hundreds of pounds to the nearest whole number).

\n

", "variableReplacements": []}], "functions": {"regressline": {"type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["minx", "number"], ["maxx", "number"], ["miny", "number"], ["maxy", "number"]], "definition": "window.onload = function () {\n\tvar chart = new CanvasJS.Chart(\"chartContainer\",\n\t{\n\t\ttitle:{\n\t\t\ttext: \"Gaming Consoles Sold in 2012\"\n\t\t},\n animationEnabled: true,\n\t\tlegend:{\n\t\t\tverticalAlign: \"bottom\",\n\t\t\thorizontalAlign: \"center\"\n\t\t},\n\t\tdata: [\n\t\t{ \n\t\t\tindexLabelFontSize: 20,\n\t\t\tindexLabelFontFamily: \"Monospace\", \n\t\t\tindexLabelFontColor: \"darkgrey\", \n\t\t\tindexLabelLineColor: \"darkgrey\", \n\t\t\tindexLabelPlacement: \"outside\",\n\t\t\ttype: \"pie\", \n\t\t\tshowInLegend: true,\n\t\t\ttoolTipContent: \"{y} - #percent%\",\n\t\t\tdataPoints: [\n\t\t\t\t{ y: 4181563, legendText:\"PS 3\", indexLabel: \"PlayStation 3\" },\n\t\t\t\t{ y: 2175498, legendText:\"Wii\", indexLabel: \"Wii\" },\n\t\t\t\t{ y: 3125844, legendText:\"360\",exploded: true, indexLabel: \"Xbox 360\" },\n\t\t\t\t{ y: 1176121, legendText:\"DS\" , indexLabel: \"Nintendo DS\"},\n\t\t\t\t{ y: 1727161, legendText:\"PSP\", indexLabel: \"PSP\" },\n\t\t\t\t{ y: 4303364, legendText:\"3DS\" , indexLabel: \"Nintendo 3DS\"},\n\t\t\t\t{ y: 1717786, legendText:\"Vita\" , indexLabel: \"PS Vita\"}\n\t\t\t]\n\t\t}\n\t\t]\n\t});\n\tchart.render();\n}\n \n", "language": "javascript"}, "regfun": {"type": "html", "parameters": [["r1", "list"], ["r2", "list"], ["maxx", "number"], ["maxy", "number"], ["rsquared", "number"], ["sumr", "number"]], "definition": "\n var div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n{boundingBox:[-5,maxy,maxx,-5],\n axis:true,\n showNavigation:false,\n grid:true});\n var board = div.board; \nvar l1=board.create('text',[maxx/2,-2,'Temperature']);\nvar l2=board.create('text',[-2,maxy/2,'Sales']);\n var names = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n for (j=0;j<12;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:'blue',name:'Regression Line.',withLabel:true}); \n //for(var i=0;i<12;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\nvar t = board.create('text',[1,5,\nfunction(){ return \"\\\\[r(Y) = \" + regExpression +'\\\\]';}\n],\n{strokeColor:'black',fontSize:18}); \nvar t1 = board.create('text',[5,maxy,\nfunction(){ return \"\\\\[SSE = \" + sumr +'\\\\]';}\n],\n{strokeColor:'black',fontSize:18}); \nvar t2 = board.create('text',[20,maxy,\nfunction(){ return \"\\\\[R^2 = \" + rsquared +'\\\\]';}\n],\n{strokeColor:'black',fontSize:18}); \nreturn div;\n \n", "language": "javascript"}}, "variables": {"tol1": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "tol1", "definition": "0.01"}, "owner": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "owner", "definition": "random(\"Kevin\",\"Mary\",\"Bill\",\"Doreen\",\"Peter\",\"Helen\",\"Michael\",\"Samantha\")"}, "r1": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "r1", "definition": "[random(0..6),random(1..7),random(4..10),random(7..13),random(12..18),random(4..20),random(16..22),random(19..25),random(17..23),random(13..19),random(8..14),random(3..9)]"}, "pub": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "pub", "definition": "random(\"Black Bull Inn\",\"County Inn\",\"Dog and Duck Pub\",\"Slug and Lettuce Pub\", \"Cross Keys Pub\",\"Newcastle Arms Pub\",\"Red Lion Pub\")"}, "sc": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "sc", "definition": "r1[ch]"}, "sumr": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "sumr", "definition": "precround(sum(map(res[x]^2,x,0..n-1)),3)"}, "a": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "a", "definition": "precround(1/n*(t[1]-spxy/ss[0]*t[0]),3)"}, "beverage": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "beverage", "definition": "random(\"home-brewed beer\",\"home-brewed lager\",\"specially-brewed beer\",\"super-strength lager\",\"cold-filtered lager\",\"ice-filtered cider\",\"cherry cider\")"}, "b1": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "b1", "definition": "random(0.25..0.45#0.05)"}, "ch": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "ch", "definition": "random(0..11)"}, "prediction": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "prediction", "definition": "round(a+b*thisval)"}, "b": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "b", "definition": "precround(spxy/ss[0],3)"}, "ls": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "ls", "definition": "precround(a+b*sc,2)"}, "res": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "res", "definition": "map(precround(r2[x]-(a+b*r1[x]),2),x,0..n-1)"}, "tol": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "tol", "definition": "0.001"}, "a1": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "a1", "definition": "random(10..20)"}, "tsqovern": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "tsqovern", "definition": "[t[0]^2/n,t[1]^2/n]"}, "obj": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "obj", "definition": "['Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec']"}, "n": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "n", "definition": "12"}, "ss": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "ss", "definition": "[ssq[0]-t[0]^2/n,ssq[1]-t[1]^2/n]"}, "spxy": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "spxy", "definition": "sxy-t[0]*t[1]/n"}, "sxy": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "sxy", "definition": "sum(map(r1[x]*r2[x],x,0..n-1))"}, "corr": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "corr", "definition": "precround(tcorr,2)"}, "t": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "t", "definition": "[sum(r1),sum(r2)]"}, "thisval": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "thisval", "definition": "random(15..22)"}, "rsquared": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "rsquared", "definition": "precround(spxy^2/(ss[0]*ss[1]),3)"}, "tcorr": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "tcorr", "definition": "spxy/sqrt(ss[0]*ss[1])"}, "r2": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "r2", "definition": "map(round(a1+b1*x+random(-9..9)),x,r1)"}, "ssq": {"description": "", "templateType": "anything", "group": "Ungrouped variables", "name": "ssq", "definition": "[sum(map(x^2,x,r1)),sum(map(x^2,x,r2))]"}}, "statement": "

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

", "tags": [], "extensions": ["stats", "jsxgraph"], "name": "Gareth's copy of BES220: Find regression equation and correlation coefficient", "type": "question", "contributors": [{"name": "Gareth Woods", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/978/"}]}]}], "contributors": [{"name": "Gareth Woods", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/978/"}]}