VB Box Cox Example

← All NMath Code Examples

 

Imports System

Imports CenterSpace.NMath.Core


Namespace CenterSpace.NMath.Examples.VisualBasic

  A .NET example in Visual Basic
  Module BoxCoxExample

    Sub Main()

      The data to be transformed.
      Dim Data As New DoubleVector("[.15 .09 .18 .10 .05 .12 .08 .05 .08 .10 .07 .02 .01 .10 .10 .10 .02 .10 .01 .40 .10 .05 .03 .05 .15 .10 .15 .09 .08 .18 .10 .20 .11 .30 .02 .20 .20 .30 .30 .40 .30 .05]")

      The interval to search for the value of lambda which maximizes the log-likelihood
      function.
      Dim lambdaInterval As New Interval(-3, 3, Interval.Type.Closed)

      We want lambda values less than 0.01 to be considered equal to zero.
      Dim lambdaEpsilon As Double = 0.01

      Construct a BoxCox for the given data and lambda information.
      Dim BC As New BoxCox(Data, lambdaInterval, lambdaEpsilon)

      Console.WriteLine()

      Write the optimal lambda and the transformed data Imports that lambda value.
      Console.WriteLine("Optimal lambda value in {0} is {1}", BC.LambdaInterval, BC.Lambda)
      Console.WriteLine(Environment.NewLine & "Transformed data:")
      Console.WriteLine(BC.TransformedData.ToString("G5"))

      Print out the log-likelihood function for the data at the optimal lambda value.
      Console.WriteLine(Environment.NewLine & "Value of the log-likelihood function at lambda = {0} is {1}", _
  BC.Lambda, BoxCox.LogLikelihood(Data, BC.Lambda))

      Transform some other data Imports a lambda value of 0.27.
      Dim lambda As Double = 0.27
      Dim Y As New DoubleVector(10, New RandGenBeta(2.2))
      Dim transformedY As DoubleVector = BoxCox.Transform(Y, lambda)
      Console.WriteLine(Environment.NewLine & "y transformed with lambda = {0}:", lambda)
      Console.WriteLine(transformedY.ToString("G5"))

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

    End Sub

  End Module

End Namespace

← All NMath Code Examples
Top