Author |
Topic  |
|
Alice
25 Posts |
Posted - 01 Feb 2008 : 14:16:17
|
I am tring to add a bell curve on my FrequencyHistogram control,but it only draws a straight line. Can you tell what I do wrong:
Here are the data I use:
Dim freqValues() As Double = {4.65, 4.56, 4.59, 4.63, 4.62, 4.65, 4.6, 4.63,4.55, 4.66, 4.67, 4.62, 4.68, 4.62, 4.53, 4.63, 4.6, 4.64, 4.55, 4.65, 4.62, 4.68, 4.61, 4.65, 4.64, 4.6, 4.67,4.6, 4.63, 4.63, 4.58, 4.56, 4.62, 4.6, 4.56, 4.56,4.61, 4.65, 4.55, 4.6, 4.62,4.60,4.58,4.66,4.65}
Dim freqLimits() As Double = {4.48, 4.52, 4.56, 4.60,4.64,4.69,4.73}
Dim mean As Double = SPCArrayStatistics.GetMean(freqValues) Dim standarddeviation As Double = SPCArrayStatistics.GetStandardDeviation(freqValues) AddGaussianCurve(Me, mean, standarddeviation, Color.Yellow)
Thanks!
|
|
quinncurtis
1164 Posts |
Posted - 01 Feb 2008 : 15:05:49
|
The original code we sent you was just an example of how to plot extra lines on a frequency histogram. It contained a bug in that it did not use the standard deviation that was passed in and instead used a local variable that was hard coded. Below you will find a corrected versionof the AddGaussianCurve method.
The amplitude variable in the method is used to scale the gaussian curve to the chart height. We aren't sure exactly how to calculate that value. It is set for your current range of values.
Public Sub AddGaussianCurve(ByVal chart As FrequencyHistogramChart, ByVal mean As Double, ByVal sdev As Double, ByVal curvecolor As Color)
Dim normalx(100) As Double
Dim normaly(100) As Double
Dim normv As Double = 0
Dim xval As Double = 0
Dim amplitude As Double = 0.35
' calculate the x and y-values for the curve
Dim i As Integer
For i = 0 To normalx.Length - 1
'start 5 std dev to the left of the mean and continue for 5 std dev. to right of mean
xval = mean - 5 * sdev + i * (10 * sdev) / 100
normv = amplitude * Math.Exp((-0.5 * Math.Pow((xval - mean) / sdev, 2))) _
* (1.0 / sdev * Math.Sqrt((2.0 * Math.PI)))
normalx(i) = xval
normaly(i) = normv
Next i
Dim normDataset As New SimpleDataset("NormDataset", normalx, normaly)
Dim normAttribute As New ChartAttribute(curvecolor, 3)
Dim normPlot As New SimpleLinePlot(chart.CoordinateSystem, normDataset, normAttribute)
Me.AddChartObject(normPlot)
End Sub 'AddGaussianCurve |
 |
|
Alice
25 Posts |
Posted - 01 Feb 2008 : 15:14:40
|
Thank you so much!! |
 |
|
Alice
25 Posts |
Posted - 04 Feb 2008 : 15:25:36
|
You said "We aren't sure exactly how to calculate that value(amplitude )", so you set it as 0.35 for me. It works for my current data set.But how about if I get another set of data? How did you get 0.35? Any rule? |
 |
|
quinncurtis
1164 Posts |
Posted - 04 Feb 2008 : 15:54:19
|
Sorry, we don't have a rule. Our example is not meant to show you how to draw a bell curve to your data. It meant to show you how to add plot objects to the Histogram chart, using a simple bell curve as an example. It is up to you define the data that you use. If you want us to create a generalized routine that can fit a bell curve to any data that you pass in, contact our special services department with a specification and they will get back to you with a quote.
|
 |
|
|
Topic  |
|
|
|