cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

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

Help using JSL to extract fit parameters from Fit Curve platform

I am fairly new to the JSL coding and I have been struggling to automate a workflow involving the Fit Curve platform.  Here is what I am trying to automate:

Step 1: Fit Curve Exponential 2P model to data by providing X, Y, and BY data.  Script code below works fine.

Step 2: Collect fit parameters: Scale and Growth Rate (I wish this was just "a" and "b") for each Sample ID and create a new Table that has columns: "Sample ID", "Scale" or "a", "Growth Rate" or "b", "Number of datapoints" (Used in Fit) 

  • this is where I am struggling, I can create a new table with the appropriate headings (see script below). but I cannot figure out how to communicate with the Fit Curve report to extract the values for the fits for each sample ID and then use those to populate one row for each SampleID.  I have tried the JMP assistant and Claude to help code this and they both struggled to extract this info from the report.

Step 3: In this new table add two more columns: "Prediction at TOS =60", and "Uncertainty of Prediction" and use the Exponential 2P formula (y= a*exp(b*x)) for the prediction and use fit error in parameters to estimate the uncertainty of value at TOS = 60.

Thanks for any help,

Dave

 

Fit Curve(
	Y( :Conversion ),
	X( :TOS ),
	Fit Exponential 2P,
	By( :Sample ID )
);
results_dt = New Table( "Exponential Fit Results",
Add Rows( 0 ),
New Column( "Sample ID" ),
New Column( "a", Numeric, Continuous ),
New Column( "b", Numeric, Continuous ),
New Column( "Number of Points", Numeric, Continuous ),
New Column( "Conversion at 60 hr", Numeric, Continuous ),
New Column( "Error of Estimate", Numeric, Continuous )
);

 

4 REPLIES 4
jthi
Super User

Re: Help using JSL to extract fit parameters from Fit Curve platform

Right click on one of the result tables, make into combined data table

jthi_0-1776874647177.png

And from the resulting table, you can take the table script "Make Combined Data Table". This gives quite a good idea what you can do

Names Default To Here(1);
rpt = New Window("Bioassay - Fit Curve of Toxicity by log Conc",
	Data Table("Bioassay") << Fit Curve(
		Y(:Toxicity),
		X(:log Conc),
		Fit Exponential 2P,
		By(:Formulation)
	)
);
Wait(0);
rpt["Fit Curve", "Formulation=standard", "Exponential 2P", "Parameter Estimates",
Table Box(1)] << Make Combined Data Table;
rpt << Close Window;

jthi_1-1776874800669.png

From the table you can then use different table platforms (such as summary, split and update) to create your final table

jthi_2-1776874840757.png

jthi_3-1776874857822.png

 

-Jarmo
DBarton
Level I

Re: Help using JSL to extract fit parameters from Fit Curve platform

Thanks for the reply.   I was considering this route, but assumed there was a way to directly grab the variables out of each of the tables instead of pulling the entire table and then reformatting for my needs.  Much appreciated the clear description as well. 

jthi
Super User

Re: Help using JSL to extract fit parameters from Fit Curve platform

You can do that, but usually it is easier to just convert it into table first and go from there.

-Jarmo
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Help using JSL to extract fit parameters from Fit Curve platform

Here is another approach that uses XPath to search the report structure.  I will not suggest this is easier, but I've found it to be more robust and fail loudly if something unexpected happens, like the third table isn't the third table anymore, rather than just returning the wrong value, especially if you put some checks in and throw errors if unexpected values show up.  I do think this should be easier, so I will shamelessly promote my own wish list item to at least build wrappers for these:Make it easier to get results from reports via JSL 

Names Default To Here( 1 );

// Example fit 
dt = Open( "$SAMPLE_DATA/Nonlinear Examples/Bioassay.jmp" );
curves = dt << Fit Curve(
	Y( :Toxicity ),
	X( :log Conc ),
	Fit Exponential 2P,
	By( :Formulation )
);

// Run this to inspect the report's XML structure — it's the key to
// writing the XPath expressions below. Combine with web searches on
// XPath syntax (//, ancestor::, parent::, text(), etc.) as needed.
curves << Get XML;

// Find the right fit by matching the outline box heading — return the first match
curve = filter each( {c}, curves, length( c << XPath( "/OutlineBox[text()='Formulation=standard']" ) ) > 0 )[1];

// Find columns labeled 'Parameter' inside an outline box called 'Parameter Estimates'
// inside a box called 'Exponential 2P', then find the grandparent TableBox and return
// the first one (there should only be one — you can verify with
//   if( N Items( ... ) > 1, throw( ... ) )
// Single XPath split across lines for readability; the || concatenates the fragments.
paramTableRef = (curve << XPath(
	"//OutlineBox[text()='Exponential 2P']"
	|| "//OutlineBox[text()='Parameter Estimates']"
	|| "//StringColBoxHeader[text()='Parameter']"
	|| "//ancestor::TableBox"
))[1];

// Alternative approach: you could grab the whole table as a list and parse it directly:
paramTableList = paramTableRef << Get;
Show( paramTableList );

// Sticking with XPath for now: find that StringColBoxHeader again, find its parent, and get
// the parameter names (again, assumes there is only one matching column).
paramNames = (paramTableRef << XPath( "//StringColBoxHeader[text()='Parameter']//parent::StringColBox" ))[1] << Get;

// Now get the estimates
paramEstimates = (paramTableRef << XPath( "//NumberColBoxHeader[text()='Estimate']//parent::NumberColBox" ))[1] << Get;

// Put them in an associative array
arrParamEstimates = Associative Array( paramNames, paramEstimates );

// And now you have the values keyed by parameter name
Show( arrParamEstimates["Growth Rate"], arrParamEstimates["Scale"] );

Recommended Articles