cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
learning_JSL
Level IV

need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

My code is not working and I'm having trouble identifying why.  Any help would be most appreciated - thanks!

 

dt = Open("C:\Users\trcampbell\Desktop\MASTER ECOLI\2025\2024.xlsx");

 
obj = Fit model(
Y( :LOGECOLI ),
Effects( :LOGTURB),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(:LOGECOLI )) ;
    
// Extract slope and intercept
reportObj = obj << Report;
paramTable = reportObj( "Parameter Estimates" );
 
// Extract values from Parameter Estimates table
intercept = paramTable[estimate(1)];  //1st column
slope = paramTable[estimate(2)];  //2nd column    
 
// Create a new data table to store the results
results = New Table( "Fit Results",
    Add Column( "Parameter", Character, Set Values( {"Slope", "Intercept"} ) ),
    Add Column( "Value", Numeric, Set Values( {slope, intercept} ) )
);
 
// Save the results to an Excel spreadsheet
results << Export( "C:\\Users\\trcampbell\\Desktop\\MASTER ECOLI\\2025\\validation results\\test xxx.xlsx"); 
 
 
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

Hi @learning_JSL ,

 

I've altered your script to take advantage of the 'make into data table' function to bring the details over, but I've also added where your challenges with the script were by changing the paramtable to target the specific estimates section of the table - if you want to find how to do this it's best to right click>properties and highlight the estimates section to find the path to the object.

 

I've used the sample data folder here just to test that it works.

 

dt=Open("$SAMPLE_DATA/Tablet Production.jmp");
obj = Fit model(
Y( :Dissolution ),
Effects( :Mill Time),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(:Dissolution )) ;
    
// Extract slope and intercept
reportObj = obj << Report;
paramTable = ReportObj["Response Dissolution","Whole Model","Parameter Estimates",TableBox(1)]; //Change the report to target the table that needs saving

/*In the old method you had, you could instead make param table this to target the specific estimate column, just change the Y name:
paramTable = reportObj["Response Dissolution","Whole Model","Parameter Estimates",NumberColBox("Estimate")];*/
// Extract values from Parameter Estimates table
/*intercept = paramTable[1];  //1st column - grab the first item [corrected from what you had]
slope = paramTable[2];  //2nd column - grab the second item*/

dtnew=paramTable<<make into data table;
 

 
// Save the results to an Excel spreadsheet as you have
dtnew << Export( "C:\\Users\\trcampbell\\Desktop\\MASTER ECOLI\\2025\\validation results\\test xxx.xlsx"); 
“All models are wrong, but some are useful”

View solution in original post

Byron_JMP
Staff

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

 

The same code works for me

dt=Open("$SAMPLE_DATA/Tablet Production.jmp");
obj = Fit model(Y( :Dissolution ),Effects( :Mill Time),Personality( "Standard Least Squares" ),Emphasis( "Effect Leverage" ),Run(:Dissolution )) ;

rpt=obj<<report;
rpt["Response Dissolution", "Whole Model", "Parameter Estimates", Table Box( 1 )] << Make Into Data Table;

It could be that you're using an older version of JMP?
maybe try using a different platform

 

Fit y by X

Names Default To Here( 1 );
rpt = New Window( "Tablet Production - Fit Y by X of Dissolution by Mill Time",
	Data Table( "Tablet Production.jmp" ) <<
	Bivariate(Y( :Dissolution ),X( :Mill Time ),
	Fit Line( {Line Color( {230, 159, 0} )} )
	)
);

rpt["Bivariate Fit of Dissolution By Mill Time", "Linear Fit", "Parameter Estimates",
Table Box( 1 )] << Make Into Data Table;

or this one
Fit Curve

Names Default To Here( 1 );
rpt = New Window( "Tablet Production - Fit Curve of Dissolution by Mill Time",
	Data Table( "Tablet Production.jmp" ) <<
	Fit Curve( Y( :Dissolution ), X( :Mill Time ), Fit Linear ));

rpt["Fit Curve", "Linear", "Parameter Estimates", Table Box( 1 )] <<
Make Into Data Table;

 

JMP Systems Engineer, Health and Life Sciences (Pharma)

View solution in original post

6 REPLIES 6

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

Hi @learning_JSL ,

 

I've altered your script to take advantage of the 'make into data table' function to bring the details over, but I've also added where your challenges with the script were by changing the paramtable to target the specific estimates section of the table - if you want to find how to do this it's best to right click>properties and highlight the estimates section to find the path to the object.

 

I've used the sample data folder here just to test that it works.

 

dt=Open("$SAMPLE_DATA/Tablet Production.jmp");
obj = Fit model(
Y( :Dissolution ),
Effects( :Mill Time),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(:Dissolution )) ;
    
// Extract slope and intercept
reportObj = obj << Report;
paramTable = ReportObj["Response Dissolution","Whole Model","Parameter Estimates",TableBox(1)]; //Change the report to target the table that needs saving

/*In the old method you had, you could instead make param table this to target the specific estimate column, just change the Y name:
paramTable = reportObj["Response Dissolution","Whole Model","Parameter Estimates",NumberColBox("Estimate")];*/
// Extract values from Parameter Estimates table
/*intercept = paramTable[1];  //1st column - grab the first item [corrected from what you had]
slope = paramTable[2];  //2nd column - grab the second item*/

dtnew=paramTable<<make into data table;
 

 
// Save the results to an Excel spreadsheet as you have
dtnew << Export( "C:\\Users\\trcampbell\\Desktop\\MASTER ECOLI\\2025\\validation results\\test xxx.xlsx"); 
“All models are wrong, but some are useful”
learning_JSL
Level IV

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

Thanks Ben. 

 

I am getting this error:  

learning_JSL_0-1742919193908.png

 

Byron_JMP
Staff

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

 

The same code works for me

dt=Open("$SAMPLE_DATA/Tablet Production.jmp");
obj = Fit model(Y( :Dissolution ),Effects( :Mill Time),Personality( "Standard Least Squares" ),Emphasis( "Effect Leverage" ),Run(:Dissolution )) ;

rpt=obj<<report;
rpt["Response Dissolution", "Whole Model", "Parameter Estimates", Table Box( 1 )] << Make Into Data Table;

It could be that you're using an older version of JMP?
maybe try using a different platform

 

Fit y by X

Names Default To Here( 1 );
rpt = New Window( "Tablet Production - Fit Y by X of Dissolution by Mill Time",
	Data Table( "Tablet Production.jmp" ) <<
	Bivariate(Y( :Dissolution ),X( :Mill Time ),
	Fit Line( {Line Color( {230, 159, 0} )} )
	)
);

rpt["Bivariate Fit of Dissolution By Mill Time", "Linear Fit", "Parameter Estimates",
Table Box( 1 )] << Make Into Data Table;

or this one
Fit Curve

Names Default To Here( 1 );
rpt = New Window( "Tablet Production - Fit Curve of Dissolution by Mill Time",
	Data Table( "Tablet Production.jmp" ) <<
	Fit Curve( Y( :Dissolution ), X( :Mill Time ), Fit Linear ));

rpt["Fit Curve", "Linear", "Parameter Estimates", Table Box( 1 )] <<
Make Into Data Table;

 

JMP Systems Engineer, Health and Life Sciences (Pharma)
learning_JSL
Level IV

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

Thanks so much!   

jthi
Super User

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

One small change I would consider doing when looking for the reference, is to drop the column name from the first outline box reference ("Dissolution" in this case) as it makes it more robust. You could either ignore that outline box or you could use wildcard "?" in place of the column

Names Default To Here(1);

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

fm = dt << Fit Model(
	Y(:y),
	Effects(:Drug, :x),
	Personality(Standard Least Squares),
	Run Model()
);

rep = Report(fm);

// tb_param_estimates1 = rep["Whole Model", "Parameter Estimates", TableBox(1)];
tb_param_estimates2 = rep["Response ?", "Whole Model", "Parameter Estimates", TableBox(1)];

Usually I also add those outlineboxes there, but its a preference

rep[OutlineBox("Response ?"), OutlineBox("Whole Model"), OutlineBox("Parameter Estimates"), TableBox(1)];
-Jarmo
learning_JSL
Level IV

Re: need to extract slope and intercept from parameter estimates table in a linear least squares model fit and save to a file

Thank you Jarmo!!  Most appreciated!

Recommended Articles