Ecco un approccio:
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 );
Ciao .... mi chiedo se qualcuno può spiegare la seguente discrepanza con il numero di elementi in un rapporto. Ho il seguente codice che sta tentando di estrarre l'intercetta e di inclinarsi fuori da un adattamento lineare che è stato applicato a una piattaforma Fit Y di X. Il problema che vedo è se la colonna: group contiene solo un elemento poi i numplots = 2, e ottengo un errore nel tentativo di estrarre l'intercetta e la pendenza da rp [1]. Devo estrarre da rp [2]. Se il numero di elementi nella colonna: gruppo = 2 o superiore, numplots = il numero di elementi nella colonna del gruppo e I può estrarre intercetta e pendenza da rp [1]. Alla fine, voglio essere in grado di estrarre tutte le intercettazioni e le pendenze per il numero x di gruppi in cui x può essere qualsiasi cosa da 1 a qualsiasi, ma questa "caratteristica" rende la codifica un po 'più lunga perché devo trattare # gruppi = 1 diverso da # gruppi> = 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];
Grazie
Quando si utilizza un By () in una chiamata alla piattaforma se c'è più di un gruppo, il risultato sarà un elenco delle piattaforme.
Considera quanto segue:
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 );
Il registro mostrerà:
/*:
bivobj1 = {Bivariate[], Bivariate[]};
bivobj2 = Bivariate[];
Quindi, puoi controllare la tua variabile bivObj per vedere se si tratta di una lista e agire di conseguenza. Per esempio:
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];
);