Subscribe Bookmark RSS Feed

How to plot individual peak fit curves on histogram (fitted 2 normal mixture)

dbosch

New Contributor

Joined:

Oct 18, 2017

Hello,

 

I have a data set which contains multiple peaks, which I am able to fit nicely using the histogram plot's Fitted Normal 2 Mixture option.  This outputs the mean and sigma for each peak as well as the weights as numeric values and overlays the fit curve over the histogram.  Is there a way to visualize the individual peak fits overlaid on the histogram as well?

 

Thanks!

Denny

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

There are a couple of ways to do this.  Both require the adding of JSL to your code.  Method 1, is to Right Click on the graph, and select "Customize...".  This will allow you to modify the graph, or to add to it.  If you Click on the "+" it will allow you to add a script, and one of the Samples allows for the creation of a normal curve.  With some knowlege of plotting using the Y Function and the Normal Density function, you could add in such a curve.

Below is an example of adding JSL to a script to generate 2 normal curves on top of the sample data.  The Add Graphics Script() function does the work.  I took a couple of shortcuts by hard coding in the 2 different means and standard deviations and also, the scale factors based upon the total number of data points divided by the data points for the maximum bar in the histogram distribution.  These data values would have to be calculated within any given script, based upon what exactly you are proposing.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

Dis = dt << Distribution(
	Continuous Distribution( Column( :height ), Vertical( 0 ), Density Axis( 1 ) )
);

Report( Dis )[Frame Box( 2 )] << Add Graphics Script(
	mu = 63;
	sigma = 3.2;
	Pen Color( "Red" );
	Y Function( Normal Density( (x - mu) / sigma ) / (40 / 12), x );

	mu = 51.5;
	sigma = .87;
	Pen Color( "Blue" );
	Y Function( Normal Density( (x - mu) / sigma ) / (40 / 2), x );
);

customize.PNG

 

The code that is within the Add Graphics Script() function is the same code that you would add to the script if you choose the Customize... option

Jim
4 REPLIES
ih

Community Trekker

Joined:

Sep 30, 2016

This distribution platform can show the curve fit:

 

Dist.PNG

 

dt = New Table( "Two Peaks",
	Add Rows( 500 ),
	New Column( "Column 1",
		Numeric, "Continuous", Format( "Best", 12 ),
		Formula(
			If( Random Uniform() > 0.3,
				Random Normal( 5 ),
				Random Normal( 10 )
			)
		)
	)
);

dist =Distribution(
	Continuous Distribution(
		Column( :Column 1 ),
		Fit Distribution( Normal Mixtures( Clusters( 2 ) ) )
	)
);
dbosch

New Contributor

Joined:

Oct 18, 2017

Hi ih,

 

I did see the option to display the overall curve fit but not the individual peaks.  Here is what I want to output (excuse my crude drawing):

 

Untitled.png

 

Thanks!

txnelson

Super User

Joined:

Jun 22, 2012

Solution

There are a couple of ways to do this.  Both require the adding of JSL to your code.  Method 1, is to Right Click on the graph, and select "Customize...".  This will allow you to modify the graph, or to add to it.  If you Click on the "+" it will allow you to add a script, and one of the Samples allows for the creation of a normal curve.  With some knowlege of plotting using the Y Function and the Normal Density function, you could add in such a curve.

Below is an example of adding JSL to a script to generate 2 normal curves on top of the sample data.  The Add Graphics Script() function does the work.  I took a couple of shortcuts by hard coding in the 2 different means and standard deviations and also, the scale factors based upon the total number of data points divided by the data points for the maximum bar in the histogram distribution.  These data values would have to be calculated within any given script, based upon what exactly you are proposing.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

Dis = dt << Distribution(
	Continuous Distribution( Column( :height ), Vertical( 0 ), Density Axis( 1 ) )
);

Report( Dis )[Frame Box( 2 )] << Add Graphics Script(
	mu = 63;
	sigma = 3.2;
	Pen Color( "Red" );
	Y Function( Normal Density( (x - mu) / sigma ) / (40 / 12), x );

	mu = 51.5;
	sigma = .87;
	Pen Color( "Blue" );
	Y Function( Normal Density( (x - mu) / sigma ) / (40 / 2), x );
);

customize.PNG

 

The code that is within the Add Graphics Script() function is the same code that you would add to the script if you choose the Customize... option

Jim
dbosch

New Contributor

Joined:

Oct 18, 2017

Exactly what I was looking for. Thanks!