NMath User's Guide

TOC | Previous | Next | Index

Chapter 38. Descriptive Statistics (.NET, C#, CSharp, VB, Visual Basic, F#)

Class StatsFunctions provides a wide variety of static functions for computing descriptive statistics, such as mean, variance, standard deviation, percentile, median, quartiles, geometric mean, harmonic mean, RMS, kurtosis, skewness, and many more.

Method overloads accept data as an array of doubles, as a DoubleVector, or as a column in a DataFrame (Chapter 37). For example:

Code Example – C#

double[] dblArray = { 1.12, -2.0, 3.88, 1.2, 15.345 };
double mean1 = StatsFunctions.Mean( dblArray );



var v = new DoubleVector( "1.12 -2.0 3.88 1.2 15.345"  );
double mean2 = StatsFunctions.Mean( v );



var df = new DataFrame();
df.AddColumn(
  new DFNumericColumn( "myData", 1.12, -2.0, 3.88, 1.2, 15.345 ) );
double mean3 = StatsFunctions.Mean( df[ "myData" ] );  



// mean1 == mean2 == mean3

Code Example – VB

Dim DblArray() As Double = {1.12, -2.0, 3.88, 1.2, 15.345}
Dim Mean1 As Double = StatsFunctions.Mean(DblArray)



Dim V As New DoubleVector("1.12 -2.0 3.88 1.2 15.345")
Dim Mean2 As Double = StatsFunctions.Mean(V)



Dim DF As New DataFrame()
DF.AddColumn(New DFNumericColumn("myData", 1.12, -2.0, 3.88, 1.2, 
  15.345))
Dim Mean3 As Double = StatsFunctions.Mean(DF("myData"))



'' mean1 == mean2 == mean3

In this chapter, where data is used in code examples, it should be understood to be an instance of any of these three types.


Top

Top