cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
joshua
Level III

How to group by and get slopes in a JSL fit model script

Hi, 

I'm trying to fit data in group and get slope and R squared number. I'm using Fishing data set as an example here.

I stacked the data so that the summary will be outputted easily as one single column then I need to spread the columns again.

 

So I did 

fishing_stacked = dt << Stack(
	columns(
		:Fish Caught,
		:Live Bait,
		:Fishing Poles,
		:Camper,
		:People,
		:Children,
		:Fished
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);

 

joshua_0-1583767793311.png

 

I want to group the data by Validation column and fit (Y axis = Fish cought )and X axis are "Live Bait, Fishing Poles, Camper ...." and get the slope value and R squared number as new columns.

Here is the previous post but I don't know how to apply it to my data set.


https://community.jmp.com/t5/Discussions/Save-Parameter-Estimates-of-Linear-Regression-with-by-Varia...

13 REPLIES 13
joshua
Level III

Re: How to group by and get slopes in a JSL fit model script

 
joshua
Level III

Re: How to group by and get slopes in a JSL fit model script

If I want to loop over the columns ( I have many columns in real data) and not to include the those contains certain string how to loop through them ?

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Fishing.jmp");


colList = dt << get column names( string );

For( i = 1, i <= N Items( colList ), i++,
If( ! Contains( colList[i], "Validation") & ! Contains( colList[i], "People") ,

biv = Bivariate(invisible,
Y( :Fish Caught ),
X( :i),
Fit Line( {Line Color( "Medium Dark Red" )} ),
By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]<< make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]<< make combined data table (invisible);
dtR2 << select where(:Column 1 != "RSquare");
dtR2 << delete rows;
dtR2:Column 2 << set name("RSquare");
dtR2 << delete Columns({"Validation 2","Column 1"});
txnelson
Super User

Re: How to group by and get slopes in a JSL fit model script

I would approach this differently.  By placing all of the output into a single window, the 

     << Make Combined Data Table 

will work as desired.  Working across separate windows will be an issue.

I choose to modify the list of x columns one wants to use, and then apply it to only one Bivariate execution

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Fishing.jmp" );


colList = dt << get column names( string );

For( i = N Items( colList ), I >= 1, i--,
	If( Contains( colList[i], "Validation" ) | Contains( colList[i], "People" ),
		Remove From( colList, i, 1 )
	)
);

biv = Bivariate(invisible,
Y( :Fish Caught ),
X( eval(colList) ),
Fit Line( {Line Color( "Medium Dark Red" )} ),
By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]<< make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]<< make combined data table (invisible);
dtR2 << select where(:Column 1 != "RSquare");
dtR2 << delete rows;
dtR2:Column 2 << set name("RSquare");
dtR2 << delete Columns({"Validation 2","Column 1"});

There is also a Platform that you may want to explore, that directly produces the report you want.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Fishing.jmp" );


colList = dt << get column names( string );

For( i = N Items( colList ), I >= 1, i--,
	If( Contains( colList[i], "Validation" ) | Contains( colList[i], "People" ) |
		Contains( colList[i], "Fish Caught" ),
		Remove From( colList, i, 1 )
	)
);

Response Screening(
	Y( :Fish Caught ),
	X( eval(colList) ),
	Where( Format( :Validation ) == "Training" )
);

 

 

Jim
joshua
Level III

Re: How to group by and get slopes in a JSL fit model script

thanks Jim, you are a great help !