cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

fit y by x question: show equation on chart

stevend1219
Level II

Hi all JMP experts,

 

The equation along with R^2 are shown below in summary and it takes twice copy/paste to copy both the chart & summary to my slide.

So Is it possible to show the fitting equation & R-square on chart? The feature is feasible in Excel.

 

Thanks!

7 REPLIES 7
txnelson
Super User


Re: fit y by x question: show equation on chart

There are a couple of ways to handle this.  With Fit Y by X, a little script can be added that can add the desired stats onto the graph.  Secondly, the Graph Builder has the feature you are looking for as a build in capability.

Jim
stevend1219
Level II


Re: fit y by x question: show equation on chart

Hi Jim, Thanks for the feedback! Could you give me a hint how the script looks like? Usually I start scripting by the template of functionality in GUI -> save to script, but not for this one because I couldn't find it in GUI. Thank you!

txnelson
Super User


Re: fit y by x question: show equation on chart

Here is a simple example. 

txnelson_1-1670294081868.png

 

I developed it interactively by using the  Customize Graph designer dialog box available by right clicking on the graph and selecting "Customize".

txnelson_0-1670293863962.png

Once I developed the code, using the Text Template, I then had JMP generate the complete JSL, see below.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

Bivariate(
	Y( :height ),
	X( :weight ),
	Fit Line( {Line Color( {212, 73, 88} )} ),
	SendToReport(
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Add Graphics Script(
				4,
				Description( "" ),
				Text(
					Center Justified,
					{75, 67},
					"R2 = " || Char( Round( (Current Report()[Number Col Box( 1 )] << get)[1], 5 ) )
				)
			)}
		)
	)
);
Jim
pmroz
Super User


Re: fit y by x question: show equation on chart

Here's an example with Graph Builder:

pmroz_0-1670353546011.png

Note that I left the control panel open so you could see the options to display the line of fit.

Here's the code:

Graph Builder(
	Size( 909, 580 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements(
		Points( X, Y, Legend( 5 ) ),
		Line Of Fit(
			X,
			Y,
			Legend( 7 ),
			Confidence of Prediction( 1 ),
			Root Mean Square Error( 1 ),( 1 ),
			Equation( 1 ),
			F Test( 1 )
		)
	)
);
stevend1219
Level II


Re: fit y by x question: show equation on chart

Hi Jim, Thanks, it works, but encounter another problem: I'd like to use variables in the "{75, 67}," i.e. the position but seems the variables cannot be passed into the function. I need to use variable instead of fixed value because the text position should depend on x/y scale, which differs chart by chart.

 

Something like this: the my_pos_lst seems cannot be successfully fed into the function. Do you have any idea? Thanks!!

 

my_pos_lst = {100, 100};

Bivariate(
	///...
			{Add Graphics Script(
				4,
				Description( "" ),
				Text(
					Center Justified,
					my_pos_lst,
					"R2 = " || Char( Round( (Current Report()[Number Col Box( 1 )] << get)[1], 5 ) )
				)
			)}
		)
	)
);

 

stevend1219
Level II


Re: fit y by x question: show equation on chart

oh BTW, I've used evallist(my_pos_lst) whether outside or inside Bivariate function, but it still doesn't work.

txnelson
Super User


Re: fit y by x question: show equation on chart

It works for me

txnelson_0-1671036794573.png

It just isn't in the default range for the chart, so I had to scroll up to 100 on the Y axis to see it

Jim