這是一種方法:
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];
);