cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

Slope and Intercept calculations in JSL

@Jeff_Perkinson , @Milo , 
        This is in reference to a discussion - Slope and intercept functions
        I have found this discussion to be helpful. I am currently using JMP 13, so if there are developments made in JMP 14, I dont necessarily have access to it. 

        But, here are my questions: 

Clear Log() ; Clear Globals(); Close All(DataTables,"No Save");  

Slope = function({x,y},{default local},
				If( !(Is Matrix( x ) & Is Matrix( y ) & N Col( x ) == 1 & N Col( y ) == 1),
					Show( "x or y arguments are not matrices or they have more than one column" );
					Throw();
					,
					x = J( N Row( x ), 1 ) || x; // put in an intercept column of 1s 
					beta = Inv( X` * X ) * X` * Y; // the least square estimates 
					beta[2];
				  );
				); 
				
Intercept = function({x,y},{default local},
					 If( !(Is Matrix( x ) & Is Matrix( y ) & N Col( x ) == 1 & N Col( y ) == 1),
						Show( "x or y arguments are not matrices or they have more than one column" );
						Throw();
						,
						x = J( N Row( x ), 1 ) || x; // put in an intercept column of 1s 
						beta = Inv( X` * X ) * X` * Y; // the least square estimates 
						beta[1];
					   );
					); // end of intercept function 

x1 = 0.05417099; 
x2 = 0.057730865; 
y1 = 30.5885; 
y2 = 31.5885; 

dt = New Table(); 
dt << New Column("X",Numeric,Continuous,<< Set Values({x1,x2}))
   << New Column("Y",Numeric,Continuous,<< Set Values({y1,y2}));
   
dt << New Script("Biv",Bivariate( Y( :Y ), X( :X ), Fit Line( {Line Color( {213, 72, 87} )} ) ));
 
SlopeTest = Slope(Matrix({y1,y2}),Matrix({x1,x2})); 
Show(SlopeTest);
InterceptTest = Intercept(Matrix({y1,y2}),Matrix({x1,x2})); 
Show(InterceptTest);

    1. Why do the slope and intercept not match for the test case that I have taken w.r.t bivariate ? 

    2. If the function or its implementation have a bug, would you be kind enough to offer an alternative ? 

Best
Uday
2 ACCEPTED SOLUTIONS

Accepted Solutions
cwillden
Super User (Alumni)

Re: Slope and Intercept calculations in JSL

Hey @uday_guntupalli,

You still got the arguments reversed.  See the screenshot:slope_int.PNG

 

 

 

-- Cameron Willden

View solution in original post

vince_faller
Super User (Alumni)

Re: Slope and Intercept calculations in JSL

The order of your inputs are backwards.  On the function it goes slope(x, y) and when you call you're doing slope(y, x)

Vince Faller - Predictum

View solution in original post

4 REPLIES 4
cwillden
Super User (Alumni)

Re: Slope and Intercept calculations in JSL

You got the arguments backward for the Slope and Intercept function.  Just reverse the order of the matrices.

-- Cameron Willden
uday_guntupalli
Level VIII

Re: Slope and Intercept calculations in JSL

@cwillden, 
       While that was a good catch, that did not change the results and the function doesn't match up to bivariateimage.png

Best
Uday
cwillden
Super User (Alumni)

Re: Slope and Intercept calculations in JSL

Hey @uday_guntupalli,

You still got the arguments reversed.  See the screenshot:slope_int.PNG

 

 

 

-- Cameron Willden
vince_faller
Super User (Alumni)

Re: Slope and Intercept calculations in JSL

The order of your inputs are backwards.  On the function it goes slope(x, y) and when you call you're doing slope(y, x)

Vince Faller - Predictum

Recommended Articles