turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Setting up a formula with a paramter

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 22, 2017 8:50 PM
(926 views)

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!!

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 23, 2017 4:08 AM
(1761 views)

Solution

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)
)
);
```

6 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 22, 2017 10:20 PM
(918 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 22, 2017 10:30 PM
(916 views)

**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!!**

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 22, 2017 11:01 PM
(904 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 22, 2017 11:20 PM
(902 views)

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 23, 2017 4:08 AM
(1762 views)

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)
)
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Oct 23, 2017 5:46 AM
(876 views)