Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Microsoft .Net & .Net Compact Framework
 SPC Control Chart Tools for .Net
 bell curve
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Alice

25 Posts

Posted - 01 Feb 2008 :  14:16:17  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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
Go to Top of Page

Alice

25 Posts

Posted - 01 Feb 2008 :  15:14:40  Show Profile  Reply with Quote
Thank you so much!!
Go to Top of Page

Alice

25 Posts

Posted - 04 Feb 2008 :  15:25:36  Show Profile  Reply with Quote
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?
Go to Top of Page

quinncurtis

1164 Posts

Posted - 04 Feb 2008 :  15:54:19  Show Profile  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-07 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07