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

- JMP User Community
- :
- Discussions
- :
- Script to run complicated formula on new columns

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Mar 17, 2020 10:02 AM
(671 views)

Trying to figure out how to script a complicated formula from curve fitting using the predictive formula. Its straight forward if all the data is lumped together and there is only one formula however if I break up the data into smaller sets I get stuck with scripting. I can do it interactively but I have many different data tables so doing in manually will get very tedious. (Thanks in advance)

I have used JMP example data Big Class as an example

```
dt = Current Data Table(); //Big Class active
biv = Bivariate(
Y( :height ),
X( :weight ),
by( :sex, :age ),
Fit Special( xTran( "Log" ), {Line Color( {212, 73, 88} )}, save predicteds )
);
biv << (curve[1] << save predicteds);
Column( N Cols( dt ) ) << set name( "Predicted Values" );
dt << NewColumn("Weight_150", set each value(150));
dt << NewColumn("Weight_180", set each value(180));
// Stuck here want to use the "Predicted Values" formula on the new weights columns added
// basically need a script to copy over formula from "Predicted Values" which is now very complicated
// and replace "weight" with "weight_150" and "weight_180" in the formula, creating two new columns
```

// extrapolated values at 150 and 180

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

If I understand correctly, here's one way. This approach doesn't care how complicated the formula is.

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp"); //Big Class active
biv = dt << Bivariate(
Y( :height ),
X( :weight ),
by( :sex, :age ),
Fit Special( xTran( "Log" ), {Line Color( {212, 73, 88} )}, save predicteds )
);
biv << (curve[1] << save predicteds);
Column(dt, N Cols( dt ) ) << set name( "Predicted Values" );
dt << NewColumn("Weight_150", set each value(150));
dt << NewColumn("Weight_180", set each value(180));
myFormula = Column(dt, "Predicted Values") << getFormula;
// Stuck here want to use the "Predicted Values" formula on the new weights columns added
// basically need a script to copy over formula from "Predicted Values" which is now very complicated
// and replace "weight" with "weight_150" and "weight_180" in the formula, creating two new columns
// extrapolated values at 150 and 180
myFormula150 = Substitute(NameExpr(myFormula), Expr(:weight), Expr(:weight_150));
dt << NewColumn( "Predicted Values 150" );
addFormula = Expr(Column(dt, "Predicted Values 150") << setFormula(formulaTBD));
SubstituteInto(addFormula, Expr(formulaTBD), NameExpr(myFormula150));
addFormula;
myFormula180 = Substitute(NameExpr(myFormula), Expr(:weight), Expr(:weight_180));
dt << NewColumn( "Predicted Values 180" );
addFormula = Expr(Column(dt, "Predicted Values 180") << setFormula(formulaTBD));
SubstituteInto(addFormula, Expr(formulaTBD), NameExpr(myFormula180));
addFormula;
dt << runFormulas;
```

1 REPLY 1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

If I understand correctly, here's one way. This approach doesn't care how complicated the formula is.

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp"); //Big Class active
biv = dt << Bivariate(
Y( :height ),
X( :weight ),
by( :sex, :age ),
Fit Special( xTran( "Log" ), {Line Color( {212, 73, 88} )}, save predicteds )
);
biv << (curve[1] << save predicteds);
Column(dt, N Cols( dt ) ) << set name( "Predicted Values" );
dt << NewColumn("Weight_150", set each value(150));
dt << NewColumn("Weight_180", set each value(180));
myFormula = Column(dt, "Predicted Values") << getFormula;
// Stuck here want to use the "Predicted Values" formula on the new weights columns added
// basically need a script to copy over formula from "Predicted Values" which is now very complicated
// and replace "weight" with "weight_150" and "weight_180" in the formula, creating two new columns
// extrapolated values at 150 and 180
myFormula150 = Substitute(NameExpr(myFormula), Expr(:weight), Expr(:weight_150));
dt << NewColumn( "Predicted Values 150" );
addFormula = Expr(Column(dt, "Predicted Values 150") << setFormula(formulaTBD));
SubstituteInto(addFormula, Expr(formulaTBD), NameExpr(myFormula150));
addFormula;
myFormula180 = Substitute(NameExpr(myFormula), Expr(:weight), Expr(:weight_180));
dt << NewColumn( "Predicted Values 180" );
addFormula = Expr(Column(dt, "Predicted Values 180") << setFormula(formulaTBD));
SubstituteInto(addFormula, Expr(formulaTBD), NameExpr(myFormula180));
addFormula;
dt << runFormulas;
```

Article Labels

There are no labels assigned to this post.