cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
akrishna39
Level III

Setting up a formula with a paramter

Hi,

I am trying to set up a formula in a column in a table along with a paramter in the formula. It is easy to do with mouse clicks. But I need to write a script. Below is the command that I have written:

 

Column( Data Table( "field_data" ), "diameter Prediction Formula" ) << Set Formula( Parameter({tuning = 1},eval(Name Expr(f11)) ));

 

My formula is stored in 'f11'. The formula will change, so I can only refer it using a variable and not write the actual formula. When I run this line, the formula gets evaluated correctly, but when I click on the column to check the formula it shows "eval(Name Expr(f11))". Is there any way to put the actual formula here? Please help. Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: Setting up a formula with a paramter

Jim has shown how to use 'Substitute()' to build the formula expression. Note that, to see what the required expression looks like, you can always build the formula column by hand, and send the resulting column a 'getScript' or 'getFormula' message. So you can build on Jim's example to get:

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
f11 = expr(:Height);
dt << New Column( "Column 6" );

Eval(
	Substitute(
			Expr(
				:column 6 << set formula(tuning=2; :weight * __f11__ )
				:column 6 << setFormula( Parameter( {b0 = initialValueTBD}, :weight * (__f11__ * b0) ) ),

			),
			Expr(initialValueTBD), 2,
			Expr( __f11__ ), evalexpr(f11) 
		)
	);

 

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Setting up a formula with a paramter

You need to force the evaluation into the formula, and I have found the easiest way to do that is using Substitute()

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
f11 = ":Height";
dt << New Column( "Column 6" );

Eval(
	Substitute(
			Expr(
				:column 6 << set formula( :weight * __f11__ )
			),
		Expr( __f11__ ), Parse( f11 )
	)
);
Jim
akrishna39
Level III

Re: Setting up a formula with a paramter

Thanks txnelson, I understand your code. But my problem has 1 additional thing. I need to set a parameter in my formula also. Let me explain with the help of the example code that you have provided. You are successfully assigned the formula in column 6. Now after this I also need a script to do the following which can be done through mouse clicks as follows:

1) Right click on column 6. Go to "Formula.."

2) Select "Parameters" from the drop down (near the lower left corner)

3) Click on "New Parameter"

4) Assign a name and value to the parameter

5) Click ok

Please let me know if this can be done. Thanks!!

 

txnelson
Super User

Re: Setting up a formula with a paramter

A parameter just sets a memory variable value into the formula, which can be emulated by just placing that code into the formula.  See my new variabtion on the formula 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
f11 = expr(:Height * tuning);
dt << New Column( "Column 6" );

Eval(
	Substitute(
			Expr(
				:column 6 << set formula(tuning=2; :weight * __f11__ )
			),
		Expr( __f11__ ), evalexpr(f11) 
	)
);
Jim
akrishna39
Level III

Re: Setting up a formula with a paramter

Thanks txnelson. Sorry, I should have told you the next step of my analysis also becuase of which it is important for me to define the parameter in the way that I mentioned earlier.

 

I am performing non-linear regression using the column with the formula (and the paramter). Now, if I define the parameter the way you have defined it in your code, then non-linear regression will not consider "tuning" as a parameter that it has to optimize. It will consider it as a fixed value. So, it will not give me the optimized value of "tuning". On the other hand, if I define "tuning" as a parameter, then non-linear regression will give me the value of the parameter "tuning" which minimizes the sum of squares. 

So, please let me know if there is any way I can define the parameter "tuning" in the same column so that non-linear regression considers it as a parameter which it has to optimize and not a fixed value. Thanks!!

 

Sorry for not being clear earlier.

 

ian_jmp
Staff

Re: Setting up a formula with a paramter

Jim has shown how to use 'Substitute()' to build the formula expression. Note that, to see what the required expression looks like, you can always build the formula column by hand, and send the resulting column a 'getScript' or 'getFormula' message. So you can build on Jim's example to get:

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
f11 = expr(:Height);
dt << New Column( "Column 6" );

Eval(
	Substitute(
			Expr(
				:column 6 << set formula(tuning=2; :weight * __f11__ )
				:column 6 << setFormula( Parameter( {b0 = initialValueTBD}, :weight * (__f11__ * b0) ) ),

			),
			Expr(initialValueTBD), 2,
			Expr( __f11__ ), evalexpr(f11) 
		)
	);

 

akrishna39
Level III

Re: Setting up a formula with a paramter

Thanks a lot Ian!! This works!! :)