igor help file for calculation of median
vinodmagic
Function/D Median(w, x1, x2) // Returns median value of wave w
Wave w
Variable x1, x2 // range of interest
Variable result
Duplicate/R=(x1,x2) w, tempMedianWave // Make a clone of wave
Sort tempMedianWave, tempMedianWave // Sort clone
SetScale/P x 0,1,tempMedianWave
result = tempMedianWave((numpnts(tempMedianWave)-1)/2)
KillWaves tempMedianWave
return result
End
why do we need to scale tempMedianWave.I guess it is already scaled while duplicating. I cudnot find find any difference if i do not use SetScale.
Please help me to understand.
Vinod
That there is no difference for you without this command most definitely owns to the fact that you probably already start with a wave 'w' using the default scaling, which is 0,1. Try to scale your test wave to, say, start = 53, delta = 0.13 and see if you can still live without the extra scaling.
October 28, 2012 at 06:26 am - Permalink
I wanted to extend this program to calculate random percentiles(say 95th). At first it was not clear to me, how IGOR calculates 95th percentile? For a dataset attached below i tried to calculate 75th percentile by two ways
1 using analysis>statistics>calculate percentile
2. using StatsQuantiles
both the methods give different values for 75th percentile.
I wrote a function to calculate percentile which gives similar result that i get from StatsQuantiles.
Vinod Kumar
IISER Mohali
October 29, 2012 at 04:49 am - Permalink
// This combined with Igor's auto interpolation results in the standard definition of the median:
// if N is even, average the two middle values; if N is odd, take the middle value.
// percentileCutoff = TmpPercentiles[j]*nReps - 0.5
// // for percentiles other than 0.5 (the median) we simply pick the value whose sequence number is
// // closest to N*quantile. This also guarantees that the 1 quantile (100th percentile) takes the last good number,
// // not the next number past the last good number.
// if (TmpPercentiles[j] != 0.5)
// percentileCutoff = floor(percentileCutoff)
// if (percentileCutoff > nReps-1)
// percentileCutoff = nReps - 1
// endif
// endif
// This is the formula advocated by NIST on http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm
// It corresponds to Q6 on the URL above.
percentileCutoff = TmpPercentiles[j]*(nReps+1) - 1
if (percentileCutoff < 0)
percentileCutoff = 0
elseif (percentileCutoff > nReps-1)
percentileCutoff = nReps-1
endif
// According to NIST, Excel uses this which corresponds to Q7 on the mathworld web site.
// percentileCutoff = TmpPercentiles[j]*(nReps-1)
// if (percentileCutoff < 0)
// percentileCutoff = 0
// elseif (percentileCutoff > nReps-1)
// percentileCutoff = nReps-1
// endif
There is generally agreement that the median for an even number of points is the average of the two data points on either side of the middle. But there are several different definitions for quantiles other than the median. Take a look at the links above- they are authoritative.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 29, 2012 at 09:07 am - Permalink