Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
avatar4293
Level I

Script to run complicated formula on new columns

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
ian_jmp
Staff

Re: Script to run complicated formula on new columns

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;

View solution in original post

1 REPLY 1
Highlighted
ian_jmp
Staff

Re: Script to run complicated formula on new columns

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;

View solution in original post

Article Labels

    There are no labels assigned to this post.