// Numbas version: finer_feedback_settings {"name": "Regression 3 TEST", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"js": "", "css": ""}, "tags": ["correlation", "data analysis", "experiment", "fitted value", "graphical", "interactive", "linear regression", "regression", "statistics"], "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"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "pickQuestions": 0, "name": ""}], "advice": "
{regfun(r1,r2,max(r1)+10,max(r2)+10,rsquared,sumr)}
", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "parts": [{"prompt": "Calculate the sample correlation coefficient $r$ for these data:
\n$r=\\;$[[0]] (enter to 2 decimal places).
", "scripts": {}, "marks": 0, "showCorrectAnswer": true, "gaps": [{"allowFractions": false, "scripts": {}, "minValue": "corr-tol1", "correctAnswerFraction": false, "showCorrectAnswer": true, "marks": 1, "type": "numberentry", "showPrecisionHint": false, "maxValue": "corr+tol1"}], "type": "gapfill"}, {"prompt": "Calculate the equation of the best fitting regression line.
\n\\[Y = a + b \\times X.\\] 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$b=\\;$[[0]], $a=\\;$[[1]] (enter both to 3 decimal places).
\nYou can experiment by dragging the points A and B around to see if you can get close to the regression line. The SSE is displayed which gives an indication of the fit.
\n{regressline(r1,r2,min(r1)-10,max(r1)+10,min(r2)-10,max(r2)+10)}
\nSSE=
\nSSE for fitted regression line: {sumr}
\n\nClick on Show steps if you want more information on calculating $a$ and $b$. You will not lose any marks by doing so.
\n", "stepsPenalty": 0, "scripts": {}, "marks": 0, "showCorrectAnswer": true, "gaps": [{"allowFractions": false, "scripts": {}, "minValue": "b-tol", "correctAnswerFraction": false, "showCorrectAnswer": true, "marks": 1, "type": "numberentry", "showPrecisionHint": false, "maxValue": "b+tol"}, {"allowFractions": false, "scripts": {}, "minValue": "a-tol", "correctAnswerFraction": false, "showCorrectAnswer": true, "marks": 1, "type": "numberentry", "showPrecisionHint": false, "maxValue": "a+tol"}], "type": "gapfill", "steps": [{"showCorrectAnswer": true, "marks": 0, "prompt": "
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$.
", "type": "information", "scripts": {}}]}, {"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.
\nWhat is the predicted value of sales (in hundreds of pounds) ?
\nUse the values of $a$ and $b$ you input above to 3 decinal places.
\nEnter the predicted sales here: [[0]] (hundreds of pounds to the nearest whole number).
\n", "scripts": {}, "marks": 0, "showCorrectAnswer": true, "gaps": [{"allowFractions": false, "scripts": {}, "minValue": "prediction-1", "correctAnswerFraction": false, "showCorrectAnswer": true, "marks": 1, "type": "numberentry", "showPrecisionHint": false, "maxValue": "prediction+1"}], "type": "gapfill"}], "showQuestionGroupNames": false, "statement": "{owner} owns the {pub}. {owner} believes that sales of {beverage} in the pub are linked to the average monthly temperature, with higher sales being recorded in months with higher temperatures. To investigate, {owner} records the average monthly temperature in the local town over a period of one year ($X$ degrees Celsius), along with total monthly sales of {beverage} ($Y$ hundred pounds). The results are shown in the table below:
\nMonth | $\\var{obj[0]}$ | $\\var{obj[1]}$ | $\\var{obj[2]}$ | $\\var{obj[3]}$ | $\\var{obj[4]}$ | $\\var{obj[5]}$ | $\\var{obj[6]}$ | $\\var{obj[7]}$ | $\\var{obj[8]}$ | $\\var{obj[9]}$ | $\\var{obj[10]}$ | $\\var{obj[11]}$ |
---|---|---|---|---|---|---|---|---|---|---|---|---|
$X$ (temperature) | \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$\\var{r1[8]}$ | \n$\\var{r1[9]}$ | \n$\\var{r1[10]}$ | \n$\\var{r1[11]}$ | \n
$Y$ (sales, £100s) | \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$\\var{r2[8]}$ | \n$\\var{r2[9]}$ | \n$\\var{r2[10]}$ | \n$\\var{r2[11]}$ | \n
You are given the following information:
\n$X$ | \n$\\sum x=\\;\\var{t[0]}$ | \n$\\sum x^2=\\;\\var{ssq[0]}$ | \n
---|---|---|
$Y$ | \n$\\sum y=\\;\\var{t[1]}$ | \n$\\sum y^2=\\;\\var{ssq[1]}$ | \n
Also you are given $\\sum xy = \\var{sxy}$.
", "variables": {"pub": {"description": "", "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\")", "templateType": "anything"}, "b1": {"description": "", "group": "Ungrouped variables", "name": "b1", "definition": "random(0.25..0.45#0.05)", "templateType": "anything"}, "res": {"description": "", "group": "Ungrouped variables", "name": "res", "definition": "map(precround(r2[x]-(a+b*r1[x]),2),x,0..n-1)", "templateType": "anything"}, "ch": {"description": "", "group": "Ungrouped variables", "name": "ch", "definition": "random(0..11)", "templateType": "anything"}, "b": {"description": "", "group": "Ungrouped variables", "name": "b", "definition": "precround(spxy/ss[0],3)", "templateType": "anything"}, "ls": {"description": "", "group": "Ungrouped variables", "name": "ls", "definition": "precround(a+b*sc,2)", "templateType": "anything"}, "corr": {"description": "", "group": "Ungrouped variables", "name": "corr", "definition": "precround(tcorr,2)", "templateType": "anything"}, "tsqovern": {"description": "", "group": "Ungrouped variables", "name": "tsqovern", "definition": "[t[0]^2/n,t[1]^2/n]", "templateType": "anything"}, "sxy": {"description": "", "group": "Ungrouped variables", "name": "sxy", "definition": "sum(map(r1[x]*r2[x],x,0..n-1))", "templateType": "anything"}, "obj": {"description": "", "group": "Ungrouped variables", "name": "obj", "definition": "['Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec']", "templateType": "anything"}, "tol": {"description": "", "group": "Ungrouped variables", "name": "tol", "definition": "0.001", "templateType": "anything"}, "beverage": {"description": "", "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\")", "templateType": "anything"}, "thisval": {"description": "", "group": "Ungrouped variables", "name": "thisval", "definition": "random(15..22)", "templateType": "anything"}, "n": {"description": "", "group": "Ungrouped variables", "name": "n", "definition": "12", "templateType": "anything"}, "tcorr": {"description": "", "group": "Ungrouped variables", "name": "tcorr", "definition": "spxy/sqrt(ss[0]*ss[1])", "templateType": "anything"}, "prediction": {"description": "", "group": "Ungrouped variables", "name": "prediction", "definition": "round(a+b*thisval)", "templateType": "anything"}, "r1": {"description": "", "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)]", "templateType": "anything"}, "r2": {"description": "", "group": "Ungrouped variables", "name": "r2", "definition": "map(round(a1+b1*x+random(-9..9)),x,r1)", "templateType": "anything"}, "t": {"description": "", "group": "Ungrouped variables", "name": "t", "definition": "[sum(r1),sum(r2)]", "templateType": "anything"}, "a": {"description": "", "group": "Ungrouped variables", "name": "a", "definition": "precround(1/n*(t[1]-spxy/ss[0]*t[0]),3)", "templateType": "anything"}, "ss": {"description": "", "group": "Ungrouped variables", "name": "ss", "definition": "[ssq[0]-t[0]^2/n,ssq[1]-t[1]^2/n]", "templateType": "anything"}, "rsquared": {"description": "", "group": "Ungrouped variables", "name": "rsquared", "definition": "precround(spxy^2/(ss[0]*ss[1]),3)", "templateType": "anything"}, "owner": {"description": "", "group": "Ungrouped variables", "name": "owner", "definition": "random(\"Kevin\",\"Mary\",\"Bill\",\"Doreen\",\"Peter\",\"Helen\",\"Michael\",\"Samantha\")", "templateType": "anything"}, "sc": {"description": "", "group": "Ungrouped variables", "name": "sc", "definition": "r1[ch]", "templateType": "anything"}, "ssq": {"description": "", "group": "Ungrouped variables", "name": "ssq", "definition": "[sum(map(x^2,x,r1)),sum(map(x^2,x,r2))]", "templateType": "anything"}, "sumr": {"description": "", "group": "Ungrouped variables", "name": "sumr", "definition": "precround(sum(map(res[x]^2,x,0..n-1)),3)", "templateType": "anything"}, "a1": {"description": "", "group": "Ungrouped variables", "name": "a1", "definition": "random(10..20)", "templateType": "anything"}, "tol1": {"description": "", "group": "Ungrouped variables", "name": "tol1", "definition": "0.01", "templateType": "anything"}, "spxy": {"description": "", "group": "Ungrouped variables", "name": "spxy", "definition": "sxy-t[0]*t[1]/n", "templateType": "anything"}}, "metadata": {"description": "Find a regression equation given 12 months data on temperature and sales of a drink. Includes an interactive diagram for experimenting with fitting a regression line.
", "notes": "04/02/2014:
\nNo advice as yet apart from a diagram of the completed regression.
\nAdapted from an i-assess question.
", "licence": "Creative Commons Attribution 4.0 International"}, "functions": {"regfun": {"parameters": [["r1", "list"], ["r2", "list"], ["maxx", "number"], ["maxy", "number"], ["rsquared", "number"], ["sumr", "number"]], "type": "html", "language": "javascript", "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])]])};\n\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"}, "regressline": {"parameters": [["r1", "list"], ["r2", "list"], ["minx", "number"], ["maxx", "number"], ["miny", "number"], ["maxy", "number"]], "type": "html", "language": "javascript", "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; \nvar l1=board.create('text',[maxx/2,-2,'Temperature']);\nvar l2=board.create('text',[-2,maxy/2,'Sales']);\nvar names = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\nfor (j=0;j<12;j++){ board.create('point',[r1[j],r2[j]],{fixed:true, style:3,name:'\\['+names[j]+'\\]'})};\nvar a1 = board.create('point',[minx+5,miny+5],{color:'blue'});\nvar b1 = board.create('point',[minx+7,miny+5],{color:'blue'});\nfunction updr(a,b){\n var s=0;\n for(var i=0;i<12;i++){\ns=s+Math.pow(r2[i]-a*r1[i]-b,2);}\nvar html = $(question.display.html);\ns=Numbas.math.niceNumber(Numbas.math.precround(s,2));\nhtml.find('#rsquared').text(s);}\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[1].gaps[0].display.studentAnswer(a);\n Numbas.exam.currentQuestion.parts[1].gaps[1].display.studentAnswer(b);\n updr(a,b);\n })};\n dr(a1);\n dr(b1); \nreturn div;\n\n \n"}}, "name": "Regression 3 TEST", "type": "question", "contributors": [{"name": "TEAME UCC", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/351/"}, {"name": "Xiaodan Leng", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2146/"}]}]}], "contributors": [{"name": "TEAME UCC", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/351/"}, {"name": "Xiaodan Leng", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2146/"}]}