报告 LSMeans 差异学生 t 数据大家好,
我正在尝试使用 LSMeans Differences Student's t 表中的具体数据制作一份报告:

我想要一个具有以下格式之一的表格:


遗憾的是,我无法让它正确打印平均值,也无法从更大的表中获取数据。我得到以下结果

我尝试了以下代码,其中我已将“17”更改为 1 到 30 之间的数字,但没有任何效果 - 17 代表不同的轮廓框:
sd = Open( "test_table.jmp" );<BR /><BR />Fitmod = Fit Model(<BR />Y( :"Test value"n ),<BR />Effects( :Person ),<BR />Random Effects( :Day[:Person] ),<BR />NoBounds( 0 ),<BR />Personality( "Standard Least Squares" ),<BR />Method( "REML" ),<BR />Emphasis( "Effect Leverage" ),<BR />Run(<BR />:"Test value"n << {Summary of Fit( 1 ),<BR />Analysis of Variance( 0 ), Parameter Estimates( 1 ), Scaled Estimates( 0 ),<BR />Plot Actual by Predicted( 1 ), Plot Regression( 0 ),<BR />Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 0 ),<BR />Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),<BR />{:Person << {LSMeans Student's t( 0.05 )}}}<BR />),<BR />Where( :ID == "A1" ),<BR />SendToReport(<BR />Dispatch(<BR />{"Test value ID=A1"},<BR />"Whole Model",<BR />OutlineBox,<BR />{Close( 1 )}<BR />),<BR />Dispatch(<BR />{"Test value ID=A1", "Person"},<BR />"Leverage Plot",<BR />OutlineBox,<BR />{Close( 1 )}<BR />)<BR />)<BR />);<BR /><BR />report(Fitmod) [Outline Box( 2 )] << Close( 0 );<BR />reportFitmod = Fitmod << Report;<BR /><BR /><STRONG>sumfit = reportFitmod[Outline Box( 17 )][Number Col Box( 1 )] << Get as Matrix;
meandiff = sumfit[1];
lowerCL = sumfit[3];
upperCL = sumfit[4];</STRONG><BR /><BR />term = reportFitmod[Outline Box( 13 )][String Col Box( 1 )] << Get();<BR /><BR />est = reportFitmod[Outline Box( 13 )][Number Col Box( 1 )] << Get as Matrix;<BR /><BR />dvalues = [];<BR />dvalues = meandiff |/ lowerCL |/ upperCL ;<BR />sfactor = term[2];<BR /><BR />dlg = New Window( "Custom Report",<BR />Outline Box( "Selected Values",<BR />Lineup Box( N Col( 2 ),<BR />Text Box( "Factor of Interest: " ),<BR />Text Box( sfactor ), ),<BR />tb = Table Box(<BR /><BR />String Col Box( " ",<BR />{"Mean difference: ", "Upper limit: ", "Lower limit: "}<BR />),<BR />Spacer Box( Size( 30, 30 ) ),<BR />,<BR />Spacer Box( Size( 0, 30 ) ),<BR />,<BR />Table Box(<BR />CloneTerm,<BR />Spacer Box( Size( 10, 0 ) ),<BR />,<BR />Number Col Box( "Estimate", est ),<BR />Spacer Box( Size( 10, 0 ) ),<BR />,<BR />Number Col Box( "Mean difference", meandiff)<BR />)<BR />)<BR />);<BR /><BR />tb << Set Shade Headings( 0 ); // Turn off shaded table headings.<BR />tb << Set Heading Column Borders( 0 ); // Turn off table column borders.<BR />
如何报告更大表格中的数据?
此致
自动化和脚本回复:报告 LSMeans 差异学生的 t 数据欢迎来到 JMP 社区。
我认为您附加的数据表和附加的脚本混淆了。脚本中对要分析的列的引用与附加数据表中的列不匹配。
如果您能提供正确的附件,我相信社区将能够帮助您完成您的工作。
回复:报告 LSMeans 差异学生的 t 数据亲爱的吉姆,
我为混淆感到抱歉。感谢您告知我。我现在已经附上了正确的脚本。
朱莉
回复:报告 LSMeans 差异学生的 t 数据这可能会帮助你获得最终产品。它产生

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 );
回复:报告 LSMeans 差异学生的 t 数据嗨吉姆,
如果有多个 ID,应该如何修改脚本以生成包含所有不同元素的表格?可以为此实现循环吗?
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据我已经修改了 JSL,以便能够处理多级 ID。

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 );
您现在的工作是研究该脚本,并了解它的作用。该脚本适用于您指定的样本数据表和拟合模型。但是,具有不同列和不同拟合模型执行的不同数据表可能无法与生成报告输出的 JSL 配合使用。您需要具备足够的知识来修改脚本以满足您的需求。
对此很好的参考是脚本指南和脚本索引,可在 JMP 的帮助下拉菜单下找到。
当然,JMP 讨论社区将协助您学习脚本。
回复:报告 LSMeans 差异学生的 t 数据感谢您的出色工作!
我尝试运行该脚本,但出现错误。我尝试浏览旧案例,并在 Google 上搜索 For Each 函数和错误,并尝试修改脚本,但无济于事。我使用的是版本 16,这会给脚本带来问题吗?
我认为错误源于 {rpt, group},因为我试图删除 For Each 中的所有内容,但仍然收到此错误。

大部分我都能理解,但是我们从哪里得到这个 rpt 以及如何使用它?它只在 For Each( {rpt, group} ...) 中提到,所以我无法合理解释它是如何适用的。
回复:报告 LSMeans 差异学生的 t 数据您使用的是哪个版本的 JMP?For Each() 在版本 16 中添加到 JMP。Fit Mod 中的 By() 功能直到 JMP 18 才添加。
需要修改脚本来处理这两个变化。
回复:报告 LSMeans 差异学生的 t 数据我使用的是 JMP 版本 16.1.0,所以一定是这个原因。
FitMod 功能是否需要用其他功能替换,或者 FitMod 是否仍可以以不同的方式使用?
回复:报告 LSMeans 差异学生的 t 数据这是脚本的修改版本。我已经在 JMP 16 中对其进行了测试。我删除了 By 子句,并用 For Each() 循环替换了该功能,该循环分别针对每个 ID 级别运行拟合模型。然后,脚本收集来自每个单独的拟合模型输出的输出并生成最终输出显示

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 );回复:报告 LSMeans 差异学生的 t 数据嗨吉姆,
太感谢了!
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据嗨吉姆,
我还有一个问题。如果我想使用许多测试值运行分析,我是否可以:
1. 使用 FitModel 进行循环,然后按照上面的脚本继续?
2. 我是否单独进行分析,在一份报告中获取报告,然后运行一个像上述脚本一样保存数据的脚本?
或者我应该尝试研究其他方法吗?
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据朱莉,
两种方法都可能有效。
在我看来,一开始就做出这个决定是非常重大的决定。我会先想出你希望最终产品是什么样子,然后拿出脚本,修改它,让你在 2 个测试值上得到这个结果。这样既能让你对方法有更多的了解,也能让你了解 JSL 中你需要学习哪些方面,以便将脚本扩展到最终产品中。
回复:报告 LSMeans 差异学生的 t 数据嗨吉姆,
很高兴知道这两种方法都可以在 JSL 中实现。
是否可以改变代码,让 Y(:“测试值”n) 也遍历所有连续列?
// Determine the levels in the ID column
summarize( sd, ByGroups = By( :ID ) );
// Loop across each level 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 );
);我查看了许多其他循环并尝试将其更改为以下内容:
Names Default To Here( 1 );
sd = Open( "test_table_002.jmp" );
Data Table( "test_table_002" );
Fitmod = {};
// Determine the levels in the ID column
summarize( sd, ByGroups = By( :ID ) );
colList = sd << Get Column Names( Continuous, String );
// Loop across each level of ID
For Each( i = 1, i <= Nitems( colList ), i++,
For Each( {BG, group}, ByGroups,
Fm = Fit Model(
Y( colList ),
Effects( :Person ),
Random Effects( :Day[:Person] ),
NoBounds( 0 ),
Personality( "Standard Least Squares" ),
Method( "REML" ),
Emphasis( "Effect Leverage" ),
Run(
colList << {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 );
);
);然而,我收到了一个我不完全理解的错误代码。
我已附加一个测试表并再次检查是否附加了正确的表。
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据错误信息是什么?
回复:报告 LSMeans 差异学生的 t 数据错误信息如下:

我现在的剧本只有 43 行
回复:报告 LSMeans 差异学生的 t 数据您的脚本修改已经非常接近成功。在第 11 行中,您指定
For Each( i = 1, i <= Nitems( colList ), i++,
应该是
For( i = 1, i <= Nitems( colList ), i++,
函数 For Each() 和 For() 之间存在很大差异。 这两个不同函数的定义和示例可在脚本索引中找到。
您还需要将您的引用更改为
列表
在第 15 行和第 23 行中指定您引用的是 colList 中的哪些项目。
由于您使用变量“i”作为查找索引值,因此您需要指定
colList[i]
在您提供的示例数据表中,您只有 Test Value 列作为数字(连续)列,因此您只会使用 For() 函数循环一次。但是,如果您添加更多数字(连续)列,则使用我提到的语法修改进行编码将针对每个数字(连续)列运行
回复:报告 LSMeans 差异学生的 t 数据谢谢。这很有道理!
最后一个问题,如果我想更改发送给报告的 Dispatch 中的文本,该怎么做?
当前是“测试值 ID=A1”,打印的是 fx 测试值 1 或测试值 2。当我尝试更改为“测试值 ID=colList”时,打印的内容相同,所以我不明白它是如何工作的。
我希望它为 ID 为 A1 的 fx 测试值 1 打印以下文本:“测试值 1,ID=A1”。我尝试了不同的字符串和函数,但要么出现错误,要么只是打印与以前相同的内容。
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据我不明白你在说什么。我会从另一个角度来处理这个问题。以下是数据表中测试值 1 列的输出

你想改变这个输出什么?
回复:报告 LSMeans 差异学生的 t 数据亲爱的吉姆,
我已将其写入我想更改的图片,如下所示:

如果不指定ID,那么我不知道如何区分有多个ID时弹出的不同窗口。
我希望这更有意义:)
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据您可以通过调整显示树对象来更改报告输出的值。

通过添加
report(fm)[OutlineBox(1)]<<SET title=""></SET>
prior to
// Save the pointer to the results in the Fitmod list
Insert Into( Fitmod, Fm );
它会将标题更改为您想要的值
回复:报告 LSMeans 差异学生的 t 数据亲爱的吉姆,
非常感谢您的帮助!我真的很感激,这对我而言也是一次巨大的学习。该脚本现已完全可用,并且可以与许多数据集一起使用。
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据亲爱的吉姆,
我一直在使用脚本,然后我注意到,当我打印数据时,参数列表并没有给我所有不同的测试值参数,而只提供了测试值 1:

我意识到这是来自脚本的以下部分:
// Get the Response variable name
Insert Into( testValue, (Substr( (reportFitmod << topparent)[Outline Box( 1 )] << get title, 10 )) );
我曾尝试改变它,但它要么仍然只打印单个参数,要么给出错误,要么打印一些我不知道来自哪里的东西。
此致,
朱莉
回复:报告 LSMeans 差异学生的 t 数据我无法再重建您正在使用的完整脚本。请附上您正在使用的完整脚本。
回复:报告 LSMeans 差异学生的 t 数据嗨吉姆,
我已附加工作数据表和脚本。
巴西/
朱莉
回复:报告 LSMeans 差异学生的 t 数据我采取了捷径来解决这个问题。我添加了一个名为“titles”的 JMP 列表,该列表在每次运行后以及在设置 Outline Box() 标题后立即填充。然后我只使用 dlg 部分中 Table Box() 中的标题列表。

Names Default To Here( 1 ); // will ignore normal JSL naming
sd = currentdatatable(); // call upon open data table
// Define that Fitmod is empty. We will fill this with our information in the loop
Fitmod = {};
// Determine the levels in the ID column
summarize( sd, ByGroups = By( :Batch ) );
// Determine the result columns
colList = sd << Get Column Names( Continuous, String );
sum = 0; // Prepare getting the total number of result columns. Will be updated in the loop
titles = {};
// Loop across each level of Batch
nw_means = New Window("My Report",
For( i = 1, i <= Nitems( colList ), i++,
For Each( {BG, group}, ByGroups,
Fm = Fit Model(
Y( colList[i] ),
Effects( :Laboratory ),
Random Effects( :Day[:Laboratory] ),
NoBounds( 0 ),
Personality( "Standard Least Squares" ),
Method( "REML" ),
Emphasis( "Effect Leverage" ),
Run(
colList[i] << {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( :Batch == ByGroups[group] ),
SendToReport(
Dispatch( {"" }, "Whole Model", OutlineBox, {Close( 1 )} ),
Dispatch(
{"", "Laboratory"},
"Leverage Plot",
OutlineBox,
{Close( 1 )}
)
)
);
report(fm)[OutlineBox(1)] << set title(report(fm)[OutlineBox(1)] << get title || ", ID=" || BG);
// Save the pointer to the results in the Fitmod list
Insert Into( Fitmod, Fm );
insert into(titles, report(fm)[OutlineBox(1)] << get title);
);
sum = sum + 1
);
);
// 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( crossTab[1, 2] , 4 );
lowerCL = Round( crossTab[3, 2] , 3 );
upperCL = Round( crossTab[4, 2] , 3 );
// Get the Response variable name
Insert Into( testValue, (Substr( (reportFitmod << topparent)[Outline Box( 1 )] << get title, 10 )) );
// Create the Difference 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( "Paramenter", titles ),
String Col Box( whereCol, repeat(ByGroups, sum) ),
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 );
回复:报告 LSMeans 差异学生的 t 数据完美!谢谢