Last modified: Thu, 05/07/2020 - 12:43
BIN_INDEX_WT (INDEX, WT, INDMAX) Returns data sorted into bins along an X axis
Arguments: | INDEX | Bin indices: sorted, 1D on x axis |
WT | Weight for each index | |
INDXMAX |
Length of result axis |
|
Result Axes: | X |
ABSTRACT |
Y | NORMAL | |
Z | NORMAL | |
T | NORMAL | |
E | NORMAL | |
F | NORMAL |
Examples: This function is called by the script frequency_histogram2.jnl
Here is an annotated example similar to frequency_histogram2.jnl
yes? ! Define some data to use - we need a 1-D list in X yes? LET myvar = { 9.04, 8.67, 8.96, 9.29, 9.18, 9.42,\ ...? 9.43, 9.33, 9.19, 9.22, 9.12, 9.36, 9.22, 9.04, 8.92, 9.00, 8.59,\ ...? 8.31, 8.69, 8.20, 8.86, 7.98, 7.80, 8.29, 7.94, 8.05, 7.85, 7.55,\ ...? 7.56, 6.82, 7.04, 6.66, 6.56, 7.36, 6.52} yes? ! Get the data range and define some bins. yes? stat/brief myvar Total # of data points: 35 (35*1*1*1*1*1) # flagged as bad data: 0 Minimum value: 6.52 Maximum value: 9.43 Mean value: 8.372 (unweighted average) yes? LET vmin = 6.5 yes? LET vmax = 10 yes? LET vdelta = 0.5 yes? ! Compute number of bins yes? LET vn = INT((vmax-vmin)/vdelta + 0.5) + 1 yes? ! Sort the data yes? LET sort_var = SAMPLEI(myvar, SORTI(myvar)) yes? ! Define a weight function for each data point, here all 1. yes? ! The weights need to be sorted identically to the data so yes? ! weights stay with the right data values. yes? LET wt_index = 1+0*myvar yes? LET sort_wt = SAMPLEI(wt_index, SORTI(myvar)) yes? ! Vindex is the bin number corresponding to the data value yes? LET vindex = INT((sort_var-vmin)/vdelta + 0.5) + 1 yes? list sort_var, vindex X: 0.5 to 35.5 Column 1: SORT_VAR is SAMPLEI(MYVAR, SORTI(MYVAR)) Column 2: VINDEX is INT((SORT_VAR-VMIN)/VDELTA + 0.5) + 1 SORT_VAR VINDEX 1 / 1: 6.520 1.000 2 / 2: 6.560 1.000 3 / 3: 6.660 1.000 4 / 4: 6.820 2.000 5 / 5: 7.040 2.000 6 / 6: 7.360 3.000 7 / 7: 7.550 3.000 8 / 8: 7.560 3.000 9 / 9: 7.800 4.000 10 / 10: 7.850 4.000 11 / 11: 7.940 4.000 12 / 12: 7.980 4.000 13 / 13: 8.050 4.000 14 / 14: 8.200 4.000 15 / 15: 8.290 5.000 16 / 16: 8.310 5.000 17 / 17: 8.590 5.000 18 / 18: 8.670 5.000 19 / 19: 8.690 5.000 20 / 20: 8.860 6.000 21 / 21: 8.920 6.000 22 / 22: 8.960 6.000 23 / 23: 9.000 6.000 24 / 24: 9.040 6.000 25 / 25: 9.040 6.000 26 / 26: 9.120 6.000 27 / 27: 9.180 6.000 28 / 28: 9.190 6.000 29 / 29: 9.220 6.000 30 / 30: 9.220 6.000 31 / 31: 9.290 7.000 32 / 32: 9.330 7.000 33 / 33: 9.360 7.000 34 / 34: 9.420 7.000 35 / 35: 9.430 7.000 yes? ! BIN_INDEX_WT counts the number of items in each bin yes? LET fh_fbins = BIN_INDEX_WT(vindex, sort_wt, vn) yes? list fh_fbins VARIABLE : BIN_INDEX_WT(VINDEX, SORT_WT, VN) SUBSET : 9 points (X) 1 / 1: 3.00 2 / 2: 2.00 3 / 3: 3.00 4 / 4: 6.00 5 / 5: 5.00 6 / 6: 11.00 7 / 7: 5.00 8 / 8: 0.00 9 / 9: 0.00 yes? ! Now make a plot, using one of the bar_chart scripts yes? ! Define an independent axis for the bin plot yes? DEFINE AXIS/Y=`vmin`:`vmax`:`vdelta` yax !-> DEFINE AXIS/Y=6.5:10:0.5 yax yes? ! Define the count variable to send to bar_chart2 yes? ! (see yes? go/help bar_chart2.jnl) yes? LET fh_wc = RESHAPE(fh_fbins, y[gy=yax]) yes? LET wt_count = MISSING(fh_wc, 0.) yes? GO bar_chart2 PLOT/LINE/COLOR=blue wt_count y yes? ! or a filled chart yes? ! (see yes? go/help bar_chart3.jnl) yes? GO bar_chart3 POLY/LINE/NOLABEL/FILL wt_count wt_count
NOTE: Defining the bins as above puts the center of the bins at the points vmin, vmin+vdelta, vmin+2*vdelta, ... The commands could be instead defined to make, for instance, bins from 6.0:6.5, then 6.5:7.0, then 7.0:7.5, etc.