I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 2.00
sub units 0.00
+
0

Frequency

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

add cart

Interface

C++

Frequency

 
template<class T> std::vector<int>frequencyintn
T*data
intm
T*bin )
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

nthe total number of data points in array data
dataan array of n data point
mthe total elements in array bin, which should be 1 more than the number of bins you need to define
binthe 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.

Authors

Will Bateman (Sep 2007)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


Class Frequency

This class is usefull in generating a histogram of a sequence of dispersed numbers. The class is initialised with the expect range of numbers (min and max) and the number of bins to create. The class will actually create 2 further bins, that captures values that fall below min and another than catches values that fall above max.

Example 1

#include <codecogs/statistics/distributions/continuous/beta/randomsample.h> 
#include <codecogs/statistics/moments/frequency.h>
 
int main(int argc, char* argv[])
{
  Stats::Dists::Continuous::Beta::RandomSample m_Betagen;
  Stats::Moments::Frequency bins(20,0,1);
 
  for(int i=0; i<10000; i++)
  {
    double val = m_Betagen.genReal(0.2, 3);
    bins.add(val);
  }
 
  for(int i=0;i<22;i++)
    printf("\n%d %lf %d %lf ",i, bins.get_x(i), bins.get_count(i), bins.get_freq(i));
}
Output
0 -0.025000 0 0.000000 
1 0.025000 7095 0.709500 
2 0.075000 944 0.094400 
3 0.125000 569 0.056900 
4 0.175000 355 0.035500 
5 0.225000 269 0.026900 
6 0.275000 196 0.019600 
7 0.325000 143 0.014300 
8 0.375000 133 0.013300 
9 0.425000 70 0.007000 
10 0.475000 63 0.006300 
11 0.525000 53 0.005300 
12 0.575000 32 0.003200 
13 0.625000 36 0.003600 
14 0.675000 19 0.001900 
15 0.725000 7 0.000700 
16 0.775000 7 0.000700 
17 0.825000 5 0.000500 
18 0.875000 2 0.000200 
19 0.925000 2 0.000200 
20 0.975000 0 0.000000 
21 1.025000 0 0.000000
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of Frequency

Frequency

 
FrequencyintN
doublemin = 0
doublemax = 1 )[constructor]
Establishes the Frequency contains which will hold the underlying histogram of results
Nthe number of bins to create
minthe start of the smallest bin
maxthe end of the largest bin

Get X

 
doubleget_xinti )
Returns the coordinate of middle of each bin: where \Delta is the width of each bin equal to max value minus the min value divided by the number of bins.
ithe i th value

Get Freq

 
doubleget_freqinti )
ithe i th value