cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lisamaley
Level III

Dunnett's for Multiple Ys

I am trying to get a script that will run Dunnett's on multiple Ys automatically in fit model, my issues:

 

If I change the multiple comparisons part where the factor and level is not a variable it works but only for the first Y, it will not repeat the Dunnett's part for the remaining Ys.   So my questions:

 

1.  Why doesn't this work like the fit model with a variable being used for the factor and control level for Dunnett's?

2.  Can we get Dunnett's for multiple Ys automatically?

 

Lisa

 

This is what I have so far:

Names Default To Here( 1 );

Clear Log();
lbwidth = 130;
Tolerance = .01;

If( Not( Is Scriptable( dt ) ), 

// Check that there is a data set open;
	//ca=Caption("Please Open Design Data Set", Back Color(yellow));
	//Stop();

	dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );
	If( dtsel == "",
		Stop(),
		Try( dt = Open( dtsel ), Stop() )
	);
);

Dia_Window = Expr(

// Window to get list of factors and response;
	Factorws = New Window( "Fit Model With Dunnetts",
		show toolbars( 0 ),
		Show Menu( 0 ),
		Border Box( Left( 3 ), top( 2 ),
			V List Box(
				H List Box(
					Panel Box( "Select Column to be used as the Factor and the Response(s)",
						colListData = Col List Box(
							All,
							width( lbWidth ),
							nLines( Min( nc, 10 ) )
						)

					), 

					Panel Box( "The Factor",
						Lineup Box( N Col( 2 ), Spacing( 3 ),
							Button Box( "Factor",
								colListW << Append( colListData << GetSelected )
							),
							colListW = Col List Box(
								width( lbWidth ),
								nLines( 1 ),
								MinItems( 1 )
							),

						)
					), 

					Panel Box( "The Response(s)",
						Lineup Box( N Col( 2 ), Spacing( 3 ),
							Button Box( "Response(s)",
								colListY << Append( colListData << GetSelected )
							),
							colListY = Col List Box(
								width( lbWidth ),
								nLines( 8 ),
								MinItems( 1 )
							),

						)
					), 

					Panel Box( "Action",
						Lineup Box( N Col( 1 ),
							Button Box( "OK",
								nm = colListW << GetItems;
								nY = colListY << GetItems;
								If( N Items( nm ) > 0,
									dm = dt << Get As Matrix( nm );
									Factorws << Close Window;
									Eval( next );
								);
							),
							Button Box( "Cancel",
								Factorws << Close Window;
								Stop();
							),
							Text Box( " " ),
							Button Box( "Remove",
								colListW << RemoveSelected;
								colListY << RemoveSelected;
							)
						)
					)
				),
				Text Box( "Written by Lisa Winland lisawinland@icloud.com" )
			)
		)
	)
);
next = Expr(
	Show( nm );
	colvalues = Associative Array( Column( nm ) ) << Get Keys;
	Show( colvalues );
	listvalues = {};
	Show( nY );
	nw = New Window( "User Input for Dunnett's",
		Outline Box( "Level Selection for Dunnett's",
			values = {};
			i = 1;
			For( i = 1, i <= N Items( colvalues ), i += 1,
				Values[i] = Char( colvalues[i] )
			);
			Show( Values );
			H List Box(
				Text Box( "Select Value for Control" ),
				listvalues = List Box( Values )
			);,
			Button Box( "OK",
				level = (listvalues << Get selected);
				nw << Close Window;
				Eval( fiteval );
				Show( level );
			)
		)
	);
);
Fiteval = Expr(
	Show( nm );
	Show( nY );
	Show( level );
	controllevel = (Char( nm ) || ":" || Char( level ));
	Show( controllevel );
	Fit Model(
		Y( Eval( nY ) ),
		Effects( Eval( nm ) ),
		Personality( "Standard Least Squares" ),
		Emphasis( "Minimal Report" ),
		Run(
			:Y << {Summary of Fit( 1 ), Analysis of Variance( 1 ), Parameter Estimates( 1 ),
			Lack of Fit( 0 ), Expanded  Estimates( 1 ), Show Prediction Expression( 1 ),
			Sorted Estimates( 1 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 0 ),
			Plot Regression( 0 ), Plot Residual by Predicted( 0 ),
			Plot Studentized Residuals( 0 ), Plot Effect Leverage( 0 ),
			Plot Residual by Normal Quantiles( 0 ), Box Cox Y Transformation( 0 ), Show VIF( 1 ),
			Multiple Comparisons(
				Effect( Eval( nm ) ),
				Comparisons with Control(
					1,
					Control Level( Eval( Parse( controllevel ) ) ),
					Comparisons with Control Decision Chart(
						Control Differences Chart( 1, Point Options( "Show Needles" ) )
					)
				)
			)},
		)
	);
);

dt = Current Data Table();
nc = N Col( dt );
nr = N Row( dt );
Eval( Dia_Window );
12 REPLIES 12

Re: Dunnett's for Multiple Ys

I tried to accomplish your goal interactively first and then I saved the script. It seems that you can do it, but you need to send the list of options to each response. You  could insert expressions to accommodate multiple responses.

 

Names Default to Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

fit = dt << Fit Model(
	Y( :height, :weight ),
	Effects( :age ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Effect Leverage" ),
	Run(
		:height << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
		Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),
		Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
		Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),
		Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
		Box Cox Y Transformation( 0 ),
		Multiple Comparisons( Effect( :age ), Tukey HSD( 1 ) )},
		:weight << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
		Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),
		Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
		Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),
		Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
		Box Cox Y Transformation( 0 ),
		Multiple Comparisons(
			Effect( :age ),
			Comparisons with Control(
				1,
				Control Level( "age:12" ),
				Comparisons with Control Decision Chart(
					Control Differences Chart( 1, Point Options( "Show Needles" ) )
				)
			)
		)}
	)
);
lisamaley
Level III

Re: Dunnett's for Multiple Ys

I could not get the Dunnett's to accept a variable for the Effect or the Control Level.  How do you get it to accept a variable?

 

I need something where they select the variable and level, then it is repeated for each response. How you have it in your reply is the actual column name and actual level.

 

 

Re: Dunnett's for Multiple Ys

I modified my example further to show you how to use expressions to build the adaptive script for any number of responses.

 

For( c = 1, c <= N Items( y ), c++,
	Insert Into( run expr,
		Substitute(
			Expr(
				yyy << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
				Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),
				Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
				Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),
				Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
				Box Cox Y Transformation( 0 ),
				Multiple Comparisons(
					Effect( :age ),
					Comparisons with Control(
						1,
						Control Level( "age:12" ),
						Comparisons with Control Decision Chart(
							Control Differences Chart( 1, Point Options( "Show Needles" ) )
						)
					)
				)}
			),
			Expr( yyy ),
			y[c];
		)
	)
);

Eval(
	Substitute(
		Expr(
			fit = dt << Fit Model(
				Y( Eval( y ) ),
				Effects( Eval( x ) ),
				Personality( "Standard Least Squares" ),
				Emphasis( "Effect Leverage" ),
				rrr
			)
		),
		Expr( rrr ),
		Name Expr( run expr )
	)
);
lisamaley
Level III

Re: Dunnett's for Multiple Ys

But in your example, the effect is still the name of the column and so is the control level.  Can you do something like:

 

effect(eval(x))

Comparisons with control(

1,

control level(eval(level)),

 

I cannot get this to work.  Or do you have to have it as the actual names?

 

 

lisamaley_0-1632854623647.png

 

Re: Dunnett's for Multiple Ys

 What is captured in your dialog for the column selections? Is it a column reference or a name (character string)?

 

Assuming it is a character string, this code might work.

 

Names Default to Here( 1 );

// example
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// values from dialog
y = List( "height", "weight" );
x = "age";
level = 12;

// empty run argument for Fit Model message
run expr = Expr( Run() );

// iteratively add the optons for each response
For( c = 1, c <= N Items( y ), c++,
	Insert Into( run expr,
		Substitute(
			Expr(
				yyy << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
				Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),
				Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
				Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),
				Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
				Box Cox Y Transformation( 0 ),
				Multiple Comparisons(
					Effect( xxx ),
					Comparisons with Control(
						1,
						Control Level( ccc ),
						Comparisons with Control Decision Chart(
							Control Differences Chart( 1, Point Options( "Show Needles" ) )
						)
					)
				)}
			),
			Expr( yyy ),
			Parse( ":" || y[c] ),
			Expr( xxx ),
			Parse( ":" || x ),
			Expr( ccc ),
			x || ":" || Char( level )
		)
	)
);

// complete message and evaluate it
Eval(
	Substitute(
		Expr(
			fit = dt << Fit Model(
				Y( Eval( y ) ),
				Effects( Eval( x ) ),
				Personality( "Standard Least Squares" ),
				Emphasis( "Minimal Report" ),
				rrr
			)
		),
		Expr( rrr ),
		Name Expr( run expr )
	)
);
lisamaley
Level III

Re: Dunnett's for Multiple Ys

I tried to convert it into a string with this:

 

controllevel = (Char( nm ) || ":" || Char( level ));

 

But when I show it in JMP, it show \!" '\!: \!" '\! with the values of nm and level in between the " ".

 

What am I doing wrong?

lisamaley
Level III

Re: Dunnett's for Multiple Ys

Ok.  Nevermind, I understand what you are doing, but when I copy your code exactly, it shows this:

 

Effect not found: in access or evaluation of 'Multiple Comparisons' , Bad Argument( As Column() ), Multiple Comparisons(

Effect( As Column() ),

Comparisons with Control(

1,

Control Level( {"TS"}:{"1"} ),

Comparisons with Control Decision Chart(

Control Differences Chart( 1, Point Options( "Show Needles" ) )

 

I think this method will work, if we could get this last part figured out, it actually tried to do the multiple comparisons three times.

 

Lisa

 

 

 

lisamaley
Level III

Re: Dunnett's for Multiple Ys

I set my variables to Y and X, so that I could use your code directly, :

 

y = {"Y", "Y2", "Y3"};

x = {"X4"};

level = {"3"};

Effect not found: in access or evaluation of 'Multiple Comparisons' , Bad Argument( As Column() ), Multiple Comparisons(

Effect( As Column() ),

Comparisons with Control(

1,

Control Level( {"X4"}:{"3"} ),

Comparisons with Control Decision Chart(

Control Differences Chart( 1, Point Options( "Show Needles" ) )

)

)

) /*###*/

 

Unable to launch Multiple Comparisons

 

Effect not found: in access or evaluation of 'Multiple Comparisons' , Bad Argument( As Column() ), Multiple Comparisons(

Effect( As Column() ),

Comparisons with Control(

1,

Control Level( {"X4"}:{"3"} ),

Comparisons with Control Decision Chart(

Control Differences Chart( 1, Point Options( "Show Needles" ) )

)

)

) /*###*/

 

Unable to launch Multiple Comparisons

 

Effect not found: in access or evaluation of 'Multiple Comparisons' , Bad Argument( As Column() ), Multiple Comparisons(

Effect( As Column() ),

Comparisons with Control(

1,

Control Level( {"X4"}:{"3"} ),

Comparisons with Control Decision Chart(

Control Differences Chart( 1, Point Options( "Show Needles" ) )

)

)

) /*###*/

 

Unable to launch Multiple Comparisons

 

level = {"3"};

lisamaley
Level III

Re: Dunnett's for Multiple Ys

So here is my final code, it is still not working for the Dunnett's any suggestions?

 

Names Default To Here( 1 );

Clear Log();

lbwidth = 130;

Tolerance = .01;

 

 

If( Not( Is Scriptable( dt ) ), 

// Check that there is a data set open;

//ca=Caption("Please Open Design Data Set", Back Color(yellow));

//Stop();

dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );

If( dtsel == "",

Stop(),

Try( dt = Open( dtsel ), Stop() )

);

);

 

Dia_Window = Expr(

// Window to get list of factors and response;

Factorws = New Window( "Fit Model With Dunnetts",

show toolbars( 0 ),

Show Menu( 0 ),

Border Box( Left( 3 ), top( 2 ),

V List Box(

H List Box(

Panel Box( "Select Column to be used as the Factor and the Response(s)",

colListData = Col List Box( All, width( lbWidth ), nLines( Min( nc, 10 ) ) )

),

Panel Box( "The Factor",

Lineup Box( N Col( 2 ), Spacing( 3 ),

Button Box( "Factor", colListW << Append( colListData << GetSelected ) ),

colListW = Col List Box( width( lbWidth ), nLines( 1 ), MinItems( 1 ) ), 

 

)

), 

 

Panel Box( "The Response(s)",

Lineup Box( N Col( 2 ), Spacing( 3 ),

Button Box( "Response(s)", colListY << Append( colListData << GetSelected ) ),

colListY = Col List Box( width( lbWidth ), nLines( 8 ), MinItems( 1 ) ), 

 

)

), 

 

Panel Box( "Action",

Lineup Box( N Col( 1 ),

Button Box( "OK",

nm = colListW << GetItems;

nY = colListY << GetItems;

If( N Items( nm ) > 0,

dm = dt << Get As Matrix( nm );

Factorws << Close Window;

Eval( next );

);

),

Button Box( "Cancel",

Factorws << Close Window;

Stop();

),

Text Box( " " ),

Button Box( "Remove",

colListW << RemoveSelected;

colListY << RemoveSelected;

)

 

)

)

),

Text Box( "Written by Lisa Winland lisawinland@icloud.com" )

)

)

)

);

 

next = Expr(

Show( nm );

colvalues = Associative Array( Column( nm ) ) << Get Keys;

Show( colvalues );

listvalues = {};

Show( nY );

 

nw = New Window( "User Input for Dunnett's",

Outline Box( "Level Selection for Dunnett's",

values = {};

i = 1;

For( i = 1, i <= N Items( colvalues ), i += 1,

Values[i] = Char( colvalues[i] )

);

Show( Values );

H List Box( Text Box( "Select Value for Control" ), listvalues = List Box( Values ) );,

Button Box( "OK",

level = (listvalues << Get selected);

nw << Close Window;

eval(FitExp);

Show( level );

)

)

);

 

 

 

);

 

 

 

FitExp = Expr(

y = nY;

show(y);

x=nm;

show(x);

show(level);

 

// empty run argument for Fit Model message

run expr = Expr( Run() );

 

// iteratively add the optons for each response

For( c = 1, c <= N Items( y ), c++,

Insert Into( run expr,

Substitute(

Expr(

yyy << {Summary of Fit( 1 ), Analysis of Variance( 1 ),

Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),

Plot Actual by Predicted( 1 ), Plot Regression( 0 ),

Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),

Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),

Box Cox Y Transformation( 0 ),

Multiple Comparisons(

Effect( xxx ),

Comparisons with Control(

1,

Control Level( ccc ),

Comparisons with Control Decision Chart(

Control Differences Chart( 1, Point Options( "Show Needles" ) )

)

)

)}

),

Expr( yyy ),

Parse( ":" || y[c] ),

Expr( xxx ),

eval(Parse( ":" || Char(x) )),

Expr( ccc ),

Parse(char(x) || ":" || Char( level ))

)

)

);

 

// complete message and evaluate it

Eval(

Substitute(

Expr(

fit = dt << Fit Model(

Y( Eval( y ) ),

Effects( Eval( x ) ),

Personality( "Standard Least Squares" ),

Emphasis( "Minimal Report" ),

rrr

)

),

Expr( rrr ),

Name Expr( run expr )

)

);

);

dt = Current Data Table();

nc = N Col( dt );

nr = N Row( dt );

Eval( Dia_Window );