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
frits_quadt
Level I

How can I parse effects to "Fit Model" in a script?

I am trying to pars effects to a fit model in a script. 

The effects are generated by a script using several runs of stepwise selection using nominal logistic regression. The selected variable names are outputted to a JMP datafile "final selection.jmp".

This is no problem if only main effects are selected, but I have not been successful in including a two factor interaction.

 

For main effects only I used the following script: 

 

 

Basedata=concat( projectpath, "final selection.jmp");
dt = OPEN(basedata);
myparameters = :Parameter << Get Values();
close(dt,nosave);

sdt = Open(concat(projectpath, "all data.jmp"));
UseEffects = {};
For (ii = 1, ii <= NItems(myparameters), ii++,
   colname = myparameters[ii];
   col = Column(sdt, colname);
   InsertInto(UseEffects, col)
  );
Fit Model(
 Y( :Y ),
 Effects( Eval(UseEffects)),
 Personality( "Nominal Logistic" ),
 Run( Likelihood Ratio Tests( 1 ), Wald Tests( 0 ), Confusion Matrix( 1 ) )
);

 

 

Using the same script if an interaction is selected results in an error message "could not find column ..."

 

I then tried the following script to generate an array with effects:

For (ii = 1, ii <= NItems(myparameters), ii++,
   colname = myparameters[ii];
   position = contains(colname,"*");
   If (position > 0,
   col = ":"||left(colname,position)||" :"||right(colname,length(colname)-position),
   col = ":"||colname);
   /*col = Column(sdt, colname);*/
   InsertInto(UseEffects, col)
  );

 

Although the effect names in UseEffects look ok, this also fails and gives again a "Column not found ... " error.

 

Any solution is welcome.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How can I parse effects to "Fit Model" in a script?

I think you might need to use JSL expressions for this. Below is an example similar to yours using the Boston Housing sample data table:

 

myparameters = {"crim*zn", "zn", "indus", "nox", "rooms", "age", "distance"};

sdt = Open("$SAMPLE_DATA/Boston Housing.jmp");

EffectsExpr = Expr(Effects());

For (ii = 1, ii <= NItems(myparameters), ii++,
	colname = myparameters[ii];
	position = contains(colname,"*");
	If (position > 0,
		col = ":"||left(colname,position)||" :"||right(colname,length(colname)-position),
		col = ":"||colname
	);
	/*col = Column(sdt, colname);*/
	InsertInto(EffectsExpr, parse(col))
);

fmExpr = substitute(
	Expr(Fit Model(
	 Y( :chas ),
	 _effects_,
	 Personality( "Nominal Logistic" ),
	 Run( Likelihood Ratio Tests( 1 ), Wald Tests( 0 ), Confusion Matrix( 1 ) )
	)),
	expr(_effects_),
	nameexpr(EffectsExpr)
);

eval(fmExpr)
Michael Crotty
Principal Statistical Writer
Manager, Statistical Documentation
JMP Development

View solution in original post

5 REPLIES 5

Re: How can I parse effects to "Fit Model" in a script?

I think you might need to use JSL expressions for this. Below is an example similar to yours using the Boston Housing sample data table:

 

myparameters = {"crim*zn", "zn", "indus", "nox", "rooms", "age", "distance"};

sdt = Open("$SAMPLE_DATA/Boston Housing.jmp");

EffectsExpr = Expr(Effects());

For (ii = 1, ii <= NItems(myparameters), ii++,
	colname = myparameters[ii];
	position = contains(colname,"*");
	If (position > 0,
		col = ":"||left(colname,position)||" :"||right(colname,length(colname)-position),
		col = ":"||colname
	);
	/*col = Column(sdt, colname);*/
	InsertInto(EffectsExpr, parse(col))
);

fmExpr = substitute(
	Expr(Fit Model(
	 Y( :chas ),
	 _effects_,
	 Personality( "Nominal Logistic" ),
	 Run( Likelihood Ratio Tests( 1 ), Wald Tests( 0 ), Confusion Matrix( 1 ) )
	)),
	expr(_effects_),
	nameexpr(EffectsExpr)
);

eval(fmExpr)
Michael Crotty
Principal Statistical Writer
Manager, Statistical Documentation
JMP Development
frits_quadt
Level I

Re: How can I parse effects to "Fit Model" in a script?

Thank you, I have used the solution you described and it did solve my problem.

 

 

lazzybug
Level III

Re: How can I parse effects to "Fit Model" in a script?

@michael_jmp Do you know if we can get the effect list from DoE model? Because the effect list was saved in the model when we design the DoE, we don't have to manual generate effect list as mentioned here. For example, how to get the list of Y, and Effects from the model script below? Thank you so much.

 

Fit Model(Y(:Y1, :Y2, :Y3, :Y4, :Y5, :Y6, :Y7, :Y8, :Y9, :Y10, :Y11, :Y12, :Y13, :Y14, :Y15), Effects(:X1 & RS, :X2 & RS, :X3 & RS, :X4 & RS, :X5 & RS, :X1 * :X1, :X1 * :X2, :X2 * :X2, :X1 * :X3, :X2 * :X3, :X3 * :X3, :X1 * :X4, :X2 * :X4, :X3 * :X4, :X4 * :X4, :X1 * :X5, :X2 * :X5, :X3 * :X5, :X4 * :X5, :X5 * :X5, :Block, :X6, :X7), Personality(\!"Standard Least Squares\!"))

jthi
Super User

Re: How can I parse effects to "Fit Model" in a script?

There are at least two options, parsing that function as a string or expression. Below is one option how you could parse it as expression using Arg()

 

Names Default To Here(1);

f = Expr(Fit Model(
	Y(:Y1, :Y2, :Y3, :Y4, :Y5, :Y6, :Y7, :Y8, :Y9, :Y10, :Y11, :Y12, :Y13, :Y14, :Y15),
	Effects(
		:X1 & RS, :X2 & RS, :X3 & RS, :X4 & RS, :X5 & RS, :X1 * :X1, :X1 * :X2, :X2 * :X2, :X1 * :X3,
		:X2 * :X3, :X3 * :X3, :X1 * :X4, :X2 * :X4, :X3 * :X4, :X4 * :X4, :X1 * :X5, :X2 * :X5, :X3 * :X5,
		:X4 * :X5, :X5 * :X5, :Block, :X6, :X7
	),
	Personality("Standard Least Squares")
));

first_arg = Arg(f, 1);
second_arg = Arg(f, 2);
ys = Substitute(Arg(f, 1), Expr(Y), Expr(List()));
show(first_arg); // first_arg = Y(:Y1, :Y2, :Y3, :Y4, :Y5, :Y6, :Y7, :Y8, :Y9, :Y10, :Y11, :Y12, :Y13, :Y14, :Y15);
show(second_arg);
show(ys); // ys = {:Y1, :Y2, :Y3, :Y4, :Y5, :Y6, :Y7, :Y8, :Y9, :Y10, :Y11, :Y12, :Y13, :Y14, :Y15};

 

I think you could also use Extract Expr()

Extract Expr(f, Y(Wild List()));
-Jarmo
lazzybug
Level III

Re: How can I parse effects to "Fit Model" in a script?

Thank you so much for your help @jthi . I figured it out by myself, but your method is much simpler.