Calculates how often values occur within a given set of ranges.

View versions (1)

Interface

Overview

This function calculates how many values in the given set of data fall within each interval of the bin array, while also calculating the number of values below and above the bin extremas. For example, use this function to count the number of test scores that fall within ranges of scores.

Example:

#include<iostream>
#include<codecogs/statistics/moments/frequency.h>
int main()
{
  double
  x[11]={160, 130, 100, 70, 52, 28, 27,26, 14.25, -1, -7 },
   y[4]={10, 25, 40.7, 61.3};
  std::vector<int> result=Stats::Moments::frequency(11,x,4,y);
  std::cout<<"The corresponding frequencies for the x array are:";
  std::cout<<std::endl;
  for(int i=0; i<result.size(); i++)
    std::cout<<result[i]<<" ";
  std::cout<<std::endl;
  return 0;
}

Output:

The corresponding frequencies for the x array are:
2 1 3 1 4

i.e. 6 numbers in total fall outside the designated range

Parameters

n
the total number of data points in array data
data
an array of n data point
m
the total elements in array bin, which should be 1 more than the number of bins you need to define
bin
the bounds of each bin, therefore given the lower and upper boundaries and shared common boundaries to each bin, there should be (number bins +1) values.

Returns

the number of times the values in the data set occur within each defined bin. Values falling below the range given in bin are returned in element[0], while values falling above the given range are returned in element[m+1]. Therefore the return array is always two larger that the bin array, contains m+2 elements.
GPL Licence — free for non commercial use. See Licence details.

Members of Frequency

CLASS MEMBER

m_delta

CLASS MEMBER

m_N

CLASS MEMBER

m_num

CLASS MEMBER

m_count

CLASS METHOD

Frequency

Establishes the Frequency contains which will hold the underlying histogram of results

Parameters

max
the end of the largest bin
min
the start of the smallest bin
N
the number of bins to create

CLASS METHOD

add

CLASS METHOD

reset

CLASS METHOD

get_count

CLASS METHOD

get_x

Returns the coordinate of middle of each bin:

x=m_{min} + (i+0.5) \Delta
(1)

where \Delta is the width of each bin equal to max value minus the min value divided by the number of bins.

Parameters

i
the i th value

CLASS METHOD

get_freq

Parameters

i
the i th value