Saturday, May 1, 2021

TI-84 Plus CE and Casio fx-CG50: Confusion Matrix, Practice SAT Questions with Mometrix

TI-84 Plus CE and Casio fx-CG50:  Confusion Matrix, Practice SAT Questions with Mometrix 

Confusion Matrix

Introduction


In statistical applications, particularly in medicine, we hear about the infection rates of a disease and tests that are created to designate whether people are infected with the disease.  No test, at least not any that I heard of, is 100% accurate in detecting whether a person is infected with a certain virus.  


Tables can be used to summarize the accuracy of a test, measuring one of four outcomes:


true positive (TP):  the person is infected with a virus and the test detects the virus


false negative (FN):  the person is infected with a virus but the test fails to detect it


false positive (FP):  the test states the person is infected when in reality the person does not have the virus


true negative (TN):  the person is not infected and the test accurate detects the person is healthy (does not have the virus)



One of the common names for this type of table is a confusion matrix. 


Two of the many measurements that can be made from a confusion matrix are called sensitivity and specificity.



Sensitivity is the ratio of true positive results against all of the population that is infected.  


Sensitivity = true positive / (true positive + false negative)




Specificity is the ratio of true negative results against all fo the population that is not infected.  


Specificity = true negative / (false negative + true positive)



The program CONFUSE creates two 3 x 3 matrices (see the illustration below):




Matrix A:  Theoretical confusion table.  This takes into consideration the infection rate and test rate and calculates the expected values.


Matrix B:  Simulated confusion table.  The test uses a random number generator to simulate the chance of whether a person is infected by using the infection rate and whether a person's test is correct by using the test rate.  The results will vary.  



TI-84 Plus CE Program: CONFUSE


"EWS 2021-03-10"

ClrHome

DelVar [A]

DelVar [B]

{3,3}→dim([A])

{3,3}→dim([B])

Disp "CONFUSION MATRIX"

Input "POPULATION? ",N

Input "INFECTION RATE? ",C

Input "TEST RATE? ",T

N*C→[A](3,1)

N*(1-C)→[A](3,2)

[A](3,1)+[A](3,2)→[A](3,3)

[A](3,1)*T→[A](1,1)

[A](3,1)*(1-T)→[A](2,1)

[A](3,2)*(1-T)→[A](1,2)

[A](3,2)*T→[A](2,2)

[A](1,1)+[A](1,2)→[A](1,3)

[A](2,1)+[A](2,2)→[A](2,3)

For(I,1,N)

rand→R

[B](3,1)+(R≤C)→[B](3,1)

[B](3,2)+(R>C)→[B](3,2)

End

[B](3,1)+[B](3,2)→[B](3,3)

For(I,1,[B](3,1))

rand→R

[B](1,1)+(R≤T)→[B](1,1)

[B](2,1)+(R>T)→[B](2,1)

End

For(I,1,[B](3,2))

rand→R

[B](1,2)+(R>T)→[B](1,2)

[B](2,2)+(R≤T)→[B](2,2)

End

[B](1,1)+[B](1,2)→[B](1,3)

[B](2,1)+[B](2,2)→[B](2,3)

ClrHome

Disp "THEORY [A]"

Pause [A]

ClrHome

Disp "SIMULATION [B]"

Pause [B]

Disp "SENSITIVITY",[B](1,1)/[B](3,1)

Disp "SPECIFICITY",[B](2,2)/[B](3,2)


Casio fx-CG50 Program:  CONFUSE


"EWS 2021-03-13"

ClrText

{3,3}->Dim Mat A

{3,3}->Dim Mat B

"CONFUSION MATRIX"

"POPULATION"?->N

"INFECTION RATE"?->C

"TEST RATE"?->T

N*C->Mat A[3,1]

N*(1-C)->Mat A[3,2]

Mat A[3,1]+Mat A[3,2]->Mat A[3,3]

Mat A[3,1]*T->Mat A[1,1]

Mat A[3,1]*(1-T)->Mat A[2,1]

Mat A[3,2]*(1-T)->Mat A[1,2]

Mat A[3,2]*T->Mat A[2,2]

Mat A[1,1]+Mat A[1,2]->Mat A[1,3]

Mat A[2,1]+Mat A[2,2]->Mat A[2,3]

For 1->I To N

Ran#->R

Mat B[3,1]+(R<=C)->Mat B[3,1]

Mat B[3,2]+(R>C)->Mat B[3,2]

Next

Mat B[3,1]+Mat B[3,2]->Mat B[3,3]

For 1->I To Mat B[3,1]

Ran#->R

Mat B[1,1]+(R<=T)->Mat B[1,1]

Mat B[2,1]+(R>T)->Mat B[2,1]

Next

For 1->I To Mat B[3,2]

Ran#->R

Mat B[1,2]+(R>T)->Mat B[1,2]

Mat B[2,2]+(R<=T)->Mat B[2,2]

Next

Mat B[1,1]+Mat B[1,2]->Mat B[1,3]

Mat B[2,1]+Mat B[2,2]->Mat B[2,3]

ClrText

"_Mat _A: THEORY" ⊿

Mat A ⊿

"_Mat _B: SIMULATION" ⊿

Mat B ⊿

"SENSITIVITY:"

Mat B[1,1]/Mat B[3,1] ⊿

"SPECIFICITY:"

Mat B[2,2]/Mat B[3,2]


Example


Population:  N = 200

Infection Rate:  5%  (enter 0.05)

Successful Test Rate: 80%  (enter 0.80)


Theoretical Matrix (Matrix A):

[[ 8 38 46

2 152 154

10 190 200  ]]


Some simulated results (Matrix B, your results will vary):


Simulation 1:

[[ 7 40 47

1 152 153

8 192 200 ]]


Sensitivity ≈ 0.8750

Specificity ≈ 0.7917


Simulation 2:

[[ 5 34 39

1 160 161

6 194 200 ]]


Sensitivity ≈ 0.8333

Specificity ≈ 0.8247


Sources:


"Confusion Matrix" Wikipedia.  Last Edited February 27, 2021. https://en.wikipedia.org/wiki/Confusion_matrix   Retrieved March 9, 2021. 


Texas Instruments "Webinar:  Modeling as a Tool To Make Sense of the World Around Us" Presented by Gail Burrill and Tom Dick, Ph.D.  https://education.ti.com/en/professional-development/teachers-and-teams/online-learning/on-demand-webinars/2021/mar-09-2021-modeling-as-a-tool-to-make-sense  March 9, 2021


University of Nottingham.  "Accuracy Table" https://www.nottingham.ac.uk/nursing/sonet/rlos/ebp/sensitivity_specificity/page_four.html  Retrieved March 9, 2021


SAT Practice Problems with Mometrix


In 2018, I mentioned that I was going to practice some SAT questions (http://edspi31415.blogspot.com/2018/02/).  If you are taking the SAT or want to practice, a place to go is Mometrix Test Preparation.  Mometrix has online practice tests for reading, writing, and mathematics, as well as official Sample tests.  

Check them out here:  https://www.mometrix.com/academy/sat-practice-test/

Their math page which includes a free online practice test:  https://www.mometrix.com/academy/sat-math-practice-test/

Many thanks to George Bigelow for the information and site.


Disclaimer:  This is not a paid advertisement.  


Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


No comments:

Post a Comment

Update: HP Prime Connectivity Kit and Emulator

  Update: HP Prime Connectivity Kit and Emulator The HP Prime Connectivity Kit and Emulator have been updated.  The version number is 14592 ...