none
Creating statistical tests for users to use on an application

    Question

  • Hello,

    I've been looking for tips across the internet, but cant seem to find anything answering my question!

    I am new to visual basic, and attempting to create t-tests on an application for the users to use. I already have an input and save option, so they can upload files. I also have basic statistical features, such as sum, mean, standard deviation, median, sum square error...

    I have no idea where I should start at creating t-tests.. any tips or samples you can give would be amazing!

    Thank you in advance :)

    Saturday, March 18, 2017 2:49 PM

All replies

  • Hello,

    I've been looking for tips across the internet, but cant seem to find anything answering my question!

    I am new to visual basic, and attempting to create t-tests on an application for the users to use. I already have an input and save option, so they can upload files. I also have basic statistical features, such as sum, mean, standard deviation, median, sum square error...

    I have no idea where I should start at creating t-tests.. any tips or samples you can give would be amazing!

    Thank you in advance :)


    Explain what a "t-test" is and what you envision to happen with your application please?

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, March 18, 2017 3:50 PM
  • Most libraries will be in C# e.g.

    http://accord-framework.net/docs/html/T_Accord_Statistics_Testing_TTest.htm

    http://www.centerspace.net/doc/NMathStats/user/hypothesis-tests-79325.htm


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, March 18, 2017 5:54 PM
    Moderator
  • So the basic idea is that they upload a data set into the data grid view, they can they click whether they want an independent t-test or paired-sample t-test. So basically a statistical test comparing the population means.

    There will be radio buttons for them to inform us whether their hypothesis is one tailed or two tailed. 

    The script will run the t-test depending on these options, and spit out a t-value. Which will depend on the degrees of freedom, and a p-value (significance) which would be taken from a t table. 

    I know how to work out a t-test by hand, but can't seem to apply the logic into coding!

    Hopes this explains a little better what I'm after :)

    Thank you!

    Sunday, March 19, 2017 2:23 PM
  • Without a background in statistics it is hard to say how to apply the logic to code.

    If you want to post a small example dataset along with the steps to work out the answer then we might be able to write some example code which duplicates the process, or at least suggest a design along with a list of likely helper methods.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, March 19, 2017 3:02 PM
    Moderator
  • The script will run...

    This is a forum for VB Net. Was that what you meant? If not, you're in the wrong forum.

    If it is what you meant then what have you done with it so far? What are you having a problem with?

    VB isn't Fortran, but it can handle *most* things. There are also some third-party assemblies that can help.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, March 19, 2017 3:15 PM
  • Private Sub BTN_CalTTest_Click(sender As Object, e As EventArgs) Handles BTN_CalTTest.Click

            Dim DataArrayT() As Double, ColIndex1 As Integer


            If TAB_MainForm.SelectedIndex = 0 Then 'page 0, single condition
                ColIndex1 = 0 'column index is 0 by default

                DataArrayT = ColumnToArray(DGV_Con1, ColIndex1)

            End If

            If RBO_Independent.Checked Then
                Dim Results As Double
                Results = MyIndependentT(DataArrayT)
                TXT_TValue.Text = Results

            End If
        End Sub

      Function MyIndependentT(data() As Double) As Double
            'Dim LastIndex As Integer = UBound(data)


            Dim MeanOne As Double = MyMean(data)
            Dim MeanTwo As Double = MyMean(data)
            Dim SDOne As Double = MySD(data)
            Dim SDTwo As Double = MySD(data)
            Dim n1 As Double = DGV_Con1.RowCount
            Dim n2 As Double = DGV_Con1.RowCount

            Dim independentT As Double = (MeanOne - MeanTwo) / Sqrt(SDOne ^ 2 / n1 + SDTwo ^ 2 / n2)
            Return independentT


        End Function

    I already have functions calculating the Mean, Standard Deviation, and number of cells. So i'm attempting to call those functions. However, it seems to be having an issue with calculating the functions, one from collumn one and the other from collumn two in my datagridview. I don't know whether this helps at all! Sorry if it's unclear, I'm still trying to get used to visual basic :)


    • Edited by Shanb3 Monday, March 20, 2017 3:04 PM
    Monday, March 20, 2017 3:04 PM
  • Shan,

    I don't know who you're talking to - we don't all see this forum the same way - but I'll post this for what it's worth.

    A while back I put a simple class together that I call "SimpleStats". If you can use any of this then feel free but as much as anything I hope it'll give you an idea about how to get started with yours.

    Class Code:

    Option Strict On Option Explicit On Option Infer Off Public Class SimpleStats Private _sum As Decimal Private _minimum As Decimal Private _maximum As Decimal Private _range As Decimal Private _mean As Decimal Private _median As Decimal Private _variance As Decimal Private _standardDeviation As Decimal Public Sub New(ByVal values As IEnumerable(Of Decimal)) Try If values Is Nothing Then Throw New ArgumentNullException("IEnumerable(Of Decimal)", "Cannot be null." & vbCrLf) Else CalculateResults(values.ToArray) End If Catch ex As Exception Throw End Try End Sub Public Sub New(ByVal values As IEnumerable(Of Nullable(Of Decimal)), _ Optional ByVal throwIfAllNull As Boolean = True) Try If values Is Nothing Then Throw New ArgumentNullException("IEnumerable(Of Decimal)", "Cannot be null." & vbCrLf) Else Dim tempList As New List(Of Decimal) For Each d As Nullable(Of Decimal) In values If d.HasValue Then tempList.Add(d.Value) End If Next If tempList.Count > 0 Then CalculateResults(tempList.ToArray) Else If throwIfAllNull Then Throw New ArgumentNullException("Collection Of Decimal", "All values in the collection are null." & vbCrLf) End If End If End If Catch ex As Exception Throw End Try End Sub Private Sub CalculateResults(ByVal values() As Decimal) If values IsNot Nothing AndAlso values.Length > 0 Then _sum = values.Sum _minimum = values.Min _maximum = values.Max _range = Math.Abs(_maximum - _minimum) _mean = values.Average If values.Length Mod 2 = 0 Then Dim val1 As Decimal = values(CInt(values.Length / 2) - 1) Dim val2 As Decimal = values(CInt(values.Length / 2)) _median = (val1 + val2) / 2 Else _median = values(CInt(values.Length / 2)) End If Dim tempList As New List(Of Decimal) For Each d As Decimal In values tempList.Add(CDec((d - _mean) ^ 2)) Next _variance = tempList.Average _standardDeviation = CDec(Math.Sqrt(_variance)) End If End Sub Public ReadOnly Property Maximum As Decimal Get Return _maximum End Get End Property Public ReadOnly Property Mean As Decimal Get Return _mean End Get End Property Public ReadOnly Property Median As Decimal Get Return _median End Get End Property Public ReadOnly Property Minimum As Decimal Get Return _minimum End Get End Property Public ReadOnly Property Range As Decimal Get Return _range End Get End Property Public ReadOnly Property StandardDeviation As Decimal Get Return _standardDeviation End Get End Property Public ReadOnly Property Sum As Decimal Get Return _sum End Get End Property Public ReadOnly Property Variance As Decimal Get Return _variance End Get End Property End Class


    I tested it using the code shown following:

    Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load Test01() Test02() Test03() Test04() Stop End Sub Private Sub Test01() Try Dim nums() As Decimal = {1.1D, 2.2D, 3.3D, 4.4D, 5.5D} Dim ss As New SimpleStats(nums) Stop Catch ex As Exception MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _ vbCrLf, ex.Message), _ "Exception Thrown", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) End Try End Sub Private Sub Test02() Try Dim numList As New List(Of Nullable(Of Decimal)) numList.Add(-1) numList.Add(2.22D) numList.Add(-3) numList.Add(4.44D) Dim ss As New SimpleStats(numList) Stop Catch ex As Exception MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _ vbCrLf, ex.Message), _ "Exception Thrown", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) End Try End Sub Private Sub Test03() Try Dim numList As New List(Of Nullable(Of Decimal)) Dim ss As New SimpleStats(numList, False) Stop Catch ex As Exception MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _ vbCrLf, ex.Message), _ "Exception Thrown", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) End Try End Sub Private Sub Test04() Try Dim numList As New List(Of Nullable(Of Decimal)) Dim ss As New SimpleStats(numList) Stop Catch ex As Exception MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _ vbCrLf, ex.Message), _ "Exception Thrown", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) End Try End Sub End Class


    If you'll create a new project and use that, you can test it. For each of the test subs in Form1, hover your mouse over the local variable "ss" and you'll see the results:

    I hope that might help some.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Thursday, March 30, 2017 3:42 PM ...modified the URL of the screenshot image.
    Monday, March 20, 2017 3:25 PM