turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to plot individual peak fit curves on histogra...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 18, 2017 12:49 PM
(691 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 19, 2017 10:10 AM
(1280 views)

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 );
);
```

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 18, 2017 6:29 PM
(673 views)

This distribution platform can show the curve fit:

```
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 ) ) )
)
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 19, 2017 5:42 AM
(655 views)

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):

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 19, 2017 10:10 AM
(1281 views)

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 );
);
```

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 19, 2017 11:01 AM
(636 views)