Choose Language Hide Translation Bar
tmj
tmj
New Contributor

Number of items in a report

Hello....wondering if someone can explain the following discrepancy with the number of items in a report. I have the following code which is trying to extract the intercept and slope out of a linear fit that has been applied to a Fit Y by X platform. The issue I see is if the :group column contains just one item then the numplots = 2, and I get an error trying to extract the intercept and slope from rp[1]. I have to extract from rp[2]. If the number of items in the :group column = 2 or higher then numplots = the number of items in the group column and I can extract intercept and slope from rp[1]. In the end, I want to be able to extract all intercepts and slopes for x number of groups where x can be anything from 1 to whatever, but this "feature" makes coding a bit more long winded because I have to treat # groups = 1 different than # 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];

 

 

thanks

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Number of items in a report

When you use a By() in a platform call if there is more than one group the result will be a list of the platforms.

 

Consider the following:

 

 

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 );

The log will show:

/*:

bivobj1 = {Bivariate[], Bivariate[]};
bivobj2 = Bivariate[];

So, you can check your bivObj variable to see if it's a list and act accordingly. For example:

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];

);

 

-Jeff

View solution in original post

0 Kudos
2 REPLIES 2

Re: Number of items in a report

Here is one approach:

 

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 );
Learn it once, use it forever!
Jeff_Perkinson
Community Manager Community Manager

Re: Number of items in a report

When you use a By() in a platform call if there is more than one group the result will be a list of the platforms.

 

Consider the following:

 

 

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 );

The log will show:

/*:

bivobj1 = {Bivariate[], Bivariate[]};
bivobj2 = Bivariate[];

So, you can check your bivObj variable to see if it's a list and act accordingly. For example:

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];

);

 

-Jeff

View solution in original post

0 Kudos