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

column switcher function in script only reports first variable

Hello,

The following script returns one output report with the first variable for switching (Two_deoxyuridine) but not the others in the switch list.  I've looked for a solution in the Scripting Index, YouTube videos, JMP community, and reading chapters in Jump into JMP.  Is the solution to insert a For Loop?  I'm using JMP17. 

Appreciate any and all help,

Annabelle

obj = dt << Fit Model(
	Y( :dthtt ),
	Effects(
		:race1c, :age2c, :gender1, :APOE_INT, :Two_Deoxyuridine_INT,
		:APOE_INT * :Two_Deoxyuridine_INT
	),
	Personality( "Proportional Hazard" ),
	Censor( :dth ),
	Censor Code( "0" ),
	Run( Likelihood Ratio Tests( 0 ) )
);
ColumnSwitcherObject = obj << Column Switcher(
	:Two_Deoxyuridine_INT,
	{:One_5_Anhydroglucitol_INT, :Two_Deoxyuridine_INT, :Two_Hydroxybutyric acid_INT,
	:Two_Hydroxyglutaric acid_INT}
);
1 ACCEPTED SOLUTION

Accepted Solutions
aromd
Level II

Re: column switcher function in script only reports first variable

Hello,

I've provided the final script for the column switcher function to provide concatenated data tables.  I did get some help from JMP Support on how to concatenate the tables. Hope this is helpful to others.

Annabelle

View solution in original post

6 REPLIES 6
jthi
Super User

Re: column switcher function in script only reports first variable

I'm not exactly sure what is the question. My example seems to be working fine (or I might be missing something)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Job Satisfaction.jmp");
obj = dt << Fit Model(
	Y(:Satisfaction_Avg),
	Effects(
		:Support_L, :Goal_L, :Work_L, :Interact_L, :Person_C,
		:Interact_L * :Person_C
	),
	Personality( "Proportional Hazard" ),
	Emphasis("Effect Leverage"),
	Run(
		:Satisfaction_Avg << {Summary of Fit(1), Analysis of Variance(1),
		Parameter Estimates(1), 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)}
	)
);

col_switcher = obj << Column Switcher(
	:Person_C,
	{:Person_C, :Intra_C, :Inter_C, General_S}
);

jthi_0-1681493366528.png

jthi_1-1681493375882.png

 

 

 

-Jarmo
aromd
Level II

Re: column switcher function in script only reports first variable

Thank you jthi for the quick reply.  I incorporated your script into mine and got the same problem.  The output table only contains results for Two_Deoxyuridine but not the other variables in the switch list.  I did run your script and it works as expected.  

Any ideas where I'm going wrong with this script?

Annabelle

obj = dt << Fit Model(
	Y( :dthtt ),
	Effects(
		:race1c, :PC1, :PC2, :PC3, :age2c, :gender1, :bmi2c.x, :chol2.x, :curalc2.x, :pkyrs2c.x, :dbp2c.x,
		:sbp2c.x, :creatin1.x, :glucos2c.x, :APOE_INT, :Two_Deoxyuridine_INT,
		:APOE_INT * :Two_Deoxyuridine_INT
	),
	Personality( "Proportional Hazard" ),
	Emphasis( "Effect Leverage" ),
	Censor( :dth ),
	Censor Code( "0" ),
	Run(
		:dthtt << {Summary of Fit( 1 ), Analysis of Variance( 1 ), Parameter Estimates( 1 ),
		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 )}
	)
);
ColumnSwitcherObject = obj << Column Switcher(
	:Two_Deoxyuridine_INT,
	{:One_5_Anhydroglucitol_INT, :Two_Deoxyuridine_INT,
	:Two_Hydroxybutyric acid_INT, :Two_Hydroxyglutaric acid_INT,
	:Two_ketoisovaleric acid_INT, :Three_Hydroxybutyric acid_INT, :Five_MTHF_INT, 
aromd
Level II

Re: column switcher function in script only reports first variable

Addendum:  I was hoping the Column Switcher function would generate new Effect Summary tables with each variable.  The script works well with the first variable and then you can manually scroll through the Column Switcher to look at the other variables.  I want to NOT have to manually scroll through the list.  Is this possible?

aromd
Level II

Re: column switcher function in script only reports first variable

I'm making progress!  My main objective is to get a Effect Wald Test data table after every column switch. Eventually I will concatenate these tables.  The code below automatically starts the column switcher (this can be seen in the log) and does produce the Effect Wald Test data table but only for the first entry in the column switcher.  Any ideas on how to get the Effect Wald Test data table from each column when it switches? 

obj = dt << Fit Model(
	Y( :dthtt ),
	Effects(
		:race1c, :PC1, :PC2, :PC3, :age2c, :gender1, :bmi2c.x, :chol2.x, :curalc2.x, :pkyrs2c.x, :dbp2c.x,
		:sbp2c.x, :creatin1.x, :glucos2c.x, :APOE_INT, :One_5_Anhydroglucitol_INT,
		:APOE_INT * :One_5_Anhydroglucitol_INT
	),
	Personality( "Proportional Hazard" ),
	Censor( :dth ),
	Censor Code( "0" ),
	Run(
		:dthtt << {Summary of Fit( 1 ), Analysis of Variance( 1 ), Parameter Estimates( 1 ),
		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 )}
	)
);

ColumnSwitcher = obj << Column Switcher(
	:One_5_Anhydroglucitol_INT,
	{:One_5_Anhydroglucitol_INT, :Two_Deoxyuridine_INT, :Two_Hydroxybutyric acid_INT,
	:Two_Hydroxyglutaric acid_INT, :Dummy variable_INT}
);

 

pre = Function( {currentColumn, nextColumn, switcher},
	Print(
		"Before switch: " || (currentColumn << get name) || " >> " || (nextColumn << get name) ||
		" [Column Switcher] current: " || (columnSwitcher << Get Current)
	);
	If( nextColumn << get name == "Dummy variable_INT",
		0,
		1
	);
);
post = Function( {previousColumn, currentColumn, switcher},
	Print(
		"After switch: " || (previousColumn << get name) || " >> " || (currentColumn << get name) ||
		" [Column Switcher] current: " || (columnSwitcher << Get Current)
	)
);
columnSwitcher << Make Column Switch Handler( pre, post );
ColumnSwitcher << Set Script(
	obj = Data Table( "MESA 2018Events_Exam2Main_Proteomics_Metabolomics_MARCH 13 2023" ) <<
	Fit Model(
		Y( :dthtt ),
		Effects(
			:race1c, :PC1, :PC2, :PC3, :age2c, :gender1, :bmi2c.x, :chol2.x, :curalc2.x, :pkyrs2c.x, :dbp2c.x,
			:sbp2c.x, :creatin1.x, :glucos2c.x, :APOE_INT, :One_5_anhydroglucitol_INT,
			:APOE_INT * :One_5_anhydroglucitol_INT
		),
		Personality( "Proportional Hazard" ),
		Censor( :dth ),
		Censor Code( "0" ),
		Run( Likelihood Ratio Tests( 0 ) ),
		Column Switcher(
			:One_5_anhydroglucitol_INT,
			{:One_5_Anhydroglucitol_INT, :Two_Deoxyuridine_INT, :Two_Hydroxybutyric acid_INT,
			:Two_Hydroxyglutaric acid_INT, :Dummy variable_INT}
		)
	);
	Report( obj )["Effect Wald Tests", Table Box( 1 )] << Make Into Data Table;
	obj << Close Window;
);

ColumnSwitcher << Run;
Wait( 5/*seconds, while it animates*/ );
aromd
Level II

Re: column switcher function in script only reports first variable

Hello

I solved my problem and the script is attached.  One tip was to place a dummy variable column in the main table and to place it after the final variable for the column switch.  This allowed the column switch to work appropriately.  My next step is to concatenate all of the Effect Wald Tests data tables, and I don't think that should be difficult.  I hope this script is useful to others in the community.

Annabelle

aromd
Level II

Re: column switcher function in script only reports first variable

Hello,

I've provided the final script for the column switcher function to provide concatenated data tables.  I did get some help from JMP Support on how to concatenate the tables. Hope this is helpful to others.

Annabelle