// Numbas version: exam_results_page_options {"name": "Use data uploaded by the student", "extensions": ["stats"], "custom_part_types": [], "resources": [["question-resources/Data.csv", "/srv/numbas/media/question-resources/Data.csv"]], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"type": "question", "variables": {}, "variable_groups": [], "name": "Use data uploaded by the student", "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Get the student to upload their experimental data in a CSV file, then ask them to compute statistics on it.

"}, "variablesTest": {"maxRuns": 100, "condition": ""}, "parts": [{"showFeedbackIcon": true, "type": "information", "scripts": {}, "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "showCorrectAnswer": true, "prompt": "
\n

\n
\n

Your data

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Weight (N)Length (cm)
\n
\n
\n

$n$:

\n

$\\sum x$:

\n

$\\sum y$:

\n

$\\sum x^2$:

\n

$\\sum y^2$:

\n

$\\sum xy$:

\n

$\\alpha$:

\n

$\\beta$:

\n
\n
\n
", "marks": 0}, {"showFeedbackIcon": true, "type": "gapfill", "scripts": {}, "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "showCorrectAnswer": true, "gaps": [{"variableReplacements": [], "scripts": {"mark": {"script": "// get the computed stats\nvar stats = this.question.stats();\n// set the correct answer to the computed stat\nthis.settings.minvalue = stats.sx;\nthis.settings.maxvalue = stats.sx;", "order": "before"}}, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "mustBeReduced": false, "maxValue": "0", "showFeedbackIcon": true, "correctAnswerStyle": "plain", "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "minValue": "0", "correctAnswerFraction": false, "marks": 1}, {"variableReplacements": [], "scripts": {"mark": {"script": "var stats = this.question.stats();\nthis.settings.minvalue = stats.sy;\nthis.settings.maxvalue = stats.sy;", "order": "before"}}, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "mustBeReduced": false, "maxValue": "0", "showFeedbackIcon": true, "correctAnswerStyle": "plain", "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "minValue": "0", "correctAnswerFraction": false, "marks": 1}, {"variableReplacements": [], "scripts": {"mark": {"script": "var stats = this.question.stats();\nthis.settings.minvalue = stats.sxx;\nthis.settings.maxvalue = stats.sxx;", "order": "before"}}, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "mustBeReduced": false, "maxValue": "0", "showFeedbackIcon": true, "correctAnswerStyle": "plain", "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "minValue": "0", "correctAnswerFraction": false, "marks": 1}, {"variableReplacements": [], "scripts": {"mark": {"script": "var stats = this.question.stats();\nthis.settings.minvalue = stats.syy;\nthis.settings.maxvalue = stats.syy;", "order": "before"}}, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "mustBeReduced": false, "maxValue": "0", "showFeedbackIcon": true, "correctAnswerStyle": "plain", "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "minValue": "0", "correctAnswerFraction": false, "marks": 1}, {"variableReplacements": [], "scripts": {"mark": {"script": "var stats = this.question.stats();\nthis.settings.minvalue = stats.sxy;\nthis.settings.maxvalue = stats.sxy;", "order": "before"}}, "variableReplacementStrategy": "originalfirst", "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "mustBeReduced": false, "maxValue": "0", "showFeedbackIcon": true, "correctAnswerStyle": "plain", "allowFractions": false, "notationStyles": ["plain", "en", "si-en"], "minValue": "0", "correctAnswerFraction": false, "marks": 1}], "prompt": "

Compute the following statistics from your data.

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
$\\sum x$$\\sum y$$\\sum x^2$$\\sum y^2$$\\sum xy$
[[0]][[1]][[2]][[3]][[4]]
", "marks": 0}], "functions": {}, "tags": ["csv", "demo", "experiment", "statistics"], "extensions": ["stats"], "preamble": {"css": "#data-table {\n max-height: 30em;\n overflow-y: auto;\n display: inline-block;\n}\na, a:hover {\n color: blue;\n}\na:hover {\n text-decoration: underline;\n}", "js": "// read a csv file\nfunction readCSV(text) {\n var lines = text.split('\\n');\n return lines.map(function(line){return line.split(',')});\n}\n\n// wait until the question has been generated\nquestion.signals.on('HTMLAttached',function(e) {\n var display = question.display;\n\n // set up an observable for the data array\n var _data = display.data = ko.observableArray([]);\n \n // has the student uploaded data?\n display.gotData = ko.computed(function() {\n return _data().length>0;\n });\n \n // an observable object containing various computed statistics about the data - updates automatically when the data changes\n var stats = question.stats = ko.computed(function() {\n var data = _data();\n \n // weights are in the first column\n var weights = data.map(function(r){return r[0]});\n // lengths in the second column\n var lengths = data.map(function(r){return r[1]});\n \n // how many samples?\n var n = data.length;\n \n // components of the linear regression calculation\n var sx = jStat.sum(weights);\n var sy = jStat.sum(lengths);\n var sxx = jStat.sum(weights.map(function(x){return x*x}));\n var syy = jStat.sum(lengths.map(function(x){return x*x}));\n var sxy = jStat.sum(data.map(function(r){ return r[0]*r[1]}));\n \n // coefficients of the linear regression model\n var beta = (sxy - (sx*sy)/n)/(sxx-(sx*sx)/n);\n var alpha = (sy-beta*sx)/n;\n \n var stats = {\n sx: sx,\n sy: sy,\n sxx: sxx,\n syy: syy,\n sxy: sxy,\n alpha: alpha,\n beta: beta,\n n: data.length\n };\n \n return stats;\n });\n \n // format a number to 3 d.p.\n function niceNumber(n) {\n return Numbas.math.niceNumber(n,{precisionType: 'dp', precision: 3});\n }\n \n // code to read the file when it's uploaded\n $('#file').on('change',function(e) {\n var f = e.target.files[0];\n var reader = new FileReader();\n reader.onload = function(e) {\n var data = readCSV(e.target.result);\n _data(data.map(function(row){ return row.map(parseFloat)}).filter(function(row){return !isNaN(row[0])}));\n }\n reader.readAsText(f);\n });\n});"}, "ungrouped_variables": [], "statement": "

This question will only work in browsers that support the HTML5 File API! For Internet Explorer users, that means version 10 onwards.

\n

How does the length of a spring change when you suspend different masses from it? Make measurements of your spring's length when hanging various different weights from it.

\n

Download the data spreadsheet and open it in a program such as Microsoft Excel. Enter your data, save the file, and then upload it using the button below.

", "advice": "", "rulesets": {}, "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/"}]}