# VB Multiple Linear Regression Example

← All NMath Core Code Examples

```Imports System
Imports System.IO
Imports System.Collections

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Core.Examples.VisualBasic

' A .NET example in Visual Basic showing how to perform multiple linear regression.
Module MultipleLinearRegressionExample

Sub Main()

' First read in the independent (or predictor) values. This is a matrix
' with one column and a row for each amounts measurement.
Dim LongLatValues As DoubleMatrix = New DoubleMatrix(DataStream)

' Next, read in the responses. These are the readings of the gas
' chromatograph
Dim JanTemp As DoubleVector = New DoubleVector(DataStream)

' Print out the amounts and responses values.
Console.WriteLine()
Console.WriteLine("Longitudes and latitudes =")
Console.WriteLine(LongLatValues.ToTabDelimited("G7"))
Console.WriteLine()
Console.WriteLine("January temperatures =")
Console.WriteLine(JanTemp)
Console.WriteLine()

Dim Regression As LinearRegression = New LinearRegression(LongLatValues, JanTemp, True)
Dim RegressionAnova As LinearRegressionAnova = New LinearRegressionAnova(Regression)

Dim RegressionStats As DataFrame = New DataFrame()
Dim DFCol As DFIntColumn = New DFIntColumn("df")

Console.WriteLine("Dependent Variable is:       January Temp")
Console.WriteLine(Regression.NumberOfObservations & " total cases")
Console.WriteLine("R squared = " & RegressionAnova.RSquared.ToString("P"))

Console.WriteLine("s = {0} with {1} degrees of freedom",
System.Math.Sqrt(Regression.Variance).ToString("G5"),
Regression.NumberOfObservations - Regression.NumberOfParameters)
Console.WriteLine()
Console.WriteLine(RegressionStats)

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