Subscribe Bookmark RSS Feed

Slope Calculation and Compilation for Multiple Cases with Varying Numbers of Observations

sornasst

Community Trekker

Joined:

Feb 2, 2016

Hi,

I know that the topic of linear slope calculation has been discussed before but I could not find an efficient way to create a tabulated output of Slopes for a set of Cases (i.e. Patients) for which I have varying numbers of obervations as a function of time.

Here is a screen shot of the data (mock; the actual file is attached):

Mock data for SLOPE calculationMock data for SLOPE calculation

Following the advice of previous discussions in this board, I used the Fit Y by X (Change in Measure by Time) using Patient_ID as By variable, and plotting a linear fit with intercept constrains to 0:

Ouput: 5 analyses identical to the one below:

SLOPE_mock_Plot.PNG

 

Where I'm stuck is how to collect the Estimate of the Slope into a new table that would look like:

Patient_IDSlope
AAAm1
BBBm2
CCCm3
DDDm4
EEEm5

 

Any suggestion would be welcome: I'm not attached to the original data format or the analysis method.

 

Thanks 

 

1 ACCEPTED SOLUTION

Accepted Solutions
markbailey

Staff

Joined:

Jun 23, 2011

Solution

You discovered the By role group the data for separate regression analysis. (I hope that you know to press and hold the Ctrl key before clicking the red triangle and selecting the Fit Line command!) Now right-click on the Parameter Estimates table and select Make Combined Data Table.

Learn it once, use it forever!
6 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

This code will do the trick.  The "secret" is to look at the underlying tree structure of the output, converted to a report.

dt = data table("SLOPE_Calculation_mock_data");

bv = dt << Bivariate(
	Y( :Change in Measure ),
	X( :Time ),
	Fit Line( {Line Color( {213, 72, 87} )} ),
	By( :Patient_ID )
);

// Figure out how many patients there are
dtab = dt << Tabulate(
	Show Control Panel( 0 ),
	Add Table( Row Table( Grouping Columns( :Patient_ID ) ) ),
	invisible
);

pdt = dtab << Make Into Data Table;

np = nrows(pdt);
patient_list = pdt:Patient_ID << get values;
dtab << close window;
pdt << new column("Slope", numeric, continuous);

bvrep = bv << report;
//bvrep << show tree structure;	// Used to get underlying structure

for (i = 1, i <= np, i++,
	parameter_estimates = bvrep[i][numbercolbox(7)] << get;
	one_slope = parameter_estimates[2];
	pdt:Slope[i] = one_slope;
);
sornasst

Community Trekker

Joined:

Feb 2, 2016

Hi,

Thanks for your quick reply: it is what I was looking for with the exception that the "retrieval" of the parameter_estimate from the multi plot report does not work because the NumberColBox (7) only works for the first plot, the following plots have their corresponding NumberColBox 23, 37 and so on.

I'm not sure how to iterate through the NumberColBox call.

Any thoughts?

Thanks

 

TS

markbailey

Staff

Joined:

Jun 23, 2011

A script could extract the estimates, too, using several different techniques. The common iteration approach becomes cumbersome due to the By groups but can be straight-forward, if only brute force. A more elegant solution would use a single XPath query on the report display tree to retrieve all of thee slopes as a vector. I don't have time right now to research the exact syntax but it would be easy, details aside. Something like this:

plat << XPath( "//NumberColBox[NumberColBoxHeader=\!"Estimate\!"]" ) << Get( 2 );
Learn it once, use it forever!
pmroz

Super User

Joined:

Jun 23, 2011

Check the tree structure and JMP version.  My code works in JMP 11.2.1, 12.2.0 and 13.1.0.  Sometimes there are differences in the underlying structures when going from one version to another.  If you see a regular pattern in the number col boxes (e.g. 7, 22, 37, 52, 67) you can build that into the loop.

 

markbailey

Staff

Joined:

Jun 23, 2011

Solution

You discovered the By role group the data for separate regression analysis. (I hope that you know to press and hold the Ctrl key before clicking the red triangle and selecting the Fit Line command!) Now right-click on the Parameter Estimates table and select Make Combined Data Table.

Learn it once, use it forever!
sornasst

Community Trekker

Joined:

Feb 2, 2016

Thanks: I always forget about this very neat feature