cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Juli
Level I

Reporting of data from LSMeans Differences Student's t

Hi all,

I am trying to make a report with specific data from the table of LSMeans Differences Student's t:

Juli_0-1731921303275.png

I would like a table with one of the formats as below: 

Juli_1-1731921761984.png

Juli_0-1731923239812.png

 

 

Sadly, I cannot get it to print correctly for the mean and it cannot take data from the bigger table. I get the below

Juli_3-1731922050015.png

 

I have tried the following code, where I have altered the '17' to numbers from 1-30 and nothing works - 17 is for a different outline box:

 

 

sd = Open( "test_table.jmp" );

Fitmod = Fit Model(
Y( :"Test value"n ),
Effects( :Person ),
Random Effects( :Day[:Person] ),
NoBounds( 0 ),
Personality( "Standard Least Squares" ),
Method( "REML" ),
Emphasis( "Effect Leverage" ),
Run(
:"Test value"n << {Summary of Fit( 1 ),
Analysis of Variance( 0 ), 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 ),
{:Person << {LSMeans Student's t( 0.05 )}}}
),
Where( :ID == "A1" ),
SendToReport(
Dispatch(
{"Test value ID=A1"},
"Whole Model",
OutlineBox,
{Close( 1 )}
),
Dispatch(
{"Test value ID=A1", "Person"},
"Leverage Plot",
OutlineBox,
{Close( 1 )}
)
)
);

report(Fitmod) [Outline Box( 2 )] << Close( 0 );
reportFitmod = Fitmod << Report;

sumfit = reportFitmod[Outline Box( 17 )][Number Col Box( 1 )] << Get as Matrix; meandiff = sumfit[1]; lowerCL = sumfit[3]; upperCL = sumfit[4];

term = reportFitmod[Outline Box( 13 )][String Col Box( 1 )] << Get();

est = reportFitmod[Outline Box( 13 )][Number Col Box( 1 )] << Get as Matrix;

dvalues = [];
dvalues = meandiff |/ lowerCL |/ upperCL ;
sfactor = term[2];

dlg = New Window( "Custom Report",
Outline Box( "Selected Values",
Lineup Box( N Col( 2 ),
Text Box( "Factor of Interest: " ),
Text Box( sfactor ), ),
tb = Table Box(

String Col Box( " ",
{"Mean difference: ", "Upper limit: ", "Lower limit: "}
),
Spacer Box( Size( 30, 30 ) ),
,
Spacer Box( Size( 0, 30 ) ),
,
Table Box(
CloneTerm,
Spacer Box( Size( 10, 0 ) ),
,
Number Col Box( "Estimate", est ),
Spacer Box( Size( 10, 0 ) ),
,
Number Col Box( "Mean difference", meandiff)
)
)
);

tb << Set Shade Headings( 0 ); // Turn off shaded table headings.
tb << Set Heading Column Borders( 0 ); // Turn off table column borders.

 

 

How do you report the data from the bigger table?

 

Best regards

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

This may give you a leg up on getting your final product.  It produces

txnelson_0-1731940502918.png

Names Default To Here( 1 );
sd = //Open( "test_table.jmp" );
Data Table( "test_table" );
Fitmod = Fit Model(
	Y( :"Test value"n ),
	Effects( :Person ),
	Random Effects( :Day[:Person] ),
	NoBounds( 0 ),
	Personality( "Standard Least Squares" ),
	Method( "REML" ),
	Emphasis( "Effect Leverage" ),
	Run(
		:"Test value"n << {Summary of Fit( 1 ), Analysis of Variance( 0 ), 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 ), {:Person << {LSMeans Student's t( 0.05 )}}}
	),
	Where( :ID == "A1" ),
	SendToReport(
		Dispatch( {"Test value ID=A1"}, "Whole Model", OutlineBox, {Close( 1 )} ),
		Dispatch( {"Test value ID=A1", "Person"}, "Leverage Plot", OutlineBox, {Close( 1 )} )
	)
);
Report( Fitmod )[Outline Box( 2 )] << Close( 0 );
reportFitmod = Fitmod << Report;
sumfit = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix; 
// Get data from CrossTab table
crossTab = reportFitmod[Outline Box( "LSMeans Differences Student's t" )][CrosstabBox( 1 )] << get as matrix;
// Get Where clause variable
whereCol = Word( 2, ((reportFitmod << parent)[Text Box( 1 )]) << get text, ":=)" );
whereVal = {};
Eval( Parse( "insert into(whereVal," || Word( 2, ((reportFitmod << parent)[Text Box( 1 )]) << get text, "=)" ) || ");" ) );
meandiff = Round( Abs( crossTab[1, 2] ), 4 );
lowerCL = Round( Abs( crossTab[3, 2] ), 3 );
upperCL = Round( Abs( crossTab[4, 2] ), 3 );
term = reportFitmod[Outline Box( "Least Squares Means Table" )][String Col Box( 1 )] << Get();
est = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix;
testValue = {};
Insert Into( testValue, (Substr( reportFitmod[Outline Box( 1 )] << get title, 10 )) );
dif = {};
Insert Into( dif, Char( meandiff ) || " [" || Char( lowerCL ) || ";" || Char( upperCL ) || "]" );

dlg = New Window( "Custom Report",
	Outline Box( "Selected Values",
		Lineup Box( N Col( 2 ), Text Box( "Factor of Interest: " ), Text Box( sfactor ) ),
		Spacer Box( size( 0, 10 ) ),
		tb = Table Box(
			String Col Box( "Test Value", testvalue ),
			String Col Box( whereCol, whereVal ),
			Number Col Box( "Mean, " || term[1], sumfit[1] ),
			Number Col Box( "Mean, " || term[2], sumfit[2] ),
			String Col Box( "Difference in mean and CI", dif )
			
		)
	)

);
tb << Set Shade Headings( 0 ); // Turn off shaded table headings.
tb << Set Column Borders( 1 ); // Turn off table column borders.
tb << Set row Borders( 1 );
tb << border( 1 );

 

 

Jim

View solution in original post

9 REPLIES 9
txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

Welcome to the JMP Community.

I think there is a mix up between the data table you attached and the script you attached.  The references in the script to the columns to be analyzed do not match the columns in the attached data table.

If you can provide the correct attachments I am sure the Community will be able to assist you in your efforts.

Jim
Juli
Level I

Re: Reporting of data from LSMeans Differences Student's t

Dear Jim,

I apologize for the mix-up. Thank you for letting me know. I have attached the correct script now. 

Julie

txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

This may give you a leg up on getting your final product.  It produces

txnelson_0-1731940502918.png

Names Default To Here( 1 );
sd = //Open( "test_table.jmp" );
Data Table( "test_table" );
Fitmod = Fit Model(
	Y( :"Test value"n ),
	Effects( :Person ),
	Random Effects( :Day[:Person] ),
	NoBounds( 0 ),
	Personality( "Standard Least Squares" ),
	Method( "REML" ),
	Emphasis( "Effect Leverage" ),
	Run(
		:"Test value"n << {Summary of Fit( 1 ), Analysis of Variance( 0 ), 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 ), {:Person << {LSMeans Student's t( 0.05 )}}}
	),
	Where( :ID == "A1" ),
	SendToReport(
		Dispatch( {"Test value ID=A1"}, "Whole Model", OutlineBox, {Close( 1 )} ),
		Dispatch( {"Test value ID=A1", "Person"}, "Leverage Plot", OutlineBox, {Close( 1 )} )
	)
);
Report( Fitmod )[Outline Box( 2 )] << Close( 0 );
reportFitmod = Fitmod << Report;
sumfit = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix; 
// Get data from CrossTab table
crossTab = reportFitmod[Outline Box( "LSMeans Differences Student's t" )][CrosstabBox( 1 )] << get as matrix;
// Get Where clause variable
whereCol = Word( 2, ((reportFitmod << parent)[Text Box( 1 )]) << get text, ":=)" );
whereVal = {};
Eval( Parse( "insert into(whereVal," || Word( 2, ((reportFitmod << parent)[Text Box( 1 )]) << get text, "=)" ) || ");" ) );
meandiff = Round( Abs( crossTab[1, 2] ), 4 );
lowerCL = Round( Abs( crossTab[3, 2] ), 3 );
upperCL = Round( Abs( crossTab[4, 2] ), 3 );
term = reportFitmod[Outline Box( "Least Squares Means Table" )][String Col Box( 1 )] << Get();
est = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix;
testValue = {};
Insert Into( testValue, (Substr( reportFitmod[Outline Box( 1 )] << get title, 10 )) );
dif = {};
Insert Into( dif, Char( meandiff ) || " [" || Char( lowerCL ) || ";" || Char( upperCL ) || "]" );

dlg = New Window( "Custom Report",
	Outline Box( "Selected Values",
		Lineup Box( N Col( 2 ), Text Box( "Factor of Interest: " ), Text Box( sfactor ) ),
		Spacer Box( size( 0, 10 ) ),
		tb = Table Box(
			String Col Box( "Test Value", testvalue ),
			String Col Box( whereCol, whereVal ),
			Number Col Box( "Mean, " || term[1], sumfit[1] ),
			Number Col Box( "Mean, " || term[2], sumfit[2] ),
			String Col Box( "Difference in mean and CI", dif )
			
		)
	)

);
tb << Set Shade Headings( 0 ); // Turn off shaded table headings.
tb << Set Column Borders( 1 ); // Turn off table column borders.
tb << Set row Borders( 1 );
tb << border( 1 );

 

 

Jim
Juli
Level I

Re: Reporting of data from LSMeans Differences Student's t

Hi Jim,

 

How should the script be altered if there are multiple IDs to generate a table with all the different elements? Can a loop be implemented for this? 

 

Best regards,

Julie 

txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

I have modified the JSL to be able to handle multiple levels of ID.

txnelson_0-1732101149794.png

Names Default To Here( 1 );
sd = //Open( "test_table.jmp" );
Data Table( "test_table " );
Fitmod = Fit Model(
	Y( :"Test value"n ),
	Effects( :Person ),
	Random Effects( :Day[:Person] ),
	NoBounds( 0 ),
	Personality( "Standard Least Squares" ),
	Method( "REML" ),
	Emphasis( "Effect Leverage" ),
	Run(
		:"Test value"n << {Summary of Fit( 1 ), Analysis of Variance( 0 ), 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 ), {:Person << {LSMeans Student's t( 0.05 )}}}
	),
	by( :ID ),
	SendToReport(
		Dispatch( {"Test value ID=A1"}, "Whole Model", OutlineBox, {Close( 1 )} ),
		Dispatch( {"Test value ID=A1", "Person"}, "Leverage Plot", OutlineBox, {Close( 1 )} )
	)
);

// Set the lists for the storage of the data from the by groups
whereVal = testValue = dif = sumfit1 = sumfit2 = {};

// Loop across each by group and gather the data
For Each( {rpt, group}, Fitmod, 
	// Point to the current report
	reportFitmod = Fitmod[group] << Report;
	
	// Get the means for the 2 levels
	sumfit = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix;
	Insert Into( sumfit1, sumfit[1] );
	Insert Into( sumfit2, sumfit[2] );
	term = reportFitmod[Outline Box( "Least Squares Means Table" )][String Col Box( 1 )] << Get();
	
	// Get By Group column
	whereCol = Word( 1, (reportFitmod[Outline Box( 1 )] << get title), "=)" );
	Insert Into( whereVal, Word( 2, (reportFitmod[Outline Box( 1 )] << get title), "=)" ) );
		
	// Get data from CrossTab table
	crossTab = reportFitmod[Outline Box( "LSMeans Differences Student's t" )][CrosstabBox( 1 )] <<
	get as matrix;
	meandiff = Round( Abs( crossTab[1, 2] ), 4 );
	lowerCL = Round( Abs( crossTab[3, 2] ), 3 );
	upperCL = Round( Abs( crossTab[4, 2] ), 3 );
	
	// Get the Response variable name
	Insert Into( testValue, (Substr( (reportFitmod << topparent)[Outline Box( 1 )] << get title, 10 )) );

	// Create the Differeence in mean and CL string
	Insert Into( dif, Char( meandiff ) || " [" || Char( lowerCL ) || ";" || Char( upperCL ) || "]" );
);

// Create the table
dlg = New Window( "Custom Report",
	Outline Box( "Selected Values",
		Lineup Box( N Col( 2 ), Text Box( "Factor of Interest: " ), Text Box( term[1] ) ),
		Spacer Box( size( 0, 10 ) ),
		tb = Table Box(
			String Col Box( "Test Value", testvalue ),
			String Col Box( whereCol, whereVal ),
			Number Col Box( "Mean, " || term[1], sumfit1 ),
			Number Col Box( "Mean, " || term[2], sumfit2 ),
			String Col Box( "Difference in mean and CI", dif )
			
		)
	)

);
tb << Set Shade Headings( 0 ); // Turn off shaded table headings.
tb << Set Column Borders( 1 ); // Turn off table column borders.
tb << Set row Borders( 1 );
tb << border( 1 );

Your job now is to study the script, and learn what it does.  The script works for the sample data table and Fit Model you specified.  However, different data tables with different columns and different Fit Model executions may not work with the JSL that generates the report output.  You will need to become knowledgeable enough to modify the script to meet your needs.

Good references for this is the Scripting Guide and the Scripting Index, available under the Help pull down menu in JMP.

Of course, the JMP Discussion Community will be there to assist you with your learning of the script.

Jim
Juli
Level I

Re: Reporting of data from LSMeans Differences Student's t

Thank you for your impressive work!

 

I have tried to run the script, but I get an error. I have tried to browse through old cases and google for both the function For Each and the error as well as trying to modify the script but to no avail. I have version 16, could this pose an issue to the script?

 

My belief is the error stems from {rpt, group} as I have tried to remove all in the For Each and I still get this error. 

Juli_0-1733328225343.png

 

Most of it I can understand, but where do we get this rpt from and how is it used? It is only mentioned in the For Each( {rpt, group} ...) so I cannot rationalise how it fits.

 

txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

What version of JMP are you using?  For Each() was added to JMP in version 16.  The By() functionality in Fit Mod was not added until JMP 18.  

The script will need to be modified to handle both of these changes.

Jim
Juli
Level I

Re: Reporting of data from LSMeans Differences Student's t

I use JMP version 16.1.0, so that must be the reason.

Does the FitMod function need to be replaced by another function or can FitMod still be used just differently? 

txnelson
Super User

Re: Reporting of data from LSMeans Differences Student's t

Here is a modified version of the script.  I have tested it in JMP 16.  I removed the By clause and replaced the functionality with a For Each() loop that runs the Fit Model for each level of ID separately.  The script then gathers the output from each of the separate Fit Model outputs and generates the final output display

txnelson_0-1734015772163.png

Names Default To Here( 1 );
sd = //Open( "test_table.jmp" );
Data Table( "test_table" );
Fitmod = {};

// Determine the levels in the ID column
summarize( sd, ByGroups = By( :ID ) );

// Loop across each levle of ID 
For Each( {BG, group}, ByGroups,
	Fm = Fit Model(
		Y( :"Test value"n ),
		Effects( :Person ),
		Random Effects( :Day[:Person] ),
		NoBounds( 0 ),
		Personality( "Standard Least Squares" ),
		Method( "REML" ),
		Emphasis( "Effect Leverage" ),
		Run(
			:"Test value"n << {Summary of Fit( 1 ), Analysis of Variance( 0 ),
			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 ), {:Person << {LSMeans Student's t( 0.05 )}}}
		),
		Where( :ID == ByGroups[group] ),
		SendToReport(
			Dispatch( {"Test value ID=A1"}, "Whole Model", OutlineBox, {Close( 1 )} ),
			Dispatch(
				{"Test value ID=A1", "Person"},
				"Leverage Plot",
				OutlineBox,
				{Close( 1 )}
			)
		)
	);

// Save the pointer to the results in the Fitmod list
	Insert Into( Fitmod, Fm );
);

// Set the lists for the storage of the data from the by groups
testValue = dif = sumfit1 = sumfit2 = {};

// Loop across each by group and gather the data
For Each( {rpt, group}, Fitmod, 
	// Point to the current report
	reportFitmod = Fitmod[group] << Report;
	
	// Get the means for the 2 levels
	sumfit = reportFitmod[Outline Box( "Least Squares Means Table" )][Number Col Box( 1 )] << Get as Matrix;
	Insert Into( sumfit1, sumfit[1] );
	Insert Into( sumfit2, sumfit[2] );
	term = reportFitmod[Outline Box( "Least Squares Means Table" )][String Col Box( 1 )] << Get();
	
	// Get By Group column
	whereCol = Word( 2, ((reportFitmod << parent)[Text Box( 1 )]) << get text, ":=)" );
		
	// Get data from CrossTab table
	crossTab = reportFitmod[Outline Box( "LSMeans Differences Student's t" )][CrosstabBox( 1 )] <<
	get as matrix;
	meandiff = Round( Abs( crossTab[1, 2] ), 4 );
	lowerCL = Round( Abs( crossTab[3, 2] ), 3 );
	upperCL = Round( Abs( crossTab[4, 2] ), 3 );
	
	// Get the Response variable name
	Insert Into( testValue, (Substr( (reportFitmod << topparent)[Outline Box( 1 )] << get title, 10 )) );

	// Create the Differeence in mean and CL string
	Insert Into( dif, Char( meandiff ) || " [" || Char( lowerCL ) || ";" || Char( upperCL ) || "]" );
);

// Create the table
dlg = New Window( "Custom Report",
	Outline Box( "Selected Values",
		Lineup Box( N Col( 2 ), Text Box( "Factor of Interest: " ), Text Box( term[1] ) ),
		Spacer Box( size( 0, 10 ) ),
		tb = Table Box(
			String Col Box( "Test Value", testvalue ),
			String Col Box( whereCol, ByGroups ),
			Number Col Box( "Mean, " || term[1], sumfit1 ),
			Number Col Box( "Mean, " || term[2], sumfit2 ),
			String Col Box( "Difference in mean and CI", dif )
			
		)
	)

);
tb << Set Shade Headings( 0 ); // Turn off shaded table headings.
tb << Set Column Borders( 1 ); // Turn off table column borders.
tb << Set row Borders( 1 );
tb << border( 1 );
Jim