// Numbas version: exam_results_page_options {"name": "Random data set - linear relationship with noise", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Random data set - linear relationship with noise", "tags": [], "metadata": {"description": "

This question shows how to generate a random set of $(x,y)$ samples, where $y = mx + c + \\mathrm{noise}$.

\n

The JSXGraph extension is used to show a scatter plot of the data. This isn't necessary if you just want to generate the data.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

{table([xs,ys])}

\n

{graph}

", "advice": "", "rulesets": {}, "extensions": ["jsxgraph", "stats"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"xs": {"name": "xs", "group": "Ungrouped variables", "definition": "repeat(precround(random(1..100#0),3), n)", "description": "

X values. Chosen uniformly at random within a range.

", "templateType": "anything", "can_override": false}, "n": {"name": "n", "group": "Ungrouped variables", "definition": "10", "description": "

The number of samples.

", "templateType": "anything", "can_override": false}, "ys": {"name": "ys", "group": "Ungrouped variables", "definition": "map(\n precround(gradient*x + intercept + normalsample(0,noise_variance), 3),\n x,\n xs\n)", "description": "

Y values. They have a linear relationship with X, plus some normally-distributed noise. The values are rounded to 3 d.p.

", "templateType": "anything", "can_override": false}, "gradient": {"name": "gradient", "group": "Ungrouped variables", "definition": "random(1..4#0.1)", "description": "

The gradient of Y with respect to X.

", "templateType": "anything", "can_override": false}, "intercept": {"name": "intercept", "group": "Ungrouped variables", "definition": "random(30..50)", "description": "

The $y$-intercept of the line.

", "templateType": "anything", "can_override": false}, "noise_variance": {"name": "noise_variance", "group": "Ungrouped variables", "definition": "5^2", "description": "

The variance of the noise.

", "templateType": "anything", "can_override": false}, "graph": {"name": "graph", "group": "Ungrouped variables", "definition": "jsxgraph(400,400,[-20,tonearest(max(ys),50)+50,tonearest(max(xs),50)+50,-20],\n map([\"point\",pos], pos, zip(xs,ys))\n)", "description": "

A scatter plot of the points.

", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["n", "xs", "ys", "gradient", "intercept", "noise_variance", "graph"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "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/"}]}