tableOneway¶
Tallies observations into a one-way frequency table.
Synopsis¶
tableOneway (x)
Required Arguments¶
- float
x[]
(Input) - Array of length
nObservations
containing the observations.
Return Value¶
An array of length nIntervals
containing the counts.
Optional Arguments¶
dataBounds
,minimum
,maximum
(Output)- If none is specified or if
dataBounds
is specified,nIntervals
intervals of equal length are used with the initial interval starting with the minimum value inx
and the last interval ending with the maximum value inx
. The initial interval is closed on the left and right. The remaining intervals are open on the left and closed on the right. WhendataBounds
is explicitly specified, the minimum and maximum values inx
are output inminimum
andmaximum
. With this option, each interval is of length (maximum
−minimum
)/nIntervals
.
or
knownBounds
,lowerBound
,upperBound
(Input)If
knownBounds
is specified, two semi-infinite intervals are used as the initial and last intervals. The initial interval is closed on the right and includeslowerBound
as its right endpoint. The last interval is open on the left and includes all values greater thanupperBound
. The remainingnIntervals
− 2 intervals are each of length\[\frac{\mathrm{upperBound} - \mathrm{lowerBound}}{\mathrm{nIntervals} - 2}\]and are open on the left and closed on the right. Argument
nIntervals
must be greater than or equal to 3 for this option.
or
cutpoints
, float[]
(Input)- If
cutpoints
is specified, cutpoints (boundaries) must be provided in the arraycutpoints
of lengthnIntervals
− 1. This option allows unequal interval lengths. The initial interval is closed on the right and includes the initial cutpoint as its right endpoint. The last interval is open on the left and includes all values greater than the last cutpoint. The remainingnIntervals
− 2 intervals are open on the left and closed on the right. ArgumentnIntervals
must be greater than or equal to 3 for this option.
or
classMarks
, float[]
(Input)If
classMarks
is specified, equally spaced class marks in ascending order must be provided in the arrayclassMarks
of lengthnIntervals
. The class marks are the midpoints of each of thenIntervals
. Each interval is assumed to have lengthclassMarks
[1
] −classMarks
[0
]. ArgumentnIntervals
must be greater than or equal to 2 for this option.None or exactly one of the four optional arguments described above can be specified in order to define the intervals or bins for the one-way table.
Examples¶
Example 1¶
The data for this example is from Hinkley (1977) and Velleman and Hoaglin (1981). The measurements (in inches) are for precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.
from numpy import *
from pyimsl.stat.tableOneway import tableOneway
from pyimsl.stat.writeMatrix import writeMatrix
n_intervals = 10
x = array([0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05])
table = tableOneway(x, nIntervals=n_intervals)
writeMatrix("Counts", table, writeFormat="%10i")
Output¶
Counts
1 2 3 4 5 6
4 8 5 5 3 1
7 8 9 10
3 0 0 1
Example 2¶
In this example, knownBounds
is used, and lowerBound
= 0.5 and
upperBound
= 4.5 are set so that the eight interior intervals each have
width \((4.5-0.5)/(10-2)=0.5\). The 10 intervals are
\(\left(-\infty,0.5\right],\left(0.5,1.0\right],\ldots,\left(4.0,4.5\right],\text{
and }\left(4.5,\infty\right]\).
from numpy import *
from pyimsl.stat.tableOneway import tableOneway
from pyimsl.stat.writeMatrix import writeMatrix
n_intervals = 10
x = array([0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05])
knownBounds = {}
knownBounds["lowerBound"] = 0.5
knownBounds["upperBound"] = 4.5
table = tableOneway(x, n_intervals, knownBounds=knownBounds)
writeMatrix("Counts", table, writeFormat="%10i")
Output¶
Counts
1 2 3 4 5 6
2 7 6 6 4 2
7 8 9 10
2 0 0 1
Example 3¶
In this example, 10 class marks, 0.25, 0.75, 1.25, …, 4.75, are input. This defines the class intervals (0.0, 0.5], (0.5, 1.0], …, (4.0, 4.5], (4.5, 5.0]. Note that unlike the previous example, the initial and last intervals are the same length as the remaining intervals.
from numpy import *
from pyimsl.stat.tableOneway import tableOneway
from pyimsl.stat.writeMatrix import writeMatrix
n_intervals = 10
x = array([0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05])
classMarks = [0.25, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75]
table = tableOneway(x, n_intervals, classMarks=classMarks)
writeMatrix("Counts", table, writeFormat="%10i")
Output¶
Counts
1 2 3 4 5 6
2 7 6 6 4 2
7 8 9 10
2 0 0 1
Example 4¶
In this example, cutpoints, 0.5, 1.0, 1.5, 2.0, …, 4.5, are input to define the same 10 intervals as in Example 2. Here again, the initial and last intervals are semi-infinite intervals.
from numpy import *
from pyimsl.stat.tableOneway import tableOneway
from pyimsl.stat.writeMatrix import writeMatrix
n_intervals = 10
x = array([0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32,
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96,
1.89, 0.90, 2.05])
cutpoints = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
table = tableOneway(x, n_intervals, cutpoints=cutpoints)
writeMatrix("Counts", table, writeFormat="%10i")
Output¶
Counts
1 2 3 4 5 6
2 7 6 6 4 2
7 8 9 10
2 0 0 1