943,169 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1007
  • Perl RSS
Aug 27th, 2010
0

Plotting Normalized Curve over histogram

Expand Post »
I have a series of data (x,y) as below. I want to use this data to
create a bell curve (normal distribution) with perl. How can I do
this?
x y
1 2
2 50
3 40
4 300
5 70
6 80
7 8
8 10
9 25
10 60
11 350
12 80
13 40
14 5

By normalized curve i mean something like on the link below. Didnt know how to draw a graph here.

Really appreciate any help clues.

http://training.ce.washington.edu/WS...stribution.htm
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Roger101 is offline Offline
9 posts
since Aug 2010
Aug 27th, 2010
1
Re: Plotting Normalized Curve over histogram
Sorry, this question is way over my head. I got as far as plotting your data but it doesn't look like a bell curve... more like twin peaks. In case it helps as an example of a line graph, here's the script:
Perl Syntax (Toggle Plain Text)
  1. #!/usr/bin/perl
  2. #bell_curve_line.pl
  3. use strict;
  4. use warnings;
  5.  
  6. use GD::Graph::lines;
  7. my $perlscriptsdir = '/home/david/Programming/Perl';
  8.  
  9. #For some reason, installing GD::Graph didn't put save.pl in my @INC path
  10. require "/usr/share/doc/libgd-graph-perl/examples/samples/save.pl";
  11. my $chart_file_out = 'bell_line';
  12. print STDERR "Processing $chart_file_out\n";
  13.  
  14. #The @data array is an array of array references
  15. # to an array of x values and an array of y values.
  16.  
  17. my @data = (
  18. [ qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 ) ],
  19. [ qw(2 50 40 300 70 80 8 10 25 60 350 80 40 5 )],);
  20.  
  21. my $my_graph = new GD::Graph::lines();
  22.  
  23. $my_graph->set(
  24. x_label => 'X',
  25. y_label => 'Frequency?',
  26. title => 'Frequency of Various Values of X',
  27. y_max_value => 350,
  28. y_min_value => 2,
  29. y_tick_number => 10,
  30. y_label_skip => 2,
  31. box_axis => 0,
  32. line_width => 3,
  33.  
  34. transparent => 0,
  35. );
  36.  
  37. $my_graph->plot(\@data);
  38. save_chart($my_graph, "$perlscriptsdir/data/$chart_file_out");
Running this creates a file called "bell_line.gif" (see attached).
Attached Thumbnails
Click image for larger version

Name:	bell_line.gif
Views:	542
Size:	3.0 KB
ID:	16947  
Reputation Points: 153
Solved Threads: 140
Master Poster
d5e5 is offline Offline
735 posts
since Sep 2009
Aug 27th, 2010
0
Re: Plotting Normalized Curve over histogram
Hi David,
Thanks for your promt response.

but this a line curve of actual values.
Plot the data in a bars. Then create a curve over the bar chart. So that gives you 2 bell shaped curve. The curve will be through the center of each bar. Does it make sense?

See this link
http://training.ce.washington.edu/WS...stribution.htm

Any help is greatly appreciated.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Roger101 is offline Offline
9 posts
since Aug 2010
Aug 29th, 2010
0
Re: Plotting Normalized Curve over histogram
I'm afraid it doesn't make much sense to me, maybe because I've forgotten the very little I learned about statistics over 35 years ago.

Here's what I don't understand: If you create a bar chart of actual data and draw a line through the centre of the top of each bar, I don't see how that makes two bell curves. Wouldn't you end up with just the line chart of actual data superimposed on a bar chart of the same actual data? I installed GD::Graph only after reading your question so I don't know much about it -- but I don't see any option for creating a curve. One approach might be to input the actual data points into some kind of algorithm that would create a long series of ordered pairs representing a best-fit curve, and then GD::Graph could plot that. But I don't know how to create such an algorithm. Hopefully someone else here on Daniweb acquainted with statistical analysis modules will reply to your question?

I notice that someone asked a question similar to yours at this link and the response to it sheds some light on the problem but doesn't contain the complete solution.
Reputation Points: 153
Solved Threads: 140
Master Poster
d5e5 is offline Offline
735 posts
since Sep 2009
Aug 30th, 2010
0

But the curve is not through the center of each bar at your link.

Click to Expand / Collapse  Quote originally posted by Roger101 ...
Hi David,
Thanks for your promt response.

but this a line curve of actual values.
Plot the data in a bars. Then create a curve over the bar chart. So that gives you 2 bell shaped curve. The curve will be through the center of each bar. Does it make sense?

See this link
http://training.ce.washington.edu/WS...stribution.htm

Any help is greatly appreciated.
I looked at the example in the link you gave and the curve is not drawn through the centre of each bar. It looks like someone used their intuition to draw a bell curve that best fit the actual data represented by the bars. I doubt that GD::Graph can guess which bell curve best fits a small sample of data points. There may be statistical analysis packages that do this.
Attached Thumbnails
Click image for larger version

Name:	bell-curve-over-bars.gif
Views:	539
Size:	8.3 KB
ID:	16984  
Reputation Points: 153
Solved Threads: 140
Master Poster
d5e5 is offline Offline
735 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Plots in Perl - GD::Graph Module
Next Thread in Perl Forum Timeline: Configuration Syncronization





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC