// Numbas version: exam_results_page_options {"name": "BS1.5", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"lquartile": {"definition": "\n interpolate(a,(length(a)+1)/4)", "type": "number", "language": "jme", "parameters": [["a", "list"]]}, "uquartile": {"definition": "interpolate(a,3*(length(a)+1)/4)", "type": "number", "language": "jme", "parameters": [["a", "list"]]}, "interpolate": {"definition": "(1-fract(r))*sort(a)[floor(r)-1]+fract(r)*sort(a)[ceil(r)-1]", "type": "number", "language": "jme", "parameters": [["a", "list"], ["r", "number"]]}, "flattenint": {"definition": "\n /*only for integer arrays*/ \n array.toString().split(',').forEach( function (item, i) \n {array[i] = parseInt(item);\n }\n ); \n return array;\n ", "type": "list", "language": "javascript", "parameters": [["array", "list"]]}}, "name": "BS1.5", "tags": ["interquartile range", "lower quartile", "mean", "median", "ordered data", "sample data", "sample mean", "sample standard deviation", "sc", "statistics", "udf", "upper quartile"], "advice": "\n
As we have to find the median and the interquartile range it is a good idea to order the data and also to total up the data (for the mean) and find the total of the squares of the data (for the variance).
\n{table([['Data']+sort(r),['Squared data']+map(x^2,x,sort(r)),['Index']+map(x,x,1..m*n)],[])}
\nNote that from the above table:
\n$n=\\var{m*n}$.
\n$\\displaystyle \\sum x_i = \\var{sum(r)}$ and
\n$\\displaystyle \\sum x^2_i = \\var{sum(map(x^2,x,r))}$ .
\nThe sample mean is $\\bar{x}=\\displaystyle \\frac{ \\sum x_i}{n}=\\frac{\\var{sum(r)}}{\\var{m*n}}=\\var{mean(r)}=\\var{av}$ to 2 decimal places.
\nThe sample deviation is the square root of the sample variance.
\nSample variance:\\[\\begin{eqnarray*}\\frac{1}{ n -1}\\left(\\sum x_i ^ 2 - n \\bar{x} ^ 2\\right)&=& \\frac{1}{\\var{m*n-1}}\\left(\\var{sum(map(x^2,x,r))}-\\var{m*n}\\times\\var{mean(r)^2}\\right)\\\\&=&\\var{variance(r,true)}\\end{eqnarray*}\\] {Note}
\nSo the sample standard deviation = $\\sqrt{\\var{variance(r,true)}}=\\var{std}$ to 2 decimal places.
\nThe median is $\\var{median(r)} $.
\nThe lower quartile is : $\\var{lquartile(r)}$.
\nThe upper quartile is : $\\var{uquartile(r)}$.
\nThe interquartile range is the difference between these quartiles =$\\var{uquartile(r)}-\\var{lquartile(r)}=\\var{uquartile(r)-lquartile(r)}$
\n\n
\n ", "rulesets": {}, "parts": [{"prompt": "\n
Sample mean = [[0]]{shortform}. Give your answer to $2$ decimal places.
\nSample Standard Deviation = [[1]] {shortform}. Give your answer to $2$ decimal places.
\nSample Median = [[2]] (Input as an exact decimal).
\nThe interquartile range= [[3]] (Input as an exact decimal).
\n ", "gaps": [{"minvalue": "av-0.01", "type": "numberentry", "maxvalue": "av+0.01", "marks": 1.0, "showPrecisionHint": false}, {"minvalue": "std-0.01", "type": "numberentry", "maxvalue": "std+0.01", "marks": 1.0, "showPrecisionHint": false}, {"minvalue": "med", "type": "numberentry", "maxvalue": "med", "marks": 1.0, "showPrecisionHint": false}, {"minvalue": "interq", "type": "numberentry", "maxvalue": "interq", "marks": 1.0, "showPrecisionHint": false}], "type": "gapfill", "marks": 0.0}], "extensions": ["stats"], "statement": "\nThe following data are the {whatever} for {these}, {units} taken by {this}
\n{table(tble,t)}
\nAnswer the following questions:
\n\n
\n ", "variable_groups": [], "progress": "testing", "type": "question", "variables": {"me": {"definition": "random(7..12)", "name": "me"}, "tble1": {"definition": "repeat(repeat(max(round(normalsample(me,sig)),random(4..6)),m),n)", "name": "tble1"}, "tble": {"definition": "switch(n=2,map(['Year '+x+':']+tble1[x-1],x,1..2),map(['Week '+ x+':']+tble1[x-1],x,1..3))", "name": "tble"}, "shortform": {"definition": "'orders'", "name": "shortform"}, "med": {"definition": "median(r)", "name": "med"}, "this": {"definition": "'an online warehouse' ", "name": "this"}, "m": {"definition": "if(n=2,12,random(7,5))", "name": "m"}, "period": {"definition": "switch(m=7,'day',m=12,'month',m=5,'weekday')", "name": "period"}, "whatever": {"definition": "'number of orders per ' + period", "name": "whatever"}, "interq": {"definition": "precround(uquartile(r)-lquartile(r),2)", "name": "interq"}, "note": {"definition": "if(mean(r)=av,' ','Note that we used the more accurate value $(\\\\var{mean(r)})^2$ for $\\\\bar{x}^2$.')", "name": "note"}, "p": {"definition": "switch(m=12,'year','week')", "name": "p"}, "std": {"definition": "precround(stdev(r,true),2)", "name": "std"}, "r": {"definition": "flattenint(tble1)", "name": "r"}, "these": {"definition": "'specialist camera equipment'", "name": "these"}, "t": {"definition": "switch(m=12,[' ','J','F','M','A','M','J','J','A','S','O','N','D'],m=5,[' ','M','T','W','T','F'],[' ','M','T','W','T','F','S','S'])", "name": "t"}, "av": {"definition": "precround(mean(r),2)", "name": "av"}, "units": {"definition": "'over a '+ n + ' '+p+ ' period,'", "name": "units"}, "sig": {"definition": "random(2..4#0.2)", "name": "sig"}, "n": {"definition": "random(2,3)", "name": "n"}}, "metadata": {"notes": "
Note that the uquartile and lquartile are calculated as given by the functions below these may change!
\n21/12/2012:
\nThree user defined functions. Added tag udf.
\nflattenint, takes an array of arrays with integers leaves and converts to an integer array by flattening the array. Other two functions, uquartile and lquartile find the lower and upper quartiles.
\nScenarios possible, added sc.
\n22/10/2013:
\n
Redefined functions uquartile and lquartile to fit new definitions. Added helper udf interpolate.
Given sample data find mean, standard deviation, median, interquartile range.
\nNote that there are different versions of the upper and lower quartiles, so you may want to include your own versions - see the user defined functions in the question.
", "licence": "Creative Commons Attribution 4.0 International"}, "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}]}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}