VB Probability Distribution Example

← All NMath Stats Code Examples

 

Imports System
Imports System.Collections

Imports CenterSpace.NMath.Core
Imports CenterSpace.NMath.Stats

Namespace CenterSpace.NMath.Stats.Examples.VisualBasic

  ' A .NET example in Visual Basic showing how to use the probability distribution classes.

  ' NMath Stats provides classes for computing the probability density
  ' function (PDF), the cumulative distribution function (CDF), the inverse
  ' cumulative distribution function, and random variable moments for a
  ' variety of probability distributions, including normal (Gaussian), Poisson,
  ' chi-square, gamma, beta, Student's t, F, binomial, and negative binomial.
  Module ProbabilityDistributionExample

    Sub Main()

      ' The distribution classes share a common interface, so once you
      ' learn how to use one distribution class, it’s easy to use any of
      ' the others. This code constructs an F distribution object with
      ' degrees of freedom 9,24.
      Dim DF1 As Integer = 9
      Dim DF2 As Integer = 24

      Dim Dist As New FDistribution(DF1, DF2)

      Console.WriteLine()
      Console.WriteLine(Dist)
      Console.WriteLine()

      ' Pick a sample value for the F statistic.
      Dim FStat As Double = 3.94
      Console.WriteLine("Sample F statistic =" & FStat)
      Console.WriteLine()

      ' The PDF() method computes the probability density function
      ' evaluated at a given value. The probability of
      ' observing an F-statistic of 3.94 is given by:
      Console.WriteLine("PDF = " & Dist.PDF(FStat))

      ' The CDF() method computes the cumulative density function
      ' evaluated at a given value. Find the probability of
      ' observing an F-statistic of 3.94 or less, and the probability
      ' of observing an F-statistic greater than 3.94:
      Console.WriteLine("CDF = " & Dist.CDF(FStat))
      Console.WriteLine("Upper tail probability = " & (1 - Dist.CDF(FStat)))
      Console.WriteLine()

      ' The InverseCDF() computes the inverse cumulative density
      ' function evaluated at a given value. Calculate left and right
      ' critical values for 0.01 alpha level:
      Dim Alpha As Double = 0.01
      Console.WriteLine("Alpha = " & Alpha)
      Console.WriteLine("Left critical value = " & Dist.InverseCDF(Alpha))
      Console.WriteLine("Right critical value = " & Dist.InverseCDF(1 - Alpha))
      Console.WriteLine()

      ' Properties are provided for getting the first four moments of a
      ' distribution.
      Console.WriteLine("Mean of distribution = " & Dist.Mean)
      Console.WriteLine("Variance of distribution = " & Dist.Variance)
      Console.WriteLine("Skewness of distribution = " & Dist.Skewness)
      Console.WriteLine("Kurtosis of distribution = " & Dist.Kurtosis)
      Console.WriteLine()

      Console.WriteLine()
      Console.WriteLine("Press Enter Key")
      Console.Read()

    End Sub

  End Module

End Namespace
← All NMath Stats Code Examples
Top