cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
pauldeen
Level VI

How to get the half evaluated form of a prediction equation

I am using fit model to built a regression equation for time and a bunch of extra factors. The end goal is to create a table in a journal that has the prediction equation evaluated for all the extra factors and show the pure intercept + slope * time based equation. Example:

dt = Open("$SAMPLE_DATA\Powder Metallurgy.jmp");
fm = dt << Fit Model(
	Y( :Shrinkage ),
	Effects(
		:Formation Method, :Compaction Method, :Sintering Time
	),
	Personality( "Standard Least Squares" ),
	Emphasis( "Effect Leverage" ),
	Run()
);
PredForm = Arg(Arg((FM << GetPredictionFormula), 3),1);

This results in equation:

0.942161598883733 + Match( :Formation Method,
	"Die", 0.0407171588498178,
	"Extrusion", 0.0256123252434345,
	"Isostatic", -0.0663294840932524,
	.
) + Match( :Compaction Method,
	"Cold", 0.594574663098895,
	"Warm", -0.594574663098895,
	.
) + -0.0742413463542265 * :Sintering Time

We can then create a table with the extra factors:

dtEquations = dt << Summary(
	Group( :Formation Method, :Compaction Method ),
	Freq( "None" ),
	Weight( "None" )
);
dtEquations << DeleteColumns(:N Rows);

And so how do I write the equation into a new column where it looks at the (in this example) first 2 columns and evaluates the Match statements, with simplicfication, but leaves the equation for time? End goal:

pauldeen_0-1691659449029.png

Even better if all the static coefficients are reduced to one.

 

The whole thing needs to be dynamic for multiple extra factor levels, and the equation could common slope, common intercept or it could be different slopes and or different intercepts.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to get the half evaluated form of a prediction equation

This will most likely require quite a lot of modification, but one option would be to use Extract Expr

Names Default To Here(1);

dt = Open("$SAMPLE_DATA\Powder Metallurgy.jmp");
fm = dt << Fit Model(
	Y(:Shrinkage),
	Effects(:Formation Method, :Compaction Method, :Sintering Time),
	Personality("Standard Least Squares"),
	Emphasis("Effect Leverage"),
	Run()
);

dtEquations = dt << Summary(Group(:Formation Method, :Compaction Method), Freq("None"), Weight("None"));

dtEquations << New Column("Sintering Time", Character, Continuous, << Set Each Value(
	PredForm = Arg(Arg((FM << GetPredictionFormula), 3), 1);
	PredForm = Substitute(Name Expr(PredForm), Extract Expr(PredForm, Match(Wild List())), Eval(Extract Expr(PredForm, Match(Wild List()))));
	PredForm = Substitute(Name Expr(PredForm), Extract Expr(PredForm, Match(Wild List())), Eval(Extract Expr(PredForm, Match(Wild List()))));
	Char(Name Expr(PredForm));
));

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How to get the half evaluated form of a prediction equation

This will most likely require quite a lot of modification, but one option would be to use Extract Expr

Names Default To Here(1);

dt = Open("$SAMPLE_DATA\Powder Metallurgy.jmp");
fm = dt << Fit Model(
	Y(:Shrinkage),
	Effects(:Formation Method, :Compaction Method, :Sintering Time),
	Personality("Standard Least Squares"),
	Emphasis("Effect Leverage"),
	Run()
);

dtEquations = dt << Summary(Group(:Formation Method, :Compaction Method), Freq("None"), Weight("None"));

dtEquations << New Column("Sintering Time", Character, Continuous, << Set Each Value(
	PredForm = Arg(Arg((FM << GetPredictionFormula), 3), 1);
	PredForm = Substitute(Name Expr(PredForm), Extract Expr(PredForm, Match(Wild List())), Eval(Extract Expr(PredForm, Match(Wild List()))));
	PredForm = Substitute(Name Expr(PredForm), Extract Expr(PredForm, Match(Wild List())), Eval(Extract Expr(PredForm, Match(Wild List()))));
	Char(Name Expr(PredForm));
));

-Jarmo
pauldeen
Level VI

Re: How to get the half evaluated form of a prediction equation

@jthi brilliant, thank you!

I added a simplify expr to the last block to reduce all coefficients to one but otherwise solution was perfect.

dtEquations << New Column("Sintering Time", Character, Continuous, << Set Each Value(
	PredForm = Arg(Arg((FM << GetPredictionFormula), 3), 1);
	PredForm = Substitute( Name Expr( PredForm ),
		Extract Expr( PredForm, Match( Wild List() ) ), Eval( Extract Expr( PredForm, Match( Wild List() ) ) )
	);
	PredForm = Substitute( Name Expr( PredForm ),
		Extract Expr( PredForm, Match( Wild List() ) ), Eval( Extract Expr( PredForm, Match( Wild List() ) ) )
	);
	Char(Simplify Expr(Name Expr(PredForm)));
));
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to get the half evaluated form of a prediction equation

That is slick, great question @pauldeen and great solution @jthi !