VB Missing Values Example

← All NMath Code Examples


Imports System
Imports System.Globalization
Imports System.Threading

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Core.Examples.VisualBasic

  ' A .NET example in Visual Basic showing how to perform statistical operations on a matrix containing
  ' missing data.
  Module MissingValuesExample

    Sub Main()

      Dim Original As CultureInfo = Thread.CurrentThread.CurrentCulture

      ' This example uses strings representing numbers in the US locale
      ' so change the current culture info.  For example, "NaN"
      Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")

      ' Matrix A contains experimental drug results. Rows represent data for seven patients.
      ' Columns represent cholesterol levels before and after a drug regimen. No data is
      ' available for two of the patients.
      Dim A As New DoubleMatrix("7x2 [280 260 NaN NaN 335 338 310 220 NaN NaN 378 335 288 279]")

      ' Back to original culture
      Thread.CurrentThread.CurrentCulture = Original

      ' Average the columns and display results

      ' Throw out patient #3
      A.Set(2, Slice.All, Double.NaN)

      ' Average the columns and display results

      Console.WriteLine("Press Enter Key")

    End Sub

        Private Sub DisplayResults(ByVal Results As DoubleVector)

            Console.Write("Mean cholesterol level before trial: ")
            Console.Write("Mean cholesterol level after trial: ")
            Console.Write("Mean drop in cholesterol level: ")
            Console.WriteLine(Results(1) - Results(0))

        End Sub

  End Module

End Namespace

← All NMath Code Examples