cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
John_Gam
Level I

graph builder - set the intercept of the best fit line

Hi,

 

I am using graph builder for visual representations of my data, combining several variables into one graph with an x-y scatter. I want to add a simple linear line of best fit but force it to go through 0,0 - this seems like a pretty fundamental feature so am I missing something? I have been through every option I can think and tried both methods of creating the line of best fit (line of fit, and smoother with max lambda) but nowhere is the option to adjust intercept of the line!

 

I know I can do it with bivariate fit Y by X, or fit model, but if I've got two variables fields i have to do my analysis by both of these and I'll end up with 4 separate graphs instead of a nice overlayed graph. 

 

Many thanks

 

 

 

2 REPLIES 2
txnelson
Super User

Re: graph builder - set the intercept of the best fit line

I am not aware of an option within Graph Builder to force the intercept through zero.  However, a simple little script can be added to the Graph Builder, that will draw the line.

i1.JPG

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

gb = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ) )
);


/*Simple Linear Regression: y = intercept + beta * x + error*/
report(gb)[framebox(1)]<<add graphics script(
goodRows = dt<<get rows where(excluded(rowstate(row()))==0);
y = dt:height[goodRows];
X = dt:weight[goodRows];
{Estimates, Std_Error, Diagnostics} =
Linear Regression( y, X, nointercept );
List1 = { 0, 0}; 
List2 = {};
insert into(List2, max(x));
insert into(List2, estimates[1]*max(x));
pen color(blue);
line(List1,List2)
);

 

Jim
peter_michel
Level III

Re: graph builder - set the intercept of the best fit line

Hi Tx,

 

That is exactly what I'm looking for. Unfortunately are my scripting skills way far behind yours. Could you make it in easy to use for simple minded Scripters. 

 

e.g  you drop a graph builder in a script window and mark the important Text sequences where to find what and then I drop my graph builder in a Script window and follow the actions you did. Any help is very valued.

 

I can barely live with Fit x to y  and Fit Special. But I  would really appreciate if I could get all the Graph Builder functions.

 

many thanks

Peter