cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
ivomdb
Level III

How to Save prediction formula for different categories when running Nonlinear model fitting

I have a script that fits a custom formula for a Nonlinear model (not available on Nonlib) that gets the estimates for the model parameters. I can Save the formula under the red triangule menu and select save prediction formula which will create a new column for the new results. I can do this for every category.

 

New Column( "Fitted Model By Sample",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Set Property( "By ID", 207957763 ),
	Formula(
		If( :Sample == "Barley 2710",
			If( :Days > 0,
				0.171070850115799 * Exp( -Exp( ((0.00826868962267886 * Exp()) / 0.171070850115799) * (8.5626914275992 - :Days) ) )
				+0.189197655815188 * Exp( -Exp( ((0.0822175769423173 * Exp()) / 0.189197655815188) * (1.00952608535815 - :Days) ) ),
				0
			),
			.
		)
	),
	Set Property( "Predicting", {:Average, Creator( "Nonlinear" )} ),
	Set Selected
);
Set Label Columns( :Label );

 

However, I am trying to get it to run for all the categories in the data table to avoid having to do it manually. Any suggestion on how to do this?

 

I have tried to just publish the new formula but no column is created as when doing it manually such as:

 

obj = Nonlinear( Y( :Average ), X( :Model ), Loss( :Err ), Iteration Limit( 5000 ), By( :Sample ) );
obj << go;
obj << Publish prediction formula;
obj << Set name( "Fitted Model by sample" );

 

I have also tried modifying the JSL recorded script as below, unfortunately the formula does not work. Any help is much appreciated.

 

obj = Nonlinear( Y( :Average ), X( :Model ), Loss( :Err ), Iteration Limit( 5000 ), By( :Sample ) );
obj << go;
//returns a list of vectors where each vector, contains the parameters estimates
obj << get estimates;
obj << get prediction formula;
col11 = New Column( "Fitted Model By Sample",
	set formula(
		If( :Days > 0,
			(Y1_Y1_0 * Exp( -Exp( ((K1_K1_0 * Exp()) / Y1_Y1_0) * (P1_P1_0 - :Days) ) ) + Y2_Y2_0 * Exp(
				-Exp( ((K2_K2_0 * Exp()) / Y2_Y2_0) * (P2_P2_0 - :Days) )
			)),
			0
		),
		By( :Sample ),
		Set Property( "Predicting", {:Average, Creator( "Nonlinear" )} ),
		Set Selected
	),
	Set Label Columns( :Label )
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
Phil_Kay
Staff

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Does the solution from @txnelson in this post help? ("Saving prediction formula back to table")

 

Names Default To Here( 1 );
dt = Open(
	"$SAMPLE_DATA/Nonlinear Examples/Bioassay.jmp"
);
obj = Fit Curve(
	Y( :Toxicity ),
	X( :log Conc ),
	Group( :formulation ),
	Fit Logistic 4P
);
obj << (Fit[1] << Save Prediction Formula);

This uses the Save Prediction Formula command, rather than Publish prediction formula. I think this is what you want to do and it does not require Pro.

 

It gives you a result prediction formula column with, effectively, a model for each Group:

 

Match( :Formulation,
	"standard",
		0.599015186864584 + (1.10686367677145 - 0.599015186864584) / (1
		+Exp( -5.84379312234502 * (:log Conc - 0.32019959502239) )),
	"test A",
		0.590902329849433 + (1.1012080930316 - 0.590902329849433) / (1
		+Exp( -5.98069280093278 * (:log Conc - 0.284551221955609) )),
	"test B",
		0.592984828033858 + (1.0972015134296 - 0.592984828033858) / (1
		+Exp( -5.75586785289505 * (:log Conc - 0.084429442746212) )),
	"test C",
		0.593403681513877 + (1.10597929999838 - 0.593403681513877) / (1
		+Exp( -6.00992746207644 * (:log Conc - 0.298749145989595) )),
	.
)

View solution in original post

6 REPLIES 6
Phil_Kay
Staff

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Hi,

 

Just a few of tips to help people to help you with your challenges.

 

First of all, it would help if you can use the JSL option when you post scripting questions. You just need to click on <JSL> on tool bar above the posting window and add your JSL there. Much clearer for people to understand your JSL and help you.

 

Second, there is a complex nonlinear model fitting here but your question is really about how you automate fitting a model and generating the prediction formula column for each group. It will be easier for people to help if you supply a simpler example that demonstrates the particular part of the problem that you are trying to address. It will also make it more accessible for other community members to understand if this gives them a solution to their problem. An example using the classic Big Class sample data set is always good. In your case I think fitting a simple model for each group of Sex in Big Class might be enough to demonstrate your challenge. Or maybe it is more complex than that. I'm not sure because the information that you have provided is a little unclear.

 

Finally, it might help if you can explain a little about what you are ultimately trying to achieve. Why do you want to create formuale columns for each group? There might be other, better ways to achieve your objective.

 

I think if you follow these steps you should find you will get more help with the qeuries that you post.

 

Regards,

Phil

ivomdb
Level III

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Hi Phil,

 

Thanks again for the feedback. 

I will try to explain a little bit more on this reply.

 

Yes my quaestion is about how I automate fitting a model and generate a column with the resultant prediction formula for each group. It is only one column I want to create. The Model formula is already in one column for each group and I just want to replicate that with the new parameters that were estimated.

 

The idea of doing this is just so I can report the results for each group indicidually as well as being able to represent graphically the model curve and experimental data differently via graph builder.

 

I hope this is more clear.

 

Nevertheless, it seems I would need Jump Pro to be able to do this is that rigth?

 

Thanks

Ivo

 

 

Phil_Kay
Staff

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Publish prediction formula relates to the capability to publish to the Formula Depot in JMP Pro. I don't expect this to work if you are using standard JMP. You could check by using the example script form the Scripting Index.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );
obj = K Nearest Neighbors(
	Y( :mvalue ),
	X(
		:crim,
		:zn,
		:indus,
		:chas,
		:nox,
		:rooms,
		:age,
		:distance,
		:radial,
		:tax,
		:pt,
		:b,
		:lstat
	),
	K( 10 )
);
obj << (Response[1] << Publish Prediction Formula);

(BTW, this is what I was saying about the insert JSL option - much clearer, isn't it?)

 

Does that work? It should bring up the Formula Depot. Again, I only expect it to work if you are using JMP Pro.

ivomdb
Level III

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Thanks for the feedback Phil.

 

I have tried the script and you are right it does not work as I only have the standard JMP...sadly. 

 

 

Phil_Kay
Staff

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Does the solution from @txnelson in this post help? ("Saving prediction formula back to table")

 

Names Default To Here( 1 );
dt = Open(
	"$SAMPLE_DATA/Nonlinear Examples/Bioassay.jmp"
);
obj = Fit Curve(
	Y( :Toxicity ),
	X( :log Conc ),
	Group( :formulation ),
	Fit Logistic 4P
);
obj << (Fit[1] << Save Prediction Formula);

This uses the Save Prediction Formula command, rather than Publish prediction formula. I think this is what you want to do and it does not require Pro.

 

It gives you a result prediction formula column with, effectively, a model for each Group:

 

Match( :Formulation,
	"standard",
		0.599015186864584 + (1.10686367677145 - 0.599015186864584) / (1
		+Exp( -5.84379312234502 * (:log Conc - 0.32019959502239) )),
	"test A",
		0.590902329849433 + (1.1012080930316 - 0.590902329849433) / (1
		+Exp( -5.98069280093278 * (:log Conc - 0.284551221955609) )),
	"test B",
		0.592984828033858 + (1.0972015134296 - 0.592984828033858) / (1
		+Exp( -5.75586785289505 * (:log Conc - 0.084429442746212) )),
	"test C",
		0.593403681513877 + (1.10597929999838 - 0.593403681513877) / (1
		+Exp( -6.00992746207644 * (:log Conc - 0.298749145989595) )),
	.
)
ivomdb
Level III

Re: How to Save prediction formula for different categories when running Nonlinear model fitting

Awesome! I can believe I missed this solution in the community. I have searched all sort of examples. Only needed "Save" thats all I needed.

Thanks so much Phil!