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
- :
- Discussions
- :
- Computing Slope And Intercept in JSL

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
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 22, 2014 11:17 PM
(4027 views)

I have a data table where the data points (both y's and x's) for slope calculation are in non-contiguous columns and I need to compute slope and intercept data for each row. Is there a way to do this in JMP? Tried to do it in excel but Slope function doesn't work, due to y's and x's being in non-contiguous columns.

To illustrate the problem, in the sample data table attached, I need the slope of (height1, height2, ...) against (weight1, weight2, ...) computed for every row. I intend to build a column with slope data

I would appreciate any ideas or suggestions.

Thanks!

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 10:37 AM
(6501 views)

Matrix formulas could solve it very efficiently. But if we stick with the *Fit Y by X* platform the columns must be stacked before analysis. For your example table, this code stacks the columns, fits the lines and then transfer all slopes and intercept to a new table (which can be joined with the original data table if desired):

//Stack with multiple series option

dt_stacked = Data Table**(** "Example-2.jmp" **)** << **Stack****(**

columns**(** :height, :weight, :height1, :weight1, :height2, :weight2 **)**,

Source Label Column**(** "Label" **)**,

Stacked Data Column**(** "Data" **)**,

Number of Series**(** **2** **)**

**)**;

//Fit all slopes

biv = dt_stacked << **Bivariate****(** Y**(** :Data 2 **)**, X**(** :Data **)**, Group by**(** :Temp1 2 **)**, Fit line**(** **1** **)** **)**;

//Make into data table

slopetable = Report**(** biv **)[**Outline Box**(** "Parameter Estimates" **)][****1****]** << **make combined data table**;

// Split table to get slope and intercept on the same row

slopetable << **Split****(**

Split By**(** :Term **)**,

Split**(** :Estimate **)**,

Group**(** :X, :Y, :Temp1 2 **)**,

Remaining Columns**(** Drop All **)**

**)**;

7 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 8:04 AM
(3497 views)

// one way...

dt = Open("$Sample_Data/Big Class.jmp");

dt << Graph Builder(

Show Control Panel(0),

Variables( x( :weight ), Y( :height ),

Elements(

Points( X, Y, Legend( 1 ), Jitter( 1 ),

Line of Fit(

X,

Y,

Legend( 5 ),

Confidence of Fit( 1 ),

Confidence of Prediction( 0 ),

Degree( "linear" ),

Equation( 1 ),

Root Mean Square Error( 0 )

)

)

);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 9:41 AM
(3497 views)

Matt, thanks for the reply, but that's not what I wanted.

Attached is an example data table to illustrate. I need the slope of (height1, height2) against (weight1, weight2) computed for every row. I intend to build a column of slope data.

Thanks,

Ravi

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 10:01 AM
(3497 views)

If there only are two points involved the slope can be calculated for each row by the formula (:height2 - :height1) / (:weight2 - :weight1).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 10:03 AM
(3497 views)

Hi MS,

I have more than 2 points involved.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 10:37 AM
(6502 views)

Matrix formulas could solve it very efficiently. But if we stick with the *Fit Y by X* platform the columns must be stacked before analysis. For your example table, this code stacks the columns, fits the lines and then transfer all slopes and intercept to a new table (which can be joined with the original data table if desired):

//Stack with multiple series option

dt_stacked = Data Table**(** "Example-2.jmp" **)** << **Stack****(**

columns**(** :height, :weight, :height1, :weight1, :height2, :weight2 **)**,

Source Label Column**(** "Label" **)**,

Stacked Data Column**(** "Data" **)**,

Number of Series**(** **2** **)**

**)**;

//Fit all slopes

biv = dt_stacked << **Bivariate****(** Y**(** :Data 2 **)**, X**(** :Data **)**, Group by**(** :Temp1 2 **)**, Fit line**(** **1** **)** **)**;

//Make into data table

slopetable = Report**(** biv **)[**Outline Box**(** "Parameter Estimates" **)][****1****]** << **make combined data table**;

// Split table to get slope and intercept on the same row

slopetable << **Split****(**

Split By**(** :Term **)**,

Split**(** :Estimate **)**,

Group**(** :X, :Y, :Temp1 2 **)**,

Remaining Columns**(** Drop All **)**

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 2:32 PM
(3497 views)

MS,

Thanks for the help!

I have a follow up question. Is there an easy way to combine RSquare (only) from 'Summary of Fit' along with slope and intercept. I tried below command, but looks like once it goes one layer down the outline, it can't go back up a level to the outline nodes.

slopetable = Report( biv )[Outline Box( "Parameter Estimates" )][1][Outline Box( "Summary of Fit" )][1] << make combined data table;

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jan 23, 2014 3:15 PM
(3497 views)

That's right, you're digging deeper inside the Parameter Estimates and won't find the RSquare down there. The Summary of Fit sits on the same level in tree, so use a separate call instead of go down and back up again.

I do not think it is possible to get parameters and summary of fit in the same table with one command. Make two tables and then there are several ways to bring the data together.

Try this:

//Stack with multiple series option

dt_stacked = Data Table**(** "Example-2.jmp" **)** << **Stack****(**

columns**(** :height, :weight, :height1, :weight1, :height2, :weight2 **)**,

Source Label Column**(** "Label" **)**,

Stacked Data Column**(** "Data" **)**,

Number of Series**(** **2** **)**

**)**;

//Fit all slopes

biv = dt_stacked << **Bivariate****(** Y**(** :Data 2 **)**, X**(** :Data **)**, Group by**(** :Temp1 2 **)**, Fit line**(** **1** **)** **)**;

//Make into data tables

slopetable = Report**(** biv **)[**Outline Box**(** "Parameter Estimates" **)][****1****]** << **make combined data table**;

R2table = Report**(** biv **)[**Outline Box**(** "Summary of Fit" **)][****1****]** << **make combined data table**;

// Split table to get slope and intercept on the same row, then add a column with R2-values

results = slopetable << **Split****(**

Split By**(** :Term **)**,

Split**(** :Estimate **)**,

Group**(** :X, :Y, :Temp1 2 **)**,

Remaining Columns**(** Drop All **)**

**)**;

results << **New Column****(** "R2",

numeric,

set values**(**

Column**(** R2table, "Column 2" **)[**R2table << **get rows where****(**

Column**(** R2table, "Column 1" **)[]** == "RSquare"

**)]**

**)**

**)**;

// Close intermediate windows

Close**(** dt_stacked, slopetable, R2table, no save **)**;