这是一种方法:
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Summarize( g = By( :sex ) );
If( N Items( g ) < 2,
biv obj = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );
biv rep = biv obj << Report;
reg est = biv rep["Parameter Estimates"][NumberColBox(1)] << Get As Matrix,
// need By variable
biv obj = dt << Bivariate( Y( :weight ), X( :height ), By( :sex ), Fit Line );
biv rep = biv obj << Report;
reg est = [];
For( by = 1, by <= N Items( g ), by++,
reg est ||= (biv rep[by])["Parameter Estimates"][NumberColBox(1)] << Get As Matrix;
);
);
Show( reg est );
您好....想知道是否有人可以解释以下与报告中的项目数量的差异。我有以下代码试图从X平台应用于Fit Y的线性拟合中提取截距和斜率。我看到的问题是:如果:group列只包含一个项目,那么numplots = 2,并且我在尝试从rp [1]中提取截距和斜率时出错。我必须从rp中提取[2]。如果:group列中的项目数= 2或更高,则numplots =组列中的项目数,我可以从rp [1]中提取截距和斜率。最后,我希望能够提取x个组中的所有截距和斜率,其中x可以是从1到任意的任何东西,但是这个“特征”使编码更加冗长,因为我必须对待#groups = 1#与#goups> = 2不同。
Clear Globals();
dt = Current Data Table();
bivObj = dt << Bivariate(
Y(:this),
X(:that),
Fit Line,
By(:group),
);
rp = bivObj << Report;
numPlots = nItems(rp1);
intercept = rp[1][OutlineBox("Parameter Estimates")][Columnbox("Estimate")][1];
slope = rp[1][OutlineBox("Parameter Estimates")][Columnbox("Estimate")][1];
谢谢
如果在平台调用中使用By(),如果有多个组,则结果将是平台列表。
考虑以下:
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
dt <<
New Column( "Constant",
character,
formula( "a" )
);
bivObj1 = dt <<
Bivariate(
Y( :height ),
X( :weight ),
Fit Line,
By( :sex ),
);
bivObj2 = dt <<
Bivariate(
Y( :height ),
X( :weight ),
Fit Line,
By( :constant ),
);
Show( bivobj1, bivobj2 );
日志将显示:
/*:
bivobj1 = {Bivariate[], Bivariate[]};
bivobj2 = Bivariate[];
因此,您可以检查bivObj变量以查看它是否为列表并采取相应措施。例如:
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
dt << New Column( "Constant", character, formula( "a" ) );
bivObj1 = dt << Bivariate(
Y( :height ),
X( :weight ),
Fit Line,
By( :sex ),
);
bivObj2 = dt << Bivariate(
Y( :height ),
X( :weight ),
Fit Line,
By( :constant ),
);
Show( bivobj1, bivobj2 );
If( Is List( bivobj1 ),
//bivobj1 is a list of platform references
For( i = 1, i <= N Items( bivobj1 ), i++,
rp = bivObj1[i] << Report;
intercept = rp[Outline Box( "Parameter Estimates" )][Columnbox( "Estimate" )][1];
slope = rp[Outline Box( "Parameter Estimates" )][Columnbox( "Estimate" )][1];
Show( intercept, slope );
)
,
//bivobj1 is not a list, it's a single platform reference
rp = bivObj1 << Report;
intercept = rp[Outline Box( "Parameter Estimates" )][Columnbox( "Estimate" )][1];
slope = rp[Outline Box( "Parameter Estimates" )][Columnbox( "Estimate" )][1];
);