Message Boards Message Boards

0
|
2732 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Help converting some simple code to Mathematica

Posted 11 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 reference
AVUNINJ:=1.26436591
  /*True Positive matrix
TP(400) /* 400 @ 1% steps
  /*True Negative matrix
TN(400) /* 400 @ 1% steps
  /*False Positive matrix
FP(400) /* 400 @ 1% steps
  /*False Negative matrix
FN(400) /* 400 @ 1% steps
SENS(400) /* Sensitivity, = TP/(TP+FN) for each of the 400 cut-off points
SPEC(400) /* Specificity, = TN/(FP+TN) for each of the 400 cut-off points
PLUSLR(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 Loop
For 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 K
Next 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%
POSTED BY: Rod Whiteley
2 Replies
Thanks, I'll read up on this approach.
Rod
POSTED BY: Rod Whiteley
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[[3]]]. Use functions such as Pick, Position, Select, and Cases to extract data meeting conditions...
POSTED BY: C ormullion
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract