// Numbas version: exam_results_page_options {"name": "Testing and False Positives", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"extensions": ["jsxgraph"], "parts": [{"gaps": [{"showCorrectAnswer": true, "marks": 1, "maxValue": "poswith", "showPrecisionHint": false, "minValue": "poswith", "scripts": {}, "type": "numberentry"}, {"showCorrectAnswer": true, "marks": 1, "maxValue": "poswithout", "showPrecisionHint": false, "minValue": "poswithout", "scripts": {}, "type": "numberentry"}, {"showCorrectAnswer": true, "marks": 1, "maxValue": "totalwith", "showPrecisionHint": false, "minValue": "totalwith", "scripts": {}, "type": "numberentry"}, {"showCorrectAnswer": true, "marks": 1, "maxValue": "percentprob+0.1", "showPrecisionHint": false, "minValue": "percentprob-0.1", "scripts": {}, "type": "numberentry"}], "showCorrectAnswer": true, "marks": 0, "type": "gapfill", "prompt": "
\nWith Condition | Without Condition | Totals | |
---|---|---|---|
Test Positive | \nPosWith=[[0]] | \nPosWithout=[[1]] | \n\n |
Test Negative | \n\n | \n | \n |
Totals | \nTotalWith=[[2]] | \n\n | 1000000 | \n
Suppose we are dealing with a population of $1,000,000.$
\nIn the following enter all numbers in the table to one decimal place. Do not enter large numbers with commas i.e. enter 12,345.6 as 12345.6.
\nGiven the percentage $\\var{user}\\%$ of this population with the condition find the expected total number, TotalWith, with the condition and enter this number in the appropriate answer box in the table above. Note that the number of the population without the condition is automatically filled in.
\nNow using the data on the effectiveness of the test enter the expected number, PosWith, of the TotalWith that test positively in the table.
\nNote that the expected number with the condition that test negatively is automatically filled in.
\nThe last table entry is to fill in the number, PosWithout, of the population expected to test positively but do not have the condition. Use the data on false positives for this.
\nThe population without the condition and that test negatively is filled in for you as well as totals for positive and negative tests.
\nUsing this data, find the percentage of those that have the condition given that they have tested positively:
\nPercentage=[[3]]% (Enter to 1 decimal place).
\n", "scripts": {}}], "type": "question", "rulesets": {}, "name": "Testing and False Positives", "variables": {"thisprev": {"group": "Ungrouped variables", "name": "thisprev", "definition": "round(100/user)", "templateType": "anything", "description": ""}, "thatprev": {"group": "Ungrouped variables", "name": "thatprev", "definition": "round(1/prob)", "templateType": "anything", "description": ""}, "notpresent": {"group": "Ungrouped variables", "name": "notpresent", "definition": "\"healthy people\"", "templateType": "anything", "description": ""}, "poswithout": {"group": "Ungrouped variables", "name": "poswithout", "definition": "fal*(pop-totalwith)/100", "templateType": "anything", "description": ""}, "test": {"group": "Ungrouped variables", "name": "test", "definition": "\"A laboratory test\"", "templateType": "anything", "description": ""}, "it": {"group": "Ungrouped variables", "name": "it", "definition": "\"the test\"", "templateType": "anything", "description": ""}, "nus": {"group": "Ungrouped variables", "name": "nus", "definition": "precround((100-user)/100,4)", "templateType": "anything", "description": ""}, "falseresult": {"group": "Ungrouped variables", "name": "falseresult", "definition": "\"a false positive result\"", "templateType": "anything", "description": ""}, "percentprob": {"group": "Ungrouped variables", "name": "percentprob", "definition": "precround(100*poswith/(poswith+poswithout),1)", "templateType": "anything", "description": ""}, "effective": {"group": "Ungrouped variables", "name": "effective", "definition": "random(85..95)", "templateType": "anything", "description": ""}, "indef": {"group": "Ungrouped variables", "name": "indef", "definition": "\"a person\"", "templateType": "anything", "description": ""}, "tol": {"group": "Ungrouped variables", "name": "tol", "definition": 0.001, "templateType": "anything", "description": ""}, "eff": {"group": "Ungrouped variables", "name": "eff", "definition": "\"effective\"", "templateType": "anything", "description": ""}, "used": {"group": "Ungrouped variables", "name": "used", "definition": "\"has the disease\"", "templateType": "anything", "description": ""}, "poswith": {"group": "Ungrouped variables", "name": "poswith", "definition": "totalwith*effective/100", "templateType": "anything", "description": ""}, "fal": {"group": "Ungrouped variables", "name": "fal", "definition": "random(0.4..0.8#0.1)", "templateType": "anything", "description": ""}, "effec": {"group": "Ungrouped variables", "name": "effec", "definition": "precround(effective/100,2)", "templateType": "anything", "description": ""}, "morethaneven": {"group": "Ungrouped variables", "name": "morethaneven", "definition": "precround(user*effective/(100-user),2)", "templateType": "anything", "description": ""}, "prob": {"group": "Ungrouped variables", "name": "prob", "definition": "precround(ans1/probpositive,3)", "templateType": "anything", "description": ""}, "havecondition": {"group": "Ungrouped variables", "name": "havecondition", "definition": "\"actually have the disease\"", "templateType": "anything", "description": ""}, "pop": {"group": "Ungrouped variables", "name": "pop", "definition": 1000000, "templateType": "anything", "description": ""}, "something": {"group": "Ungrouped variables", "name": "something", "definition": "\"the population\"", "templateType": "anything", "description": ""}, "user": {"group": "Ungrouped variables", "name": "user", "definition": "random(0.05..0.15#0.01)", "templateType": "anything", "description": ""}, "us": {"group": "Ungrouped variables", "name": "us", "definition": "precround(user/100,4)", "templateType": "anything", "description": ""}, "totalwithout": {"group": "Ungrouped variables", "name": "totalwithout", "definition": "precround(pop-totalwith,0)", "templateType": "anything", "description": ""}, "present": {"group": "Ungrouped variables", "name": "present", "definition": "\"it is present\"", "templateType": "anything", "description": ""}, "fa": {"group": "Ungrouped variables", "name": "fa", "definition": "precround(fal/100,3)", "templateType": "anything", "description": ""}, "finding": {"group": "Ungrouped variables", "name": "finding", "definition": "\"detecting a certain disease\"", "templateType": "anything", "description": ""}, "totalwith": {"group": "Ungrouped variables", "name": "totalwith", "definition": "pop*user/100", "templateType": "anything", "description": ""}, "ans1": {"group": "Ungrouped variables", "name": "ans1", "definition": "(effective/100)*(user/100)", "templateType": "anything", "description": ""}, "testspositive": {"group": "Ungrouped variables", "name": "testspositive", "definition": "\"his test is positive\"", "templateType": "anything", "description": ""}, "probpositive": {"group": "Ungrouped variables", "name": "probpositive", "definition": "(effective/100)*(user/100)+(fal/100)*(1-user/100)", "templateType": "anything", "description": ""}}, "advice": "We present two solutions:
\nSolution a) uses the data in the table based on a population of $1,000,000$ in order to calculate the probability that a person has the condition given that the test is positive.
\nSolution b) uses conditional probability and Bayes' Theorem without reference to a specific population.
\nSolution a). Using a Table
\n
We have that the number of people in a population of $1,000,000$ expected to have the condition is given by:
\\[TotalWith =\\frac{ \\var{user}}{100} \\times 1000000=\\var{totalwith}.\\]
\nNote that we have the expected number of the population without the condition to be $\\var{totalwithout}$.
\nOf the $\\var{totalwith}$ with the condition we can calculate the expected number whose condition will be detected by the test:
\n\\[PosWith = \\frac{\\var{effective}}{100}\\times \\var{totalwith}=\\var{poswith}.\\]
\nFinally of the $\\var{totalwithout}$ without the condition we are told to expect $\\var{fal}$% to be wrongly diagnosed as with the condition i.e.
\n\\[PosWithout = \\frac{\\var{fal}}{100}\\times \\var{totalwithout}=\\var{poswithout}.\\]
\nWe now can calculate the number of the population which are expected to test positively:
\n\\[TotalPos = \\var{poswith}+\\var{poswithout}=\\var{poswith+poswithout}.\\]
\nOf these $\\var{poswith}$ actually have the condition so the percentage of those with the condition as against the total of those with positive tests is:
\n\\[Percentage=100 \\times\\frac{\\var{poswith}}{\\var{poswith+poswithout}}=\\var{percentprob}\\%.\\] to one decimal place.
\nThis gives the percentage of those expected to have the condition after a positive test.
\nWe conclude that if the results of a person's test is positive then there is a $\\var{percentprob}\\%$ chance that he/she has the disease i.e. the chances have increased from around 1 in $\\var{thisprev}$ to about 1 in $\\var{thatprev}$.
\nNote that if $PC\\%$ is the percentage of people with the condition in the population, $FP\\%$ is the percentage of false positives and $T\\%$ is the effectiveness of the test then in order to for a positive test to indicate that there is more than an evens chance of having the condition we have:\\[FP \\lt \\frac{PC\\times T}{100-PC}.\\]
\nIf we take the above data for $PC$ and $T$ then for more than an evens chance of having the condition we would have to have:
\\[FP \\lt \\frac{PC\\times T}{100-PC}=\\frac{\\var{user}\\times \\var{effective}}{100-\\var{user}}=\\var{morethaneven}\\%.\\]
\n\n\nThe above diagram shows the relationship between the percentage with the condition after testing positive and the percentage of false positives. This assumes that the test has a fixed $\\var{effective}$% success rate of detecting the condition and that there is a fixed $\\var{user}$% of the population with the condition.
\nYou can drag the red point along the curve to see how the percentages change with the false positive percentage.
\nSolution b). Bayes' Theorem.
\nConsider the events
\n\n \\[\\begin{align} D &= \\text{the person has the disease.}\\\\
ND &= \\text{the person does not have the disease.}\\\\
PR&=\\text{the test result is positive.}\\end{align}\\]
We are given that
\n\\[P(PR|D)=\\var{effec},\\;P(PR|ND)=\\var{fa},\\;P(D)=\\var{us}\\]
\n\nSince the events $D$ and $ND$ form a partition of the sample space, we can use Bayes' Theorem to calculate
\n\\[\\begin{align}P(D|PR)&=\\frac{P(PR|D)\\times P(D)}{P(PR|D)\\times P(D)+P(PR|ND)\\times P(ND)}\\\\
&=\\frac{\\var{effec}\\times \\var{us}}{\\var{effec}\\times \\var{us}+\\var{fa}\\times \\var{nus}}\\\\
&=\\var{percentprob/100}\\;\\;\\text{to 3 decimal places}\\end{align}\\]
We conclude that if the results of a person's test is positive then there is a $\\var{percentprob}\\%$ chance that he/she has the disease i.e. the chances have increased from around 1 in $\\var{thisprev}$ to about 1 in $\\var{thatprev}$.
", "question_groups": [{"pickQuestions": 0, "questions": [], "pickingStrategy": "all-ordered", "name": ""}], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "notes": "02/03/2014:
\nCreated.
\n16/03/2014:
\nCreated tabular version on advice of Bill Kirkup which uses a given population to find the numbers in each relevant population. The conditional probability is then found using ratios.
\n19/03/2014:
\nAdded graph of relationship between false positive and percentage with condition after testing positive. This is found in Advice.
", "description": "Given a population size and data on a test for a condition on that population, use a tabular approach to find the increase in risk after a positive test in which there is a small chance of a false positive i.e. the probability that the test is positive even though the condition is not present. See Advice for a graphical version.
\n"}, "showQuestionGroupNames": false, "tags": ["Bayes", "Bayes' Theorem", "Jsxgraph", "Probability", "conditional probability", "false positive", "given population", "jsxgraph", "preamble", "probability", "statistics", "tabular method", "test", "testing"], "statement": "{test} is $\\var{effective}\\%$ {eff} in {finding} when {present}.
\nHowever, {it} also yields a \"false positive\" result for $\\var{fal}\\%$ of {notpresent} tested.
\nIf $\\var{user}\\%$ of {something} {havecondition}, what percentage of the population has the condition, given that their test is positive?
\n(Thanks to Dr Bill Kirkup for providing the methodology and tabular format for this approach.)
", "progress": "in-progress", "variable_groups": [], "functions": {}, "preamble": {"js": "//Note that math.niceNumber returns a string.\nfunction fill_values(){\n var html = $(question.display.html);\n var math = Numbas.math;\n ko.computed(function() {\nvar totalwith = parseFloat(question.parts[0].gaps[2].display.studentAnswer());\nif(!isNaN(totalwith)) {\n var withoutcond = 1000000-totalwith;\n var disp3=math.niceNumber(withoutcond);\n html.find('#wc').text(disp3);\n}\nelse {\n html.find('#wc').text('');\n}\n var testposwith=parseFloat(question.parts[0].gaps[0].display.studentAnswer());\nif(!isNaN(testposwith)) {\n var testnegwith= totalwith-testposwith;\n var disp2=math.niceNumber(testnegwith);\n html.find('#pwout').text(disp2);\n}\nelse {\n html.find('#pwout').text('');\n}\nvar testposwithout=parseFloat(question.parts[0].gaps[1].display.studentAnswer());\nif(!isNaN(testposwithout)) {\n var testnegwithout= withoutcond-testposwithout;\n var disp1=math.niceNumber(testnegwithout);\n \n html.find('#nwithout').text(disp1);\n \n}\nelse {\n html.find('#nwithout').text('');\n}\n\n var totalpos= math.niceNumber(testposwith+testposwithout);\nif(!isNaN(totalpos)){\n\nhtml.find('#totalpos').text(totalpos);\n}\nelse {\n html.find('#totalpos').text('');\n}\nvar totalneg= math.niceNumber(testnegwith+testnegwithout);\nif(!isNaN(totalneg)){\n\nhtml.find('#totalneg').text(totalneg);\n}\nelse {\n html.find('#totalneg').text('');\n}\n \n });\n};\nfunction fpgraph_board() {\n var scope = question.scope;\n \n var ef = Numbas.jme.unwrapValue(scope.variables.effective);\n var perc = Numbas.jme.unwrapValue(scope.variables.user);\n var fp = Numbas.jme.unwrapValue(scope.variables.fal);\n var ans = Numbas.jme.unwrapValue(scope.variables.percentprob);\n var div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',{boundingBox:[-0.01,100,2,-10],grid:false});\n \n $(question.display.html).find('#fpgraph').append(div);\n \n var board = div.board;\n \n \n var graph = board.create('functiongraph',function(x){return 100*ef*perc/(ef*perc+(100-perc)*x)});\n var q = board.create('glider', [fp, ans, graph], {withLabel:false});\n var t1= board.create('text',[0.25,90,\"Graph of % with condition on testing positive against false positive %.\"],\n {fontSize:17}); \n var t2=board.create('text',[0.5,-5,\"False Positive Percentage\"]);\n var t3 = board.create('text', [\n function(){ return q.X()+0.1; },\n function(){ return q.Y()+1.5; },\n function(){ return \"% with condition after positive test=\"+q.Y().toFixed(2)+\"% when false positive %=\" + q.X().toFixed(2) + \"%\"; }\n ], \n {fontSize:15});\n \n}\n\nquestion.signals.on('HTMLAttached',function() {\n //fill in values\n fill_values();\n fpgraph_board();\n});\n", "css": ""}, "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/"}]}