0
|
2553 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Help converting some simple code to Mathematica

Posted 10 years ago
 Hey, Mathematica noob, so sorry for posting what's likely a pretty dumb question.I have a table of data that I have done some preliminary exploration in Excel with, and now want to dive a little more deeply.In essence this data is the results of some testing we have done on athletes pre-season over the last few years. The test generates a number where we think that a higher number makes you more likely to get an injury, but it's not known at what point higher the cut-off for this number should be. After a few years of doing this, we can now look back at the data and check if the test is telling us something meaningful, and if so, what a sensible cut-off point should be.What I'd like to do is write a script which makes counts of the true positives, true negatives, false positives, and false negatives, for a range of cut-off values. The cut-off values are going to be determined as differences from the group average, starting at a 1% difference, stepping up by 1% at a time to some arbitrary point (perhaps 400% depending on what the data shows)I would be able to write this code pretty simply in something like Pascal which reads similarly to the Mathematica instruction set I have read in the manual, but have not had any experience with Mathematica aside from reading the manual.I would appreciate any help on translating the snippet below into Mathematica. Main points are that I have to correctly define the variables, matricies, populate the matricies from the raw data, and get my control structures into a syntax Mathematica is OK with.Any help gratefully received,Rod /* Define Variables, reserve memory  /* Dataset   /* Injured players, their individual scores on this test (n=100)INJ(100)   /*Uninjured Players, their individual scores on this test (n=1000)UNINJ(1000)  /* Populate the dataset - ? direct import from Excel, copy and paste CSV data into a line defining the matricies, ......AVUNINJ(Real) /*Average value of the uninjured population for this score, set as referenceAVUNINJ:=1.26436591  /*True Positive matrixTP(400) /* 400 @ 1% steps  /*True Negative matrixTN(400) /* 400 @ 1% steps  /*False Positive matrixFP(400) /* 400 @ 1% steps  /*False Negative matrixFN(400) /* 400 @ 1% stepsSENS(400) /* Sensitivity, = TP/(TP+FN) for each of the 400 cut-off pointsSPEC(400) /* Specificity, = TN/(FP+TN) for each of the 400 cut-off pointsPLUSLR(400) /* Positive Likelihood Ratio for each of the 400 cut-off points, = SENS/(1-SPEC)MINUSLR(400) /* Negative Likelihood Ratio for each of the 400 cut-off points, = (1-SENS)/SPEC   /* K: integer, local counting variable   /* I: Real, Local cut-off variable/* Main LoopFor I = .01 to 4, Step 0.01 /* Counting from 1% to 400% in 1% steps For K = 1 to Count(INJ)  If(INJ(K)>I*AVUNINJ)   INC TP /* True Positive  Else   INC FN /* False Negative Next K For K = 1 to Count(UNINJ)  If(INJ(K)>I*AVUNINJ)   INC FP /* False Positive  Else   INC TN /* True Negative Next KNext I/* Calculate the individual SENS, SPEC, thence +LR and -LR for each of the 400 steps/* Display results/* Graph PLUSLR, 0.01 to 4 /* Make a graph displyaing the +LR from 1% to 400%/* Graph MINUSLR, 0.01 to 4 /* Make a graph displyaing the -LR from 1% to 400%
2 Replies
Sort By:
Posted 10 years ago
 Thanks, I'll read up on this approach.Rod
Posted 10 years ago
 You can use Import[] to import the Excel file. You'll probably get a list of lists to hold the data. You can apply commands to rows, columns, and tables directly in Mathematica - you may not have to scan through rows and columns as if you were using Pascal. For example, to find the total of the third row, use Total[table[]]. Use functions such as Pick, Position, Select, and Cases to extract data meeting conditions...