创建正态分布图(高斯钟形曲线)vb.net

时间:2016-10-11 21:50:50

标签: asp.net vb.net charts statistics

我想为以下数据创建一个钟形曲线图:

+--------------------+
| SCORE  |Normal Dist|
|--------------------+
|   1    |0.02194562 |
| 1.125  |0.029935308|
| 1.5    |0.068504536|
| 1.625  |0.087211517|
| 1.625  |0.087211517|
| 1.875  |0.134213698|
| 2      |0.162242762|
| 2      |0.162242762|
| 2.25   |0.225121142|
| 2.375  |0.258403711|
| 2.375  |0.258403711|
| 2.458  |0.280491635|
| 2.583  |0.312845655|
|   .    |    .      |
|   .    |    .      |
|   .    |    .      |

它达到了62个值,我从sql表中获得了分数,并且我在asp.net页面上为每个值计算正态分布,如下所示:

Dim dtScores as Datatable = new Datatable
dtScores = EvaRH.GetScores(strLocation, "04/30/2015", "03/30/2016")

dtScores.DefaultView.Sort = "Score ASC"
Dim dvScore As DataView = dtScores.DefaultView

Dim intTotal as integer = dtScores.Rows.Count
Dim dbScore as Double

For i As Integer = 0 To intTotal - 1
   dbScore += Convert.ToDouble(dtScores.Rows(i).Item(0).ToString)
Next

'Gets the Average of the data (Mean)
dbScore = dbScore / intTotal

Dim dbStdDev as Double

'This calculate the Standard Deviation
For i As Integer = 0 To intTotal - 1
    dbStdDev += Math.Pow((Convert.ToDouble(dtScores.Rows(i).Item(0).ToString) - dbScore), 2)
Next
dbDesvStd = dbDesvStd / (intTotal)
dbDesvStd = Math.Sqrt(dbDesvStd)

Dim dtNormal as Datatable = New Datatable
dtNormal.Columns.Add(New DataColumn("Score", GetType(Double)))
dtNormal.Columns.Add(New DataColumn("Normal Dist", GetType(Double)))

Dim dr as DataRow   

'Here I calculate the Normal Distribution of each point
For Each Row As DataRowView In dvScore
    dr = dtNormal.NewRow()
    dr("Score") = Convert.ToDouble(Row.Item(0).ToString)
Math.Pow(((Convert.ToDouble(Row.Item(0).ToString)) - dbScore), 2)


        dbNormal = (1 / (dbDesvStd * (Math.Sqrt(2 * Math.PI)))) * (Math.Exp(-(Math.Pow(((Convert.ToDouble(Row.Item(0).ToString)) - dbPromedio), 2) / (2 * Math.Pow(dbDesvStd, 2)))))
        dr("Normal Dist") = dbNormal
        dtNormal.Rows.Add(dr)
    Next


    Dim XPointMember As String() = New String(dtNormal.Rows.Count - 1) {}
    Dim YPointMember As Double() = New Double(dtNormal.Rows.Count - 1) {}
    For int As Integer = 0 To dtNormal.Rows.Count - 1

        XPointMember(int) = dtNormal.Rows(int).Item(0).ToString
        YPointMember(int) = Convert.ToDouble(dtNormal.Rows(int).Item(1))

    Next
    'binding chart control  

    chBell.Series(0).Points.DataBindXY(XPointMember, YPointMember)

    chBell.Series(0).ChartType = SeriesChartType.Spline

有了这个,我得到一个像这样的图表: enter image description here

你可以看到它不是钟形曲线。 我在excel中做了同样的过程,我确实得到了正确的钟形曲线,我有相同的Mean,StdDev和NormDist值,但我不知道为什么我不能在vb.net上获得相同的图表,任何帮助将不胜感激

这是我从Excel获得的图表 enter image description here

Question让我想到了以前的代码。

Here是带有完整数据和图表的Excel工作表。

0 个答案:

没有答案