|
From: <ap...@us...> - 2026-05-09 22:17:08
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Maxima CAS".
The branch, master has been updated
via 328c0e8044a1bb7c711974f642be40d304a19169 (commit)
from 0f50f41faa28c4d8bc52423acdca64b7760c275e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 328c0e8044a1bb7c711974f642be40d304a19169
Author: Robert Dodier <rob...@so...>
Date: Sat May 9 15:14:16 2026 -0700
histogram: correct bar height calculation for frequency = density,
and scale bars by M/N where M is the number of data covered by bins
and N is the total number of data, for frequency = relative and frequency = percent.
Update the English-language documentation and put in a new example in rtest_statgraph.mac.
diff --git a/doc/info/descriptive.texi b/doc/info/descriptive.texi
index 6254264d9..aeb36572a 100644
--- a/doc/info/descriptive.texi
+++ b/doc/info/descriptive.texi
@@ -3364,10 +3364,30 @@ That is, the right endpoint of one interval is equal to the left endpoint of the
@item
@code{frequency} (default, @code{absolute}): indicates the scale of the vertical axis.
-Possible values are: @code{absolute} (heights of bars add up to number of data),
-@code{relative} (heights of bars add up to 1),
-@code{percent} (heights of bars add up to 100),
-and @code{density} (total area of histogram is 1).
+In the following, let @math{M} be the number of data which fall into the bins specified by @code{nclasses},
+and let @math{N} be the total number of data.
+(When all data are covered by @code{nclasses}, @math{M} is equal to @math{N}.)
+Let @math{m[k]} be the number of data falling into the @math{k}'th bin,
+and let @math{w[k]} be the width of the @math{k}'th bin.
+Then the possible values of @code{frequency} are as follows.
+
+@itemize @bullet
+@item
+@code{absolute} Height of each bar is equal to @math{m[k]},
+ and the sum of all heights is @math{M}.
+
+@item
+@code{relative} Height of each bar is equal to @math{m[k]/N},
+ and the sum of all heights is @math{M/N}.
+
+@item
+@code{percent} Height of each bar is equal to 100 times @math{m[k]/N},
+ and the sum of all heights is 100 times @math{M/N}.
+
+@item
+@code{density} Height of each bar is equal to @math{m[k]/N/w[k]},
+ and the sum of all bar areas (width times height) is equal to @math{M/N}.
+@end itemize
@item
@code{htics} (default, @code{auto}): format of tic marks on the horizontal axis.
diff --git a/share/descriptive/descriptive.mac b/share/descriptive/descriptive.mac
index df5d74ea2..9e03e43b7 100644
--- a/share/descriptive/descriptive.mac
+++ b/share/descriptive/descriptive.mac
@@ -960,7 +960,7 @@ make_skyline (xx, yy, fill_color, fill_density) :=
'points (skyline_points)]);
histogram_description(m,[select]):=
- block([fr,amp,scen,before,localopts,num_classes,v,lbels, my_fill_color, my_fill_density,
+ block([n_data,fr,amp,scen,before,localopts,num_classes,v,lbels, my_fill_color, my_fill_density,
/* specific options */
my_nclasses:10, my_frequency:'absolute, my_htics:'auto, histogram_bars, histogram_drawing],
[before, localopts]: extract_options (select, 'nclasses, 'frequency, 'htics, 'fill_color, 'fill_density),
@@ -1039,13 +1039,15 @@ histogram_description(m,[select]):=
then my_nclasses: num_classes:
ceiling(1 + log(length(m)) / 0.6931471805599453), /* <-- log(2) */
fr: float(continuous_freq(m,my_nclasses)),
+ n_data: length (m),
if member(my_frequency, ['relative, 'percent])
- then fr: [first(fr), second(fr) / apply("+", second(fr))],
+ then fr: [first(fr), second(fr) / n_data],
if my_frequency = 'percent
then fr[2]: fr[2] * 100.0,
amp: makelist(fr[1][i+1]-fr[1][i], i, 1, length(fr[1])-1),
if my_frequency = 'density
- then fr: [first(fr), second(fr) / apply("+", second(fr) * amp)],
+ then block ([listarith: true],
+ fr: [first(fr), second(fr) / n_data / amp]),
/* histogram tics */
if my_htics = 'auto
diff --git a/share/descriptive/rtest_statgraph.mac b/share/descriptive/rtest_statgraph.mac
index bef784707..77168fcad 100644
--- a/share/descriptive/rtest_statgraph.mac
+++ b/share/descriptive/rtest_statgraph.mac
@@ -32,7 +32,8 @@
"boxplot: Windspeed in knots from wind.data",
"boxplot: Horizontal boxes",
"histogram: pi digits from pidigits.data",
- "histogram + explicit: Random data from normal distribution",
+ "histogram + explicit: Random data from normal distribution, uniform bins",
+ "histogram + explicit: Random data from normal distribution, nonuniform bins",
"piechart: Digit frequencies in pi from pidigits.data",
"scatterplot: 1-dimensional random data",
"starplot: Two random samples"
@@ -130,13 +131,26 @@ block([m: 14, s: 2, s2],
s2: random_normal(m, s, 1000),
draw2d(
grid = true,
- xrange = [5, 25],
- title = title_cache ["histogram + explicit: Random data from normal distribution"],
+ title = title_cache ["histogram + explicit: Random data from normal distribution, uniform bins"],
histogram_description(
s2,
nclasses = 9,
frequency = density,
fill_density = 0.5),
+ xrange = [5, 25],
+ explicit(pdf_normal(x,m,s), x, m - 3*s, m + 3* s)));
+
+block([m: 14, s: 2, s2],
+ s2: random_normal(m, s, 1000),
+ draw2d(
+ grid = true,
+ title = title_cache ["histogram + explicit: Random data from normal distribution, nonuniform bins"],
+ histogram_description(
+ s2,
+ nclasses = setify (makelist (float (quantile_normal (k/13, m, s)), k, 1, 12)),
+ frequency = density,
+ fill_density = 0.5),
+ xrange = [5, 25],
explicit(pdf_normal(x,m,s), x, m - 3*s, m + 3* s)));
piechart(
-----------------------------------------------------------------------
Summary of changes:
doc/info/descriptive.texi | 28 ++++++++++++++++++++++++----
share/descriptive/descriptive.mac | 8 +++++---
share/descriptive/rtest_statgraph.mac | 20 +++++++++++++++++---
3 files changed, 46 insertions(+), 10 deletions(-)
hooks/post-receive
--
Maxima CAS
|