Click here to Skip to main content
15,911,132 members
Articles / Programming Languages / Visual Basic
Article

Statistic Class

Rate me:
Please Sign up or sign in to vote.
3.06/5 (8 votes)
9 Feb 2007CPOL1 min read 36.1K   681   17   2
This class has some Statistical function such as mean , variance,...

Introduction

This is a class written in vb.net. It has 8 Functions

  • Max
  • Min
  • Median
  • Mean
  • Variance
  • Covariance
  • VarCovarMatrix
  • Correlation

How to use it ...

Step 1-Add this class to your project. (Add Existing Items )
Step 2-Create an instance :

dim Ins_name as new statistic

call the functions you need from Ins_name.

Min and Max :

You can calculate the Min (max) of byte,integer or double arrays of one,two or three dimention.

each functions has 9 Overload.

Mean :

you can calculate the mea of byte,integer or double array. BUT have you ever think if you could be able to calculate the mean of several or more arrays at the same time.

I means that you do not need to call the class several times to calculate the mean of them. you can create an jagged array and use it as input so you will find the result as an array!
Example : you want to calculate the mean of to arrays ( array1, array2)

dim jagged_array(1)() as double

jagged_array(0)()=array1

jagged_array(1)()=array2

dim mean_array() as double=statistic.mean(jagged_array)

dim mean1 as double = mean_array(0)

dim mean2 as double = mean_array(1)

You can do the same for variance.

Please...

as you see my English is not very well so please tell me if you had any problem using this class.

Enjoy it. (YA ALI)


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSpeed Pin
SteveAbbott10-Feb-07 6:20
SteveAbbott10-Feb-07 6:20 
Thanks for giving us a handy set of statistics calcs.

You may want to tidy up the code a bit to speed it up. Here are a few friendly suggestions.

For example, in calculating Max you have code such as
For i = 1 To l - 1
If Array(i) > Result Then
Result = Array(i)
Temp = Array(i)
Else
Temp = Array(i)
End If
Next
But the variable Temp is doing nothing so you can eliminate it

For calculating Means you use code like
For i = 0 To l - 1
Temp = Array(i) + Temp
Next
It probably doesn't make much difference to speed but it's more usual to write it as
For i = 0 To l - 1
Temp += Array(i)
Next

More significant is the use of ^2 for squaring values. This is very slow. There's a 9x speed improvement in Var if you change

For i = 0 To l - 1
Temp += (Array(i) - mo)^2
Next
to

For i = 0 To l - 1
Temp += (Array(i) - mo) * (Array(i) - mo)
Next

Finally, it's now usual to use Option Strict On as this tends to speed up code. In order for Median to work you currently have to set Option Strict Off - it will probably be faster if you can recode Median so it works with Option Strict On.

Steve

AnswerRe: Speed Pin
Hossein Narimani Rad11-Feb-07 8:35
Hossein Narimani Rad11-Feb-07 8:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.