cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-502469%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3EAdd%20possibility%20to%20round%20to%20even%20(banker's%20rounding)%20(or%20at%20least%20add%20teaching%20script%20to%20demonstrate%20the%20effect)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-502469%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3EAdd%20function%20to%20round%20to%20even%20%2F%20preference%20to%20change%20default%20rounding%20used%20by%20JMP%20(to%20my%20understanding%20both%20%3CA%20href%3D%22https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Ffunctions.html%23round%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EPython%3C%2FA%3E%26nbsp%3Band%20%3CA%20href%3D%22https%3A%2F%2Fsearch.r-project.org%2FR%2Frefmans%2Fbase%2Fhtml%2FRound.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ER%3C%2FA%3E%26nbsp%3Bfollow%20IEEE%20754%20and%20round%20to%20even%20by%20default).%20Also%20add%20Teaching%20Script%20to%20demonstrate%20the%20effect%20of%20rounding%20to%20even%20vs%20rounding%20to%20nearest.%20To%20my%20understanding%20round-to-even%20is%20the%20default%20behaviour%20for%20example%20in%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIEEE_754%23Rounding_rules%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EIEEE%20754%20-%20Rounding%20Rules%20(wikipedia.org)%3C%2FA%3E%26nbsp%3B%20Rounding%20to%20nearest%20should%20reduce%20bias%20when%20calculating%20aggregated%20statistics%20such%20as%20sum%20and%20mean%20from%20rounded%20values.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBelow%20is%20example%20script%20(might%20not%20be%20the%20best%20demonstration...)%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%2F%2F%20https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIEEE_754%23Rounding_rules%0A%2F%2F%20https%3A%2F%2Fblogs.sas.com%2Fcontent%2Fiml%2F2019%2F11%2F11%2Fround-to-even.html%0A%2F%2F%20https%3A%2F%2Fstackoverflow.com%2Fquestions%2F311696%2Fwhy-does-net-use-bankers-rounding-as-default%0A%0Arow_count%20%3D%20400%3B%0Adt%20%3D%20New%20Table(%22Bankers_demo%22%2C%20Add%20Rows(row_count)%2C%20New%20Column(%22TrueValue%22%2C%20Numeric%2C%20Continuous%2C%20Formula(0.25%20*%20(Row()%20-%20100))))%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22RoundToNearest%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Round(%3ATrueValue%2C%200)))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22RoundToEven%22%2C%0A%09Numeric%2C%0A%09Continuous%2C%0A%09Formula(%0A%09%09l%20%3D%20Words(Char(%3ATrueValue)%2C%20%22.%22)%3B%0A%09%09If(N%20Items(l)%20%3D%3D%201%2C%0A%09%09%09%3ATrueValue%2C%0A%09%09%09If(l%5B2%5D%20%3D%3D%20%225%22%2C%0A%09%09%09%09If(Modulo(Num(l%5B1%5D)%2C%202)%2C%0A%09%09%09%09%09Ceiling(%3ATrueValue)%2C%0A%09%09%09%09%09Floor(%3ATrueValue)%0A%09%09%09%09)%2C%0A%09%09%09%09Round(%3ATrueValue%2C%200)%0A%09%09%09)%0A%09%09)%3B%0A%09)%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22TrueSum%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Col%20Cumulative%20Sum(%3ATrueValue)))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22NearestSum%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Col%20Cumulative%20Sum(%3ARoundToNearest)))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22EvenSum%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Col%20Cumulative%20Sum(%3ARoundToEven)))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22ErrorNearest%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Abs(%3ATrueSum%20-%20%3ANearestSum)))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22ErrorEven%22%2C%20Numeric%2C%20Continuous%2C%20Formula(Abs(%3ATrueSum%20-%20%3AEvenSum)))%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22TrueAvg%22%2C%20Numeric%2C%20Continuous%2C%20Formula(%3ATrueSum%20%2F%20Row()))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22NearestAvg%22%2C%20Numeric%2C%20Continuous%2C%20Formula(%3ANearestSum%20%2F%20Row()))%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22EvenAvg%22%2C%20Numeric%2C%20Continuous%2C%20Formula(%3AEvenSum%20%2F%20Row()))%3B%0A%0A%0Anw%20%3D%20New%20Window(%22Rounding%22%2C%0A%09H%20List%20Box(%0A%09%09Panel%20Box(%22Actions%22%2C%0A%09%09%09Button%20Box(%22Add%20Row%22%2C%20dt%20%26lt%3B%26lt%3B%20Add%20Rows(1%2C%20At%20End))%2C%0A%09%09%09Button%20Box(%22Add%2010%20Rows%22%2C%20dt%20%26lt%3B%26lt%3B%20Add%20Rows(10%2C%20At%20End))%2C%0A%09%09%09Button%20Box(%22Add%20100%20Rows%22%2C%20dt%20%26lt%3B%26lt%3B%20Add%20Rows(100%2C%20At%20End))%2C%0A%09%09%09Button%20Box(%22Add%201000%20Rows%22%2C%20dt%20%26lt%3B%26lt%3B%20Add%20Rows(1000%2C%20At%20End))%0A%09%09)%2C%0A%09%09gb%20%3D%20dt%20%26lt%3B%26lt%3B%20Graph%20Builder(%0A%09%09%09Size(528%2C%20456)%2C%0A%09%09%09Show%20Control%20Panel(0)%2C%0A%09%09%09Variables(X(%3ATrueValue)%2C%20Y(%3AErrorNearest%2C%20Position(1))%2C%20Y(%3AErrorEven%2C%20Position(1)))%2C%0A%09%09%09Elements(Points(X%2C%20Y(1)%2C%20Y(2)%2C%20Y(3)%2C%20Legend(3))%2C%20Line(X%2C%20Y(1)%2C%20Y(2)%2C%20Y(3)%2C%20Legend(5)))%2C%0A%09%09%09Local%20Data%20Filter(Add%20Filter(columns(%3ATrueValue)))%2C%0A%09%09%09SendToReport(%0A%09%09%09%09Dispatch(%0A%09%09%09%09%09%7B%7D%2C%0A%09%09%09%09%09%22400%22%2C%0A%09%09%09%09%09ScaleBox%2C%0A%09%09%09%09%09%7BLegend%20Model(%0A%09%09%09%09%09%093%2C%0A%09%09%09%09%09%09Base(0%2C%200%2C%200%2C%20Item%20ID(%22TrueSum%22%2C%201))%2C%0A%09%09%09%09%09%09Base(1%2C%200%2C%200%2C%20Item%20ID(%22NearestSum%22%2C%201))%2C%0A%09%09%09%09%09%09Base(2%2C%200%2C%200%2C%20Item%20ID(%22EvenSum%22%2C%201))%0A%09%09%09%09%09)%7D%0A%09%09%09%09)%0A%09%09%09)%0A%09%09)%2C%0A%09%09Tabulate(%0A%09%09%09Show%20Control%20Panel(0)%2C%0A%09%09%09Add%20Table(Column%20Table(Statistics(Sum%2C%20Mean))%2C%20Row%20Table(Analysis%20Columns(%3ATrueValue%2C%20%3ARoundToNearest%2C%20%3ARoundToEven)))%0A%09%09)%0A%09)%2C%0A%09%26lt%3B%26lt%3B%20On%20Close(Try(Close(dt%2C%20No%20Save)))%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-502469%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3EAutomation%20and%20Scripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-510003%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Add%20possibility%20to%20round%20to%20even%20(banker's%20rounding)%20(or%20at%20least%20add%20teaching%20script%20to%20demonstrate%20the%20effect)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-510003%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EThanks%20for%20the%20detailed%20description.%26nbsp%3B%20We%20may%20take%20this%20under%20consideration%20for%20a%20future%20release.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
0 Kudos

Add possibility to round to even (banker's rounding) (or at least add teaching script to demonstrate the effect)

Add function to round to even / preference to change default rounding used by JMP (to my understanding both Python and R follow IEEE 754 and round to even by default). Also add Teaching Script to demonstrate the effect of rounding to even vs rounding to nearest. To my understanding round-to-even is the default behaviour for example in IEEE 754 - Rounding Rules (wikipedia.org)  Rounding to nearest should reduce bias when calculating aggregated statistics such as sum and mean from rounded values.

 

Below is example script (might not be the best demonstration...):

Names Default To Here(1);
// https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules
// https://blogs.sas.com/content/iml/2019/11/11/round-to-even.html
// https://stackoverflow.com/questions/311696/why-does-net-use-bankers-rounding-as-default

row_count = 400;
dt = New Table("Bankers_demo", Add Rows(row_count), New Column("TrueValue", Numeric, Continuous, Formula(0.25 * (Row() - 100))));

dt << New Column("RoundToNearest", Numeric, Continuous, Formula(Round(:TrueValue, 0)));
dt << New Column("RoundToEven",
	Numeric,
	Continuous,
	Formula(
		l = Words(Char(:TrueValue), ".");
		If(N Items(l) == 1,
			:TrueValue,
			If(l[2] == "5",
				If(Modulo(Num(l[1]), 2),
					Ceiling(:TrueValue),
					Floor(:TrueValue)
				),
				Round(:TrueValue, 0)
			)
		);
	)
);

dt << New Column("TrueSum", Numeric, Continuous, Formula(Col Cumulative Sum(:TrueValue)));
dt << New Column("NearestSum", Numeric, Continuous, Formula(Col Cumulative Sum(:RoundToNearest)));
dt << New Column("EvenSum", Numeric, Continuous, Formula(Col Cumulative Sum(:RoundToEven)));
dt << New Column("ErrorNearest", Numeric, Continuous, Formula(Abs(:TrueSum - :NearestSum)));
dt << New Column("ErrorEven", Numeric, Continuous, Formula(Abs(:TrueSum - :EvenSum)));

dt << New Column("TrueAvg", Numeric, Continuous, Formula(:TrueSum / Row()));
dt << New Column("NearestAvg", Numeric, Continuous, Formula(:NearestSum / Row()));
dt << New Column("EvenAvg", Numeric, Continuous, Formula(:EvenSum / Row()));


nw = New Window("Rounding",
	H List Box(
		Panel Box("Actions",
			Button Box("Add Row", dt << Add Rows(1, At End)),
			Button Box("Add 10 Rows", dt << Add Rows(10, At End)),
			Button Box("Add 100 Rows", dt << Add Rows(100, At End)),
			Button Box("Add 1000 Rows", dt << Add Rows(1000, At End))
		),
		gb = dt << Graph Builder(
			Size(528, 456),
			Show Control Panel(0),
			Variables(X(:TrueValue), Y(:ErrorNearest, Position(1)), Y(:ErrorEven, Position(1))),
			Elements(Points(X, Y(1), Y(2), Y(3), Legend(3)), Line(X, Y(1), Y(2), Y(3), Legend(5))),
			Local Data Filter(Add Filter(columns(:TrueValue))),
			SendToReport(
				Dispatch(
					{},
					"400",
					ScaleBox,
					{Legend Model(
						3,
						Base(0, 0, 0, Item ID("TrueSum", 1)),
						Base(1, 0, 0, Item ID("NearestSum", 1)),
						Base(2, 0, 0, Item ID("EvenSum", 1))
					)}
				)
			)
		),
		Tabulate(
			Show Control Panel(0),
			Add Table(Column Table(Statistics(Sum, Mean)), Row Table(Analysis Columns(:TrueValue, :RoundToNearest, :RoundToEven)))
		)
	),
	<< On Close(Try(Close(dt, No Save)))
);

 

 

1 Comment
SamGardner
Level VII

Thanks for the detailed description.  We may take this under consideration for a future release.