| Type: | Package |
| Title: | Histogram-Valued Data Analysis |
| Version: | 1.0.9 |
| Date: | 2026-10-16 |
| Maintainer: | Antonio Irpino <antonio.irpino@unicampania.it> |
| Description: | In the framework of Symbolic Data Analysis, a relatively new approach to the statistical analysis of multi-valued data, we consider histogram-valued data, i.e., data described by univariate histograms. The methods and the basic statistics for histogram-valued data are mainly based on the L2 Wasserstein metric between distributions, i.e., the Euclidean metric between quantile functions. The package contains unsupervised classification techniques, least square regression and tools for histogram-valued data and for histogram time series. An introducing paper is Irpino A. Verde R. (2015) <doi:10.1007/s11634-014-0176-4>. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| Imports: | graphics, class, FactoMineR, ggplot2 (≥ 3.4.0), ggridges, grid, histogram, grDevices, stats, utils, Rcpp |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| URL: | https://github.com/Airpino/HistDAWass |
| BugReports: | https://github.com/Airpino/HistDAWass/issues |
| Depends: | R(≥ 3.1), methods |
| LazyData: | true |
| Collate: | 'For_Rccp_int.R' 'All_classes.R' 'RcppExports.R' 'Utility.R' 'Met_HTS.R' 'Met_MatH.R' 'Met_distributionH.R' 'Fuzzy_cmeans.R' 'H_time_series.R' 'HistDAWass-package.R' 'Kohonen_maps.R' 'principal_components.R' 'regression.R' 'unsuperv_classification.R' 'Plotting_with_ggplot.R' |
| Encoding: | UTF-8 |
| NeedsCompilation: | yes |
| LinkingTo: | Rcpp,RcppArmadillo |
| Config/roxygen2/version: | 8.1.0 |
| Packaged: | 2026-10-16 14:51:34 UTC; root |
| Author: | Antonio Irpino |
| Repository: | CRAN |
| Date/Publication: | 2026-10-18 19:20:02 UTC |
HistDAWass: Histogram-Valued Data Analysis
Description
Methods for the analysis of histogram-valued data, i.e. data described by univariate histograms, in the framework of Symbolic Data Analysis. The basic statistics and the methods are based on the L2 Wasserstein metric between distributions, i.e. the Euclidean metric between quantile functions.
Data structures
-
distributionH: a histogram;data2histbuilds one from raw data. -
MatH: a matrix of histograms (individuals by histogram-valued variables). -
HTS-class: a histogram time series.
Basic statistics
Moments of a histogram (meanH, stdH,
skewH, kurtH), quantiles and cdf
(compQ, compP), the L2 Wasserstein distance
(WassSqDistH, WH_MAT_DIST), the mean histogram
(WH.vec.mean), variance-covariance and correlation matrices
(WH.var.covar).
Methods
Clustering:
WH_kmeans,WH_adaptive.kmeans,WH_fcmeans,WH_adaptive_fcmeans,WH_hclust, Kohonen maps (WH_2d_Kohonen_maps,WH_2d_Adaptive_Kohonen_maps).Principal component analysis:
WH.1d.PCA,WH.MultiplePCA.Regression:
WH.regression.two.components.Histogram time series:
HTS.moving.averages,HTS.exponential.smoothing,HTS.predict.knn.
Author(s)
Maintainer: Antonio Irpino antonio.irpino@unicampania.it (ORCID)
Authors:
Antonio Irpino antonio.irpino@unicampania.it (ORCID)
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
See Also
Useful links:
Examples
# a matrix of four histograms (2 individuals x 2 variables)
a <- list(
distributionH(x = c(80, 100, 120, 135, 150, 165, 180, 200, 240),
p = c(0, 0.025, 0.1, 0.275, 0.525, 0.725, 0.887, 0.975, 1)),
distributionH(x = c(80, 100, 120, 135, 150, 165, 180, 195, 210, 240),
p = c(0, 0.013, 0.101, 0.255, 0.508, 0.718, 0.895, 0.961, 0.987, 1)),
distributionH(x = c(95, 110, 125, 140, 155, 170, 185, 200, 215, 230, 245),
p = c(0, 0.012, 0.041, 0.154, 0.36, 0.595, 0.781, 0.929, 0.972, 0.992, 1)),
distributionH(x = c(105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 260),
p = c(0, 0.009, 0.035, 0.081, 0.186, 0.385, 0.633, 0.832, 0.932, 0.977, 1))
)
M <- MatH(x = a, nrows = 2, ncols = 2,
rownames = c("u1", "u2"), varnames = c("Var_1", "Var_2"))
M
WH.vec.mean(M)
Age pyramids of the countries of the World in 2014
Description
Distributions of the population by 5-year age classes (relative frequencies) for 228 countries and the World (first row): whole population, male and female population.
Format
A MatH object with 229 rows (the World and 228 countries) and 3 columns:
Both.Sexes.Population, Male.Population, Female.Population.
Source
United States Census Bureau, https://www.census.gov/data.html
Examples
get.MatH.main.info(Age_Pyramids_2014)
Agronomique data
Description
Distributions of the marginal costs of farms in 22 French regions.
Format
A MatH object with 22 rows (regions) and 4 columns: Y_TSC (total costs of a
farm), X_Wheat (costs for wheat), X_Pig (costs for pigs),
X_Cmilk (costs for cow milk).
Source
Verde, R., Irpino, A., Desbois, D. (2014). How to cope with modelling and privacy concerns? A regression model and a visualization tool for aggregated data, Conference of European Statistics Stakeholders, Rome.
Examples
Agronomique
Arithmetic operators for histograms
Description
Sum, difference and product of distributionH objects and numbers,
consistent with the L2 Wasserstein metric: the operations are applied to the
quantile functions of the distributions.
-
e1 + e2: the sum of the quantile functions. A number is treated as an impulse distribution, sox + ashiftsxbya. -
e1 - e2: the difference of the quantile functions. The difference of two distributions is a distribution only ife1is more variable thane2(the result must be a non-decreasing quantile function); otherwise it may not be valid.x - ashiftsxby-a. -
a * xorx * a: the product of a distribution and a number, i.e. a rescaling ofx.
Usage
## S4 method for signature 'distributionH,distributionH'
e1 + e2
## S4 method for signature 'distributionH,distributionH'
e1 - e2
## S4 method for signature 'distributionH,distributionH'
e1 * e2
Arguments
e1, e2 |
Two |
Value
A distributionH object.
Examples
d1 <- distributionH(x = c(1, 2, 3), p = c(0, 0.4, 1))
d2 <- distributionH(x = c(7, 8, 10, 15), p = c(0, 0.2, 0.7, 1))
d1 + d2
d2 + 10
2 * d1
d2 - d1
Blood data
Description
Histograms of cholesterol, hemoglobin and hematocrit for 14 groups of patients (by sex and age).
Format
A MatH object with 14 rows (groups of patients) and 3 columns (variables).
Source
Billard L. and Diday E. (2006). Symbolic Data Analysis: Conceptual Statistics and Data Mining, Wiley.
Examples
BLOOD
plot(BLOOD)
Blood data from Brito
Description
Histograms of hematocrit and hemoglobin for 10 patients.
Format
A MatH object with 10 rows (patients) and 2 columns (variables).
Source
Dias, S. and Brito P. (2013). Distribution and Symmetric Distribution Regression Model for Histogram-Valued Variables, arXiv:1303.6199.
Examples
BloodBRITO
Centre the histograms of a matrix
Description
Shifts each histogram of a MatH object so that its mean is zero.
Usage
Center.cell.MatH(object)
Arguments
object |
A |
Value
A MatH object whose histograms have zero mean.
Examples
CEN_BLOOD <- Center.cell.MatH(BLOOD)
get.MatH.stats(CEN_BLOOD, stat = "mean")
Monthly climatic data of China
Description
Distributions of 14 climatic variables observed in 60 stations of China in each month (168 histogram-valued variables).
Format
A MatH object with 60 rows (stations) and 168 columns (14 variables x 12 months).
Details
The 14 variables are: mean station pressure (mb), mean temperature, mean
maximum temperature, mean minimum temperature, total precipitation (mm),
sunshine duration (h), mean cloud amount (percentage of sky cover), mean
relative humidity (%), snow days (days with snow cover), dominant wind
direction (degrees), mean wind speed (m/s), dominant wind frequency (%),
extreme maximum temperature (C), extreme minimum temperature (C). The
coordinates of the stations are in stations_coordinates.
Source
Climate Data Bases of the People's Republic of China 1841-1988 (TR055), doi:10.3334/CDIAC/cli.tr055
Examples
get.MatH.main.info(China_Month)$ncols
Seasonal climatic data of China
Description
Distributions of 14 climatic variables observed in 60 stations of China in each season (56 histogram-valued variables).
Format
A MatH object with 60 rows (stations) and 56 columns (14 variables x 4 seasons).
Details
The 14 variables are: mean station pressure (mb), mean temperature, mean
maximum temperature, mean minimum temperature, total precipitation (mm),
sunshine duration (h), mean cloud amount (percentage of sky cover), mean
relative humidity (%), snow days (days with snow cover), dominant wind
direction (degrees), mean wind speed (m/s), dominant wind frequency (%),
extreme maximum temperature (C), extreme minimum temperature (C). The
coordinates of the stations are in stations_coordinates.
Source
Climate Data Bases of the People's Republic of China 1841-1988 (TR055), doi:10.3334/CDIAC/cli.tr055
Examples
get.MatH.main.info(China_Seas)$ncols
Ramer-Douglas-Peucker algorithm
Description
Approximates a curve, given by a sequence of 2d points, with a polyline
(Ramer-Douglas-Peucker algorithm). It is used by data2hist with
algo = "PolyLine".
Usage
DouglasPeucker(points, epsilon)
Arguments
points |
A two-column matrix with the coordinates of the points. |
epsilon |
A positive number, the tolerance of the approximation (recommended 0.01). |
Value
A two-column matrix with the vertices of the polyline.
See Also
Examples
x <- seq(0, 1, length.out = 50)
DouglasPeucker(cbind(x, x^2), epsilon = 0.01)
Histogram time series: the HTS class
Description
The HTS class describes a histogram time series, i.e. a sequence of
histograms (TdistributionH objects) observed along time.
Slots
dataA list of
TdistributionHobjects.
Creating objects
Objects are created with new("HTS", epocs, ListOfTimedElements), where
epocs is the number of time points and ListOfTimedElements a
list of TdistributionH objects.
See Also
RetHTS for an example dataset;
subsetHTS, plot,HTS-method,
HTS.moving.averages, HTS.exponential.smoothing,
HTS.predict.knn.
Examples
RetHTS
subsetHTS(RetHTS, from = 1, to = 5)
Exponential smoothing of a histogram time series
Description
(Beta version) Exponential smoothing of a histogram time series, based on the L2 Wasserstein distance.
Usage
HTS.exponential.smoothing(HTS, alpha = 0.9)
Arguments
HTS |
A |
alpha |
A number between 0 and 1, the smoothing parameter (default 0.9). |
Value
A list with smoothing.alpha, the smoothing parameter, and
SmoothedHTS, the smoothed HTS object.
See Also
Examples
mov.expo.smooth <- HTS.exponential.smoothing(HTS = RetHTS, alpha = 0.8)
mov.expo.smooth$SmoothedHTS
Moving averages of a histogram time series
Description
(Beta version) Smoothing of a histogram time series by (weighted) moving averages, based on the L2 Wasserstein distance.
Usage
HTS.moving.averages(HTS, k = 3, weights = rep(1, k))
Arguments
HTS |
A |
k |
An odd integer, the number of elements of each average (default 3). |
weights |
A vector of |
Value
A list with k, the (normalised) weights and
AveragedHTS, the smoothed HTS object.
See Also
Examples
mov.av.smoothed <- HTS.moving.averages(HTS = RetHTS, k = 5)
mov.av.smoothed$AveragedHTS
K-NN forecast of a histogram time series
Description
(Beta version) Forecasts a histogram of a time series with the k-nearest
neighbours method, based on the L2 Wasserstein distance: the forecast is the
mean of the histograms following the k histograms most similar to the
one at position.
Usage
HTS.predict.knn(HTS, position = length(HTS@data), k = 3)
Arguments
HTS |
A |
position |
An integer, the position of the last observed histogram (default: the last one). |
k |
The number of neighbours (default 3). |
Value
A distributionH object, the forecast.
References
Arroyo, J., Mate, C. (2009). Forecasting histogram time series with k-nearest neighbours methods. International Journal of Forecasting, 25(1), 192-207. doi:10.1016/j.ijforecast.2008.07.003
Examples
prediction <- HTS.predict.knn(HTS = RetHTS, position = 108, k = 3)
Matrices of histograms: the MatH class
Description
The MatH class describes a matrix of histograms: each cell contains a
distributionH object, rows are the individuals and columns the
(histogram-valued) variables.
Usage
MatH(
x = NULL,
nrows = 1,
ncols = 1,
rownames = NULL,
varnames = NULL,
by.row = FALSE
)
Arguments
nrows, ncols |
Integers, the number of rows (individuals) and of columns (variables). Default 1. |
by.row |
A logical value (default |
x |
A list of |
rownames, varnames |
Character vectors (or lists of strings), the names
of the rows and of the columns (variables). Default |
Value
MatH() returns a MatH object.
Slots
MA matrix of mode list, each cell containing a
distributionHobject.
Creating objects
Objects are created with MatH() or with
new("MatH", nrows, ncols, ListOfDist, names.rows, names.cols, by.row),
where ListOfDist is a list of distributionH objects and
names.rows, names.cols are the names of rows and columns.
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
See Also
get.MatH.main.info, plot,MatH-method,
WH.vec.mean, WH.var.covar.
Examples
## a list of six distributionH objects
ListOfDist <- vector("list", 6)
ListOfDist[[1]] <- distributionH(c(1, 2, 3), c(0, 0.4, 1))
ListOfDist[[2]] <- distributionH(c(7, 8, 10, 15), c(0, 0.2, 0.7, 1))
ListOfDist[[3]] <- distributionH(c(9, 11, 20), c(0, 0.5, 1))
ListOfDist[[4]] <- distributionH(c(2, 5, 8), c(0, 0.3, 1))
ListOfDist[[5]] <- distributionH(c(8, 10, 15), c(0, 0.75, 1))
ListOfDist[[6]] <- distributionH(c(20, 22, 24), c(0, 0.12, 1))
## a 3 x 2 MatH filled by columns
MyMAT <- MatH(
x = ListOfDist, nrows = 3, ncols = 2,
rownames = c("I1", "I2", "I3"), varnames = c("Var1", "Var2")
)
MyMAT
## an empty 10 x 4 matrix of histograms
MAT <- MatH(nrows = 10, ncols = 4)
Ozone data (stations without missing data)
Description
Histograms of four variables recorded by 78 stations in the USA, without missing data: ozone concentration (ppb), temperature (C), solar radiation (W/m2) and wind speed (m/s).
Format
A MatH object with 78 rows (stations) and 4 columns (variables).
Source
US EPA, CASTNET (Clean Air Status and Trends Network), meteorological data.
Examples
get.MatH.main.info(OzoneFull)
Ozone data (all the stations)
Description
Histograms of four variables recorded by 84 stations in the USA: ozone concentration (ppb), temperature (C), solar radiation (W/m2) and wind speed (m/s). Some stations have missing data.
Format
A MatH object with 84 rows (stations) and 4 columns (variables).
Source
US EPA, CASTNET (Clean Air Status and Trends Network), meteorological data.
Examples
get.MatH.main.info(OzoneH)
Histogram time series of returns
Description
Daily histograms of the returns of the US dollar / Japanese yen exchange rate.
Format
A HTS-class object with 108 histograms.
Examples
summaryHTS(subsetHTS(RetHTS, from = 1, to = 5))
plot(subsetHTS(RetHTS, from = 1, to = 20))
Distance between a point and a line
Description
Computes the Euclidean distance between a point and the line through two
points (used by DouglasPeucker).
Usage
ShortestDistance(p, line)
Arguments
p |
A vector with the coordinates of the point. |
line |
A 2 x 2 matrix with the coordinates of two points of the line. |
Value
A number, the distance of p from line.
See Also
Examples
ShortestDistance(c(0, 1), rbind(c(0, 0), c(1, 0)))
Matrices of histograms with a time reference: the TMatH class
Description
The TMatH class extends MatH with a time reference (timestamps or
time periods).
Slots
tstampA numeric vector of timestamps.
periodA list of time periods (alternative to
tstamp).MThe matrix of histograms, as in
MatH-class.
Creating objects
Objects are created with new("TMatH", mat, tstamp, period), where
mat is a MatH object.
See Also
Histograms with a time reference: the TdistributionH class
Description
The TdistributionH class extends distributionH with a time
reference: a timestamp or a time period. It is the element of a histogram time
series (HTS-class).
Slots
tstampA number, the timestamp.
periodA list with two elements,
startandend, the bounds of the time period (alternative totstamp).xThe bounds of the bins (see
distributionH-class).pThe cdf at
x.mThe mean.
sThe standard deviation.
Creating objects
Objects are created with
new("TdistributionH", tstamp, period, x, p, m, s), where x,
p, m and s are as in distributionH.
See Also
HTS-class, plot,TdistributionH-method
Examples
td <- new("TdistributionH", tstamp = 1, x = c(1, 2, 3), p = c(0, 0.4, 1))
td@tstamp
Principal component analysis of a histogram variable
Description
Principal component analysis (PCA) of one histogram variable based on the L2 Wasserstein distance: a centred (not standardised) PCA of the quantiles of the histograms. It provides a dimensional reduction and a visualization of the distributions.
Usage
WH.1d.PCA(
data,
var,
quantiles = 10,
plots = TRUE,
listaxes = c(1:4),
axisequal = FALSE,
qcut = 1,
outl = 0
)
Arguments
data |
A |
var |
An integer, the column of the variable to analyse. |
quantiles |
An integer, the number of quantiles used in the analysis (default 10). |
plots |
A logical value (default |
listaxes |
A vector of integers, the axes of the factorial planes to
plot (default |
axisequal |
A logical value (default |
qcut |
A number between 0.5 and 1 (default 1): densities higher than
their |
outl |
A number between 0 (default) and 0.5, the probability mass removed from each tail of the distributions (e.g. 0.1 removes 10% from each tail). |
Value
A list with PCAout, the results of
PCA, WASSVARIANCE (not computed, always 0)
and INERTIA, the total inertia.
References
Verde, R., Irpino, A., Balzanella, A. (2016). Dimension reduction techniques for distributional symbolic data. IEEE Transactions on Cybernetics, 46(2), 344-355. doi:10.1109/TCYB.2015.2389653
See Also
WH.MultiplePCA, WH.plot_multiple_Spanish.funs
Examples
results <- WH.1d.PCA(data = BLOOD, var = 1, listaxes = c(1:2))
Principal component analysis of a set of histogram variables
Description
(Beta version) Principal component analysis of several histogram variables
based on the L2 Wasserstein distance: a multiple factor analysis
(MFA) of the quantiles of the histograms, where each
variable is a group of quantiles. It extends WH.1d.PCA.
Usage
WH.MultiplePCA(data, list.of.vars, quantiles = 10, outl = 0, graph = TRUE)
Arguments
data |
A |
list.of.vars |
A vector of integers, the columns of the variables to analyse. |
quantiles |
An integer, the number of quantiles used in the analysis (default 10). |
outl |
A number between 0 (default) and 0.5, the probability mass removed from each tail of the distributions (e.g. 0.1 removes 10% from each tail). |
graph |
A logical value (default |
Value
The results of MFA.
See Also
WH.plot_multiple_Spanish.funs,
WH.plot_multiple_indivs
Examples
res <- WH.MultiplePCA(BLOOD, list.of.vars = c(1:3), graph = FALSE)
Bind matrices of histograms
Description
WH.bind.row binds by rows two MatH objects with the same number
of columns, WH.bind.col binds by columns two MatH objects with
the same number of rows. WH.bind does one of the two according to
byrow.
Usage
WH.bind.row(object1, object2)
WH.bind.col(object1, object2)
WH.bind(object1, object2, byrow)
Arguments
object1, object2 |
Two |
byrow |
A logical value: if |
Value
A MatH object.
Examples
WH.bind.row(BLOOD[1:3, ], BLOOD[5:8, ])
WH.bind.col(BLOOD[1:10, 1], BLOOD[1:10, 3])
WH.bind(BLOOD[1:10, 1], BLOOD[1:10, 3], byrow = FALSE)
Product of two matrices of histograms
Description
Matrix product of two MatH objects, where the product of two cells is
the dot product of the histograms inducing the L2 Wasserstein metric (see
dotpW).
Usage
## S4 method for signature 'MatH,MatH'
WH.mat.prod(object1, object2, traspose1 = FALSE, traspose2 = FALSE)
Arguments
object1, object2 |
Two |
traspose1, traspose2 |
Logical values (default |
Value
A numeric matrix.
Examples
MAT <- WH.mat.prod(BLOOD[1:5, ], BLOOD[6:10, ], traspose1 = TRUE)
Sum of two matrices of histograms
Description
Sums two MatH objects of the same dimensions, cell by cell, by summing
the quantile functions of the histograms (a sum consistent with the L2
Wasserstein metric).
Usage
WH.mat.sum(object1, object2)
Arguments
object1, object2 |
Two |
Value
A MatH object.
Examples
MAT <- WH.mat.sum(BLOOD[1:5, ], BLOOD[6:10, ])
Plot the variables of a PCA of histogram variables (Spanish-fan plot)
Description
Plots the quantiles of the histogram variables on a factorial plane after
WH.MultiplePCA (or WH.1d.PCA): the quantiles of
each variable form a fan.
Usage
WH.plot_multiple_Spanish.funs(
res,
axes = c(1, 2),
var = 1,
LABS = TRUE,
multi = TRUE,
corplot = TRUE
)
Arguments
res |
The results of |
axes |
A vector of two integers, the factorial axes (default
|
var |
A vector of integers, the variables to plot. |
LABS |
A logical value (default |
multi |
A logical value: |
corplot |
A logical value: if |
Value
The plot is drawn on the current device and the ggplot object
is returned invisibly.
Examples
res <- WH.MultiplePCA(BLOOD, list.of.vars = c(1:3), graph = FALSE)
WH.plot_multiple_Spanish.funs(res, axes = c(1, 2), var = c(1:3))
Plot the histograms of the individuals on a factorial plane
Description
(Beta version) Plots the histograms (or densities) of one variable for each
individual, placed at the coordinates of the individuals on a factorial plane
of WH.MultiplePCA.
Usage
WH.plot_multiple_indivs(
data,
res,
axes = c(1, 2),
indiv = 0,
var = 1,
strx = 0.1,
stry = 0.1,
HISTO = TRUE,
coor = 0,
stat = "mean"
)
Arguments
data |
A |
res |
The results of |
axes |
A vector of two integers, the factorial axes (default
|
indiv |
A vector of integers, the individuals (rows) to plot. Default 0: all the individuals. |
var |
An integer, the variable to plot. |
strx, stry |
Resizing factors for the domain and for the density of the histograms (default 0.1: one tenth of the range of the axes). |
HISTO |
A logical value: if |
coor |
A matrix of coordinates of the individuals. Default 0: the
coordinates in |
stat |
The statistic used to label and colour the histograms in the
second plot: |
Value
The two plots are drawn on the current device and a list with the two
ggplot objects is returned invisibly.
Examples
results <- WH.MultiplePCA(BLOOD, list.of.vars = c(1:3), graph = FALSE)
WH.plot_multiple_indivs(BLOOD, results, axes = c(1, 2), var = 1, HISTO = TRUE)
WH.plot_multiple_indivs(BLOOD, results, axes = c(1, 2), var = 1, HISTO = FALSE)
Goodness of fit of a two-component regression of histogram variables
Description
Computes goodness of fit indices of the predictions of a
WH.regression.two.components model.
Usage
WH.regression.GOF(observed, predicted)
Arguments
observed |
A |
predicted |
A |
Value
A list with the root mean squared error based on the L2 Wasserstein
distance (RMSE_W), the OMEGA index and the pseudo-R2 index
(PSEUDOR2, with the details of the decomposition of the sum of
squares).
References
Irpino, A., Verde, R. (2015). Linear regression for numeric symbolic variables: a least squares approach based on Wasserstein Distance. Advances in Data Analysis and Classification, 9, 81-106. doi:10.1007/s11634-015-0197-7
Examples
model.parameters <- WH.regression.two.components(data = BLOOD, Yvar = 1, Xvars = c(2:3))
Predicted.BLOOD <- WH.regression.two.components.predict(
data = BLOOD[, 2:3],
parameters = model.parameters
)
WH.regression.GOF(observed = BLOOD[, 1], predicted = Predicted.BLOOD)
Two-component regression of histogram variables
Description
Linear regression of a histogram variable on a set of histogram variables, based on the decomposition of the L2 Wasserstein distance into a component for the means and a component for the centred distributions. The parameters are estimated by least squares (non-negative least squares for the centred component).
Usage
WH.regression.two.components(data, Yvar, Xvars, simplify = FALSE, qua = 20)
Arguments
data |
A |
Yvar |
An integer, the column of the dependent variable. |
Xvars |
A vector of integers, the columns of the explanatory variables. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles when |
Value
A named vector with the estimated parameters: the intercept and the
coefficients of the means (prefix AV_) and the coefficients of the
centred distributions (prefix CEN_).
References
Irpino, A., Verde, R. (2015). Linear regression for numeric symbolic variables: a least squares approach based on Wasserstein Distance. Advances in Data Analysis and Classification, 9, 81-106. doi:10.1007/s11634-015-0197-7
See Also
WH.regression.two.components.predict,
WH.regression.GOF
Examples
model.parameters <- WH.regression.two.components(data = BLOOD, Yvar = 1, Xvars = c(2:3))
model.parameters
Predictions of a two-component regression of histogram variables
Description
Predicts the histograms of the dependent variable using the parameters
estimated by WH.regression.two.components.
Usage
WH.regression.two.components.predict(data, parameters)
Arguments
data |
A |
parameters |
The named vector of parameters returned by
|
Value
A MatH object with one column, the predicted histograms.
See Also
Examples
model.parameters <- WH.regression.two.components(data = BLOOD, Yvar = 1, Xvars = c(2:3))
Predicted.BLOOD <- WH.regression.two.components.predict(
data = BLOOD[, 2:3],
parameters = model.parameters
)
Sum of squares, covariance and correlation of histogram variables
Description
Compute the matrix of the sums of squared deviations from the mean
(WH.SSQ), the variance-covariance matrix (WH.var.covar) and the
correlation matrix (WH.correlation) of the variables of a MatH
object, according to the L2 Wasserstein metric. The functions with suffix 2
compute the same (rectangular) matrices between the variables of two
MatH objects with the same number of rows.
Usage
## S4 method for signature 'MatH'
WH.SSQ(object, w = numeric(0))
## S4 method for signature 'MatH'
WH.var.covar(object, w = numeric(0))
## S4 method for signature 'MatH'
WH.correlation(object, w = numeric(0))
## S4 method for signature 'MatH,MatH'
WH.SSQ2(object1, object2, w = numeric(0))
## S4 method for signature 'MatH,MatH'
WH.var.covar2(object1, object2, w = numeric(0))
## S4 method for signature 'MatH,MatH'
WH.correlation2(object1, object2, w = numeric(0))
Arguments
object |
A |
object1, object2 |
Two |
w |
A vector of non-negative weights, one for each row (individual). Default: equal weights. |
Value
A numeric matrix.
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
Examples
WH.SSQ(BLOOD)
WH.var.covar(BLOOD)
WH.correlation(BLOOD)
# weighted, with random weights
RN <- runif(get.MatH.nrows(BLOOD))
WH.var.covar(BLOOD, w = RN)
# between two sets of variables
WH.correlation2(BLOOD[, 1], BLOOD[, 2:3])
Weighted sum and mean of the histograms of a matrix
Description
WH.vec.sum and WH.vec.mean compute the (weighted) sum and the
(weighted) mean of all the histograms of a MatH object, consistently
with the L2 Wasserstein metric: the result is the histogram whose quantile
function is the (weighted) sum or mean of the quantile functions. The mean is
the Wasserstein barycenter of the histograms.
Usage
## S4 method for signature 'MatH'
WH.vec.sum(object, w = numeric(0))
## S4 method for signature 'MatH'
WH.vec.mean(object, w = numeric(0))
Arguments
object |
A |
w |
A vector of non-negative weights, one for each cell of the matrix. Default: equal weights. |
Value
A distributionH object.
Examples
WH.vec.mean(BLOOD)
WH.vec.sum(BLOOD)
# weighted mean with random weights
RN <- runif(get.MatH.nrows(BLOOD) * get.MatH.ncols(BLOOD))
WH.vec.mean(BLOOD, w = RN)
Batch Kohonen self-organising maps of histogram data with adaptive distances
Description
Batch Kohonen self-organising 2d map of the individuals of a MatH
object, based on adaptive L2 Wasserstein distances.
Usage
WH_2d_Adaptive_Kohonen_maps(
x,
net = list(xdim = 4, ydim = 3, topo = c("rectangular")),
kern.param = 2,
TMAX = -9999,
Tmin = -9999,
niter = 30,
repetitions,
simplify = FALSE,
qua = 10,
standardize = FALSE,
schema = 6,
init.weights = "EQUAL",
weight.sys = "PROD",
theta = 2,
Wfix = FALSE,
verbose = FALSE,
atleast = 2
)
Arguments
x |
A |
net |
A list describing the topology of the map:
|
kern.param |
The parameter of the RBF kernel (default 2). |
TMAX, Tmin |
The initial and final values of the neighbourhood radius. When negative (default), they are computed from the size of the map. |
niter |
The maximum number of iterations (default 30). |
repetitions |
The number of repetitions of the algorithm (default 5); the best solution is returned. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
schema |
An integer, the system of weights: 1 = a weight for each variable; 2 = a weight for the position and one for the variability component of each variable; 3 and 4 = as 1 and 2, with a different set of weights for each neuron (product of the weights of each variable equal to one); 5 and 6 = as 1 and 2, with a different set of weights for each neuron (product of all the weights equal to one, default 6). |
init.weights |
The initial weights: |
weight.sys |
The constraint on the weights: |
theta |
A number, the exponent of the weights when
|
Wfix |
A logical value (default |
verbose |
A logical value (default |
atleast |
An integer (default 2): solutions where fewer than
|
Details
Batch Self-Organising Maps (BSOM) for histogram data, with a cost function based on the L2 Wasserstein distance, i.e. the Euclidean distance between quantile functions. The adaptive version introduces an automatic system of weights in the cost function, to take into account the different effect of the variables on the map.
Value
A list with:
solution |
The best solution among the repetitions: a list with
|
quality |
The proportion of the total sum of squares explained by the map (the higher the better). |
and further details on the parameters of the algorithm. The final map is plotted on the current graphic device.
References
Irpino A., Verde R., De Carvalho F.A.T. (2012). Batch self organizing maps for interval and histogram data. In: Proceedings of COMPSTAT 2012, ISI/IASC, 143-154.
See Also
Examples
results <- WH_2d_Adaptive_Kohonen_maps(
x = BLOOD,
net = list(xdim = 2, ydim = 3, topo = c("rectangular")),
repetitions = 2, simplify = TRUE,
qua = 10, standardize = TRUE
)
Batch Kohonen self-organising maps of histogram data
Description
Batch Kohonen self-organising 2d map of the individuals of a MatH
object, based on the L2 Wasserstein distance.
Usage
WH_2d_Kohonen_maps(
x,
net = list(xdim = 4, ydim = 3, topo = c("rectangular")),
kern.param = 2,
TMAX = 2,
Tmin = 0.2,
niter = 30,
repetitions = 5,
simplify = FALSE,
qua = 10,
standardize = FALSE,
verbose = FALSE
)
Arguments
x |
A |
net |
A list describing the topology of the map:
|
kern.param |
The parameter of the RBF kernel (default 2). |
TMAX, Tmin |
The initial and final values of the neighbourhood radius (defaults 2 and 0.2). |
niter |
The maximum number of iterations (default 30). |
repetitions |
The number of repetitions of the algorithm (default 5); the best solution is returned. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
verbose |
A logical value (default |
Details
Batch Self-Organising Maps (BSOM) for histogram data, with a cost function based on the L2 Wasserstein distance, i.e. the Euclidean distance between quantile functions. The adaptive version introduces an automatic system of weights in the cost function, to take into account the different effect of the variables on the map.
Value
A list with:
solution |
The best solution among the repetitions: a list with
|
quality |
The proportion of the total sum of squares explained by the map (the higher the better). |
and further details on the parameters of the algorithm. The final map is plotted on the current graphic device.
References
Irpino A., Verde R., De Carvalho F.A.T. (2012). Batch self organizing maps for interval and histogram data. In: Proceedings of COMPSTAT 2012, ISI/IASC, 143-154.
See Also
Examples
results <- WH_2d_Kohonen_maps(
x = BLOOD,
net = list(xdim = 2, ydim = 3, topo = c("rectangular")),
repetitions = 2, simplify = TRUE,
qua = 10, standardize = TRUE
)
L2 Wasserstein distance matrix
Description
Computes the matrix of the L2 Wasserstein distances between the individuals
(rows) of a MatH object, summing the squared distances over the
variables.
Usage
WH_MAT_DIST(x, simplify = FALSE, qua = 10, standardize = FALSE)
Arguments
x |
A |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
Value
A symmetric matrix of L2 Wasserstein distances.
References
Irpino A., Verde R. (2006). A new Wasserstein based distance for the hierarchical clustering of histogram symbolic data. In: Batanjeli et al. (eds.) Data Science and Classification, IFCS 2006, Springer, 185-192.
See Also
Examples
DMAT <- WH_MAT_DIST(x = BLOOD, simplify = TRUE)
K-means clustering of histogram data with adaptive distances
Description
K-means of the individuals of a MatH object based on adaptive L2
Wasserstein distances: the algorithm also estimates a weight for each variable
(or for each component of the variables, and/or for each cluster).
Usage
WH_adaptive.kmeans(
x,
k,
schema = 1,
init,
rep,
simplify = FALSE,
qua = 10,
standardize = FALSE,
weight.sys = "PROD",
theta = 2,
init.weights = "EQUAL",
verbose = FALSE
)
Arguments
x |
A |
k |
An integer, the number of clusters. |
schema |
An integer, the system of weights: 1 = a weight for each variable (default); 2 = a weight for the position and one for the variability component of each variable; 3 = as 1, with a different set of weights for each cluster; 4 = as 2, with a different set of weights for each cluster. |
init |
Not used. |
rep |
An integer, the number of repetitions of the algorithm (with random starting partitions); the best solution is returned. Default 5. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
weight.sys |
The constraint on the weights: |
theta |
A number, the exponent of the weights when
|
init.weights |
The initial weights: |
verbose |
A logical value (default |
Value
A list with IDX (the cluster of each individual),
cardinality (the size of each cluster), proto (a MatH
object with the prototypes), weights (the weights of the variables or
components), Crit (the criterion), TOTSSQ, BSQ,
WSQ (total, between and within sums of squares) and quality (the
proportion of the total sum of squares explained by the partition).
References
Irpino A., Verde R., De Carvalho F.A.T. (2014). Dynamic clustering of histogram data based on adaptive squared Wasserstein distances. Expert Systems with Applications, 41, 3351-3366. doi:10.1016/j.eswa.2013.12.001
See Also
WH_kmeans, WH_adaptive_fcmeans
Examples
results <- WH_adaptive.kmeans(x = BLOOD, k = 2, rep = 10,
simplify = TRUE, qua = 10, standardize = TRUE)
results$weights
Fuzzy c-means clustering of histogram data with adaptive distances
Description
Fuzzy c-means of the individuals of a MatH object based on adaptive L2
Wasserstein distances: the algorithm also estimates a weight for each variable
(or for each component of the variables, and/or for each cluster).
Usage
WH_adaptive_fcmeans(
x,
k = 5,
schema,
m = 1.6,
rep,
simplify = FALSE,
qua = 10,
standardize = FALSE,
init.weights = "EQUAL",
weight.sys = "PROD",
theta = 2,
verbose = FALSE
)
Arguments
x |
A |
k |
An integer, the number of clusters. |
schema |
An integer, the system of weights: 1 = a weight for each variable; 2 = a weight for the position and one for the variability component of each variable; 3 = as 1, with a different set of weights for each cluster; 4 = as 2, with a different set of weights for each cluster. |
m |
A number greater than 1, the fuzziness coefficient (default 1.6). |
rep |
An integer, the number of repetitions of the algorithm (with random starting partitions); the best solution is returned. Default 5. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
init.weights |
The initial weights: |
weight.sys |
The constraint on the weights: |
theta |
A number, the exponent of the weights when
|
verbose |
A logical value (default |
Value
A list with:
solution |
The best solution among the repetitions: a list with
|
quality |
The proportion of the total sum of squares explained by the partition (the higher the better). |
and further details on the decomposition of the sum of squares.
See Also
WH_fcmeans, WH_adaptive.kmeans
Examples
results <- WH_adaptive_fcmeans(
x = BLOOD, k = 2, schema = 4, m = 1.5, rep = 3, simplify = TRUE,
qua = 10, standardize = TRUE, init.weights = "EQUAL", weight.sys = "PROD"
)
results$solution$var.weights
Fuzzy c-means clustering of histogram data
Description
Fuzzy c-means of the individuals of a MatH object, based on the L2
Wasserstein distance between histograms.
Usage
WH_fcmeans(x, k, m = 1.6, rep, simplify = FALSE, qua = 10, standardize = FALSE)
Arguments
x |
A |
k |
An integer, the number of clusters. |
m |
A number greater than 1, the fuzziness coefficient (default 1.6). |
rep |
An integer, the number of repetitions of the algorithm (with random starting partitions); the best solution is returned. Default 5. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
Value
A list with:
solution |
The best solution among the repetitions: a list with
|
quality |
The proportion of the total sum of squares explained by the partition (the higher the better). |
and further details on the decomposition of the sum of squares.
See Also
WH_adaptive_fcmeans, WH_kmeans
Examples
results <- WH_fcmeans(x = BLOOD, k = 2, m = 1.5, rep = 10,
simplify = TRUE, qua = 10, standardize = TRUE)
results$solution$membership
Hierarchical clustering of histogram data
Description
Hierarchical clustering of the individuals of a MatH object, based on
the L2 Wasserstein distance. It is a wrapper of hclust.
Usage
WH_hclust(
x,
simplify = FALSE,
qua = 10,
standardize = FALSE,
distance = "WDIST",
method = "complete"
)
Arguments
x |
A |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
distance |
The distance: only |
method |
The agglomeration method, as in |
Value
An object of class hclust.
References
Irpino A., Verde R. (2006). A new Wasserstein based distance for the hierarchical clustering of histogram symbolic data. In: Batanjeli et al. (eds.) Data Science and Classification, IFCS 2006, Springer, 185-192.
See Also
Examples
results <- WH_hclust(x = BLOOD, simplify = TRUE, method = "complete")
plot(results)
cutree(results, k = 5)
K-means clustering of histogram data
Description
K-means (dynamic clustering) of the individuals of a MatH object, based
on the L2 Wasserstein distance between histograms.
Usage
WH_kmeans(
x,
k,
rep = 5,
simplify = FALSE,
qua = 10,
standardize = FALSE,
verbose = FALSE
)
Arguments
x |
A |
k |
An integer, the number of clusters. |
rep |
An integer, the number of repetitions of the algorithm (with random starting partitions); the best solution is returned. Default 5. |
simplify |
A logical value (default |
qua |
An integer, the number of quantiles used when |
standardize |
A logical value (default |
verbose |
A logical value (default |
Value
A list with:
solution |
The best solution among the repetitions (minimum criterion): a
list with |
quality |
The proportion of the total sum of squares explained by the partition (the higher the better). |
References
Irpino A., Verde R., Lechevallier Y. (2006). Dynamic clustering of histograms using Wasserstein metric. In: Rizzi A., Vichi M. (eds.) COMPSTAT 2006 - Advances in computational statistics, Physica-Verlag, 869-876.
See Also
WH_adaptive.kmeans, WH_fcmeans,
WH_hclust
Examples
results <- WH_kmeans(
x = BLOOD, k = 2, rep = 10, simplify = TRUE,
qua = 10, standardize = TRUE
)
results$solution$IDX
results$quality
Squared L2 Wasserstein distance between two histograms
Description
Computes the squared L2 Wasserstein distance between two distributionH
objects, i.e. the integral of the squared difference of their quantile
functions. Optionally it returns its decomposition into a position, a size and
a shape component.
Usage
## S4 method for signature 'distributionH,distributionH'
WassSqDistH(object1 = object1, object2 = object2, details = FALSE)
Arguments
object1, object2 |
Two |
details |
A logical value (default |
Value
If details = FALSE, a number, the squared distance. If
details = TRUE, a named vector with the squared distance
(SQ_W_dist), its position (POSITION), size (SIZE) and
shape (SHAPE) components, and the correlation between the quantile
functions (rQQ).
References
Irpino, A. and Romano, E. (2007): Optimal histogram representation of large data sets: Fisher vs piecewise linear approximations. RNTI E-9, 99-110.
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
See Also
WH_MAT_DIST for the distance matrix of a MatH.
Examples
mydist1 <- distributionH(x = c(1, 2, 3), p = c(0, 0.4, 1))
mydist2 <- distributionH(x = c(7, 8, 10, 15), p = c(0, 0.2, 0.7, 1))
WassSqDistH(mydist1, mydist2)
WassSqDistH(mydist1, mydist2, details = TRUE)
Fix the empty bins of histograms
Description
Checks for empty bins, i.e. bins with zero weight (two consecutive equal values
of the cdf). Each empty bin gets a weight of 1e-8 and the cdf is
renormalised. Since version 1.0.9 empty bins are fixed when a
distributionH object is created (see distributionH), so
this method is useful for objects created with previous versions of the
package or modified by assigning their slots directly. The MatH method
applies the check to all the cells of the matrix.
Usage
checkEmptyBins(object)
Arguments
object |
A |
Value
An object of the same class of object, without empty bins.
Examples
## an empty bin in an object modified by slot assignment
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.5, 0.6, 1))
mydist@p <- c(0, 0.5, 0.5, 1)
diff(checkEmptyBins(mydist)@p)
## all the distributions of a MatH
newMat <- checkEmptyBins(China_Seas[1:5, 1:3])
Cumulative distribution function of a histogram at a value
Description
Computes the value F(q) of the cumulative distribution function of a
distributionH object.
Usage
compP(object, q)
Arguments
object |
A |
q |
A number. |
Value
A number between 0 and 1.
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
compP(mydist, 5)
Quantile of a histogram
Description
Computes the quantile of a distributionH object at a given level,
i.e. the value Q(p) = F^{-1}(p) of its quantile function.
Usage
compQ(object, p)
Arguments
object |
A |
p |
A number between 0 and 1. |
Value
A number, the quantile of order p.
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
compQ(mydist, 0.5) # the median
compQ(mydist, 0) # the minimum
compQ(mydist, 1) # the maximum
compQ(mydist, 0.25) # the first quartile
Centres, radii and weights of the bins of a histogram
Description
Computes the centre (midpoint), the radius (half-width) and the weight
(probability) of each bin of a distributionH object. This
representation allows a fast computation of the statistics based on the L2
Wasserstein distance.
Usage
crwtransform(object)
Arguments
object |
A |
Value
A list with three numeric vectors: Centers, the midpoints of
the bins; Radii, the half-widths of the bins; Weights, the
probabilities of the bins (summing to one).
References
Irpino, A., Verde, R., Lechevallier, Y. (2006) Dynamic clustering of histograms using Wasserstein metric, In: Proceedings of COMPSTAT 2006, Physica-Verlag, 869-876.
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
crwtransform(mydist)
Build a histogram from raw data
Description
Builds a distributionH object from a vector of numeric values, using
one of several algorithms for choosing the bins.
Usage
data2hist(
data,
algo = "histogram",
type = "combined",
qua = 10,
breaks = numeric(0),
epsilon = 0.01
)
Arguments
data |
A numeric vector. |
algo |
The algorithm: |
type |
For |
qua |
For |
breaks |
For |
epsilon |
For |
Value
A distributionH object. Empty bins (without observations) get a
weight of 1e-8.
See Also
Examples
data <- rnorm(n = 1000, mean = 2, sd = 3)
mydist <- data2hist(data)
plot(mydist)
data2hist(data, algo = "FixedQuantiles", qua = 20)
Histogram objects: the distributionH class
Description
The distributionH class describes a histogram (a distribution) by means
of its cumulative distribution function (cdf): the bounds of the bins and the
values of the cdf at the bounds. All the methods of the package are based on
the L2 Wasserstein distance between distributions.
Usage
distributionH(x = numeric(0), p = numeric(0))
Arguments
x |
A numeric vector, the bounds of the bins, in non-decreasing order. A single value defines an impulse distribution. |
p |
A numeric vector of the same length of |
Value
distributionH() returns a distributionH object.
Slots
xA non-decreasing numeric vector: the bounds of the bins (the domain of the distribution).
pA non-decreasing numeric vector of the same length of
x, from 0 to 1: the cdf at the values inx.mThe mean of the distribution.
sThe standard deviation of the distribution.
Creating objects
Objects are created with distributionH(x, p) or, equivalently, with
new("distributionH", x, p, m, s), where the optional m and
s (mean and standard deviation) are computed when not given.
Empty bins, i.e. bins with zero weight (two consecutive equal values in
p), may produce numerical problems. Since version 1.0.9 each empty bin
gets a weight of 1e-8 and the cdf is renormalised when the object is
created (see also checkEmptyBins).
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
See Also
data2hist to build a histogram from raw data;
meanH, stdH, plot,distributionH-method.
Examples
# the histogram
# | Bins | Prob | cdf |
# | [1,2) | 0.4 | 0.4 |
# | [2,3] | 0.6 | 1.0 |
mydist <- distributionH(x = c(1, 2, 3), p = c(0, 0.4, 1))
mydist
str(mydist)
Dot product of two histograms
Description
Computes the dot product, inducing the L2 Wasserstein metric, between two
distributionH objects, or between a distributionH and a number
(considered as an impulse distribution).
Usage
dotpW(e1, e2)
Arguments
e1, e2 |
Two |
Value
A number.
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
Examples
mydist1 <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
mydist2 <- distributionH(x = c(5, 7, 15), p = c(0, 0.7, 1))
dotpW(mydist1, mydist2) # 39.51429
dotpW(mydist1, 3) # 13.2
dotpW(3, mydist1) # 13.2
Extract a sub-matrix of histograms
Description
Extracts rows and/or columns of a MatH object, as for an ordinary
matrix.
Usage
## S4 method for signature 'MatH,ANY,ANY,ANY'
x[i, j, ..., drop = TRUE]
Arguments
x |
A |
i, j |
Row and column indices (integers, names or logical vectors). |
... |
Not used. |
drop |
Not used (the result is always a |
Value
A MatH object.
Examples
SUB_D <- BLOOD[c(1, 2, 5), c(1, 2)]
SUB_D
Dimensions and names of a matrix of histograms
Description
Functions returning the number of rows and of columns, the names of the rows
(individuals) and of the columns (variables) of a MatH object.
Usage
get.MatH.nrows(object)
get.MatH.ncols(object)
get.MatH.rownames(object)
get.MatH.varnames(object)
get.MatH.main.info(object)
Arguments
object |
A |
Value
get.MatH.nrows and get.MatH.ncols return an integer;
get.MatH.rownames and get.MatH.varnames return a character
vector; get.MatH.main.info returns a list with all of them
(nrows, ncols, rownames, varnames).
Examples
get.MatH.nrows(BLOOD)
get.MatH.ncols(BLOOD)
get.MatH.rownames(BLOOD)
get.MatH.varnames(BLOOD)
get.MatH.main.info(BLOOD)
Statistics of the histograms of a matrix
Description
Computes a statistic (mean, median, standard deviation, ...) for each
histogram of a MatH object.
Usage
## S4 method for signature 'MatH'
get.MatH.stats(object, stat = "mean", prob = 0.5)
Arguments
object |
A |
stat |
The statistic: |
prob |
A number between 0 and 1, the level of the quantile when
|
Value
A list with the name of the statistic (stat), the level
prob (only when stat = "quantile") and the matrix of values
(mat).
Examples
get.MatH.stats(BLOOD) # means
get.MatH.stats(BLOOD, stat = "median")
get.MatH.stats(BLOOD, stat = "quantile", prob = 0.05) # 5th percentiles
get.MatH.stats(BLOOD, stat = "std")
Get or set a cell of a matrix of histograms
Description
get.cell.MatH returns the histogram in a cell of a MatH object;
set.cell.MatH assigns a histogram to a cell.
Usage
get.cell.MatH(object, r, c)
set.cell.MatH(object, mat, r, c)
Arguments
object |
For |
r, c |
Integers, the row and the column of the cell. |
mat |
A |
Value
get.cell.MatH returns a distributionH object,
set.cell.MatH the modified MatH object.
Examples
get.cell.MatH(BLOOD, r = 1, c = 1)
mydist <- distributionH(x = c(0, 1, 2, 3, 4), p = c(0, 0.1, 0.6, 0.9, 1))
MAT <- set.cell.MatH(mydist, BLOOD, r = 1, c = 1)
Cumulative distribution function of a histogram
Description
Returns the points of the cumulative distribution function (cdf) of a
distributionH object.
Usage
get.distr(object)
Arguments
object |
A |
Value
A data.frame with two columns: x, the bounds of the
bins, and p, the values of the cdf at x.
See Also
Examples
D <- distributionH(x = c(1, 2, 3, 4), p = c(0, 0.2, 0.6, 1))
get.distr(D)
Bins of a histogram
Description
Returns the bins of a distributionH object and their probabilities.
Usage
get.histo(object)
Arguments
object |
A |
Value
A data.frame with one row for each bin and three columns:
min.x and max.x, the bounds of the bin, and p, its
probability (relative frequency).
See Also
Examples
D <- distributionH(x = c(1, 2, 3, 4), p = c(0, 0.2, 0.6, 1))
get.histo(D)
Mean of a histogram (stored value)
Description
Returns the mean stored in the m slot of a distributionH object.
To compute it from the distribution use meanH.
Usage
get.m(object)
Arguments
object |
A |
Value
A number, the mean of the distribution.
See Also
Examples
D <- distributionH(x = c(1, 2, 3, 4), p = c(0, 0.2, 0.6, 1))
get.m(D)
Standard deviation of a histogram (stored value)
Description
Returns the standard deviation stored in the s slot of a
distributionH object. To compute it from the distribution use
stdH.
Usage
get.s(object)
Arguments
object |
A |
Value
A non-negative number, the standard deviation of the distribution.
See Also
Examples
D <- distributionH(x = c(1, 2, 3, 4), p = c(0, 0.2, 0.6, 1))
get.s(D)
Kurtosis of a histogram
Description
Computes the kurtosis (fourth standardised moment) of a distributionH
object.
Usage
kurtH(object)
Arguments
object |
A |
Value
A number, the kurtosis index (3 for a Gaussian distribution).
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
kurtH(mydist) # 2.133533
Mean of a histogram
Description
Computes the mean (first moment) of a distributionH object.
Usage
meanH(object)
Arguments
object |
A |
Value
A number, the mean of the distribution.
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
meanH(mydist) # 4.4
Plot a histogram time series
Description
Plots a HTS object as a sequence of violin plots or boxplots, one for
each timestamp.
Usage
## S4 method for signature 'HTS'
plot(x, y = "missing", type = "VIOLIN", border = "black", maxno.perplot = 30)
Arguments
x |
A |
y |
Not used. |
type |
The type of plot: |
border |
The colour of the borders (default |
maxno.perplot |
The maximum number of timestamps in each row of the plot (default 30): longer series are split into several rows. |
Value
The plot is drawn on the current device and the ggplot object is
returned invisibly, so that it can be further modified.
Examples
plot(subsetHTS(RetHTS, from = 1, to = 10))
plot(RetHTS, type = "BOXPLOT", border = "blue", maxno.perplot = 20)
plot(RetHTS, type = "VIOLIN", maxno.perplot = 20)
Plot a matrix of histograms
Description
Plots all the histograms of a MatH object: one panel for each variable,
one row for each individual.
Usage
## S4 method for signature 'MatH'
plot(x, y = "missing", type = "HISTO", border = "black", angL = 330)
Arguments
x |
A |
y |
Not used. |
type |
The type of plot: |
border |
The colour of the borders (default |
angL |
Not used (kept for compatibility). |
Value
The plot is drawn on the current device and the ggplot object is
returned invisibly, so that it can be further modified.
Examples
plot(BLOOD)
plot(BLOOD, type = "DENS", border = "blue")
plot(BLOOD, type = "BOXPLOT")
Plot a histogram with a time reference
Description
Plots a TdistributionH object: see plot,distributionH-method
for the types of plot.
Usage
## S4 method for signature 'TdistributionH'
plot(x, type = "HISTO", col = "green", border = "black")
Arguments
x |
A |
type |
The type of plot: |
col |
The fill colour (default |
border |
The colour of the borders (default |
Value
The plot is drawn on the current device and the ggplot object is
returned invisibly.
Examples
td <- new("TdistributionH", tstamp = 1, x = c(1, 2, 3), p = c(0, 0.4, 1))
plot(td)
Plot a histogram
Description
Plots a distributionH object as a histogram, a cumulative distribution
function, a quantile function, a density or a boxplot.
Usage
## S4 method for signature 'distributionH'
plot(x, type = "HISTO", col = "green", border = "black")
Arguments
x |
A |
type |
The type of plot: |
col |
The fill colour (default |
border |
The colour of the borders (default |
Value
The plot is drawn on the current device and the ggplot object is
returned invisibly, so that it can be further modified, e.g.
p <- plot(mydist); p + ggplot2::theme_bw().
Examples
mydist <- distributionH(x = c(7, 8, 10, 15), p = c(0, 0.2, 0.7, 1))
plot(mydist)
plot(mydist, type = "HISTO", col = "red", border = "blue")
plot(mydist, type = "DENS", col = "red", border = "blue")
plot(mydist, type = "HBOXPLOT")
plot(mydist, type = "VBOXPLOT")
plot(mydist, type = "CDF")
plot(mydist, type = "QF")
Plot observed versus predicted histograms
Description
Compares observed and predicted histograms (e.g. from
WH.regression.two.components.predict), one panel for each
individual.
Usage
plotPredVsObs(PRED, OBS, type = "HISTO", ncolu = 2)
Arguments
PRED |
A |
OBS |
A |
type |
The type of plot: |
ncolu |
The number of columns of panels (default 2). |
Value
The plot is drawn on the current device and the ggplot object
is returned invisibly.
See Also
Examples
pars <- WH.regression.two.components(BLOOD, Yvar = 1, Xvars = c(2:3))
PRED <- WH.regression.two.components.predict(data = BLOOD[, 2:3], parameters = pars)
OBS <- BLOOD[, 1]
plotPredVsObs(PRED, OBS, "HISTO")
plotPredVsObs(PRED, OBS, "CDF")
plotPredVsObs(PRED, OBS, "DENS")
Plot the errors of predicted histograms
Description
Plots the differences between observed and predicted histograms (e.g. from
WH.regression.two.components.predict) and prints the root mean
squared error based on the L2 Wasserstein distance.
Usage
plot_errors(PRED, OBS, type = "HISTO_QUA", np = 200)
Arguments
PRED |
A |
OBS |
A |
type |
The type of plot: |
np |
The number of points used to compute the differences (default 200). |
Value
The root mean squared error, invisibly. The plot is drawn on the current device.
See Also
plotPredVsObs, WH.regression.GOF
Examples
pars <- WH.regression.two.components(BLOOD, Yvar = 1, Xvars = c(2:3))
PRED <- WH.regression.two.components.predict(data = BLOOD[, 2:3], parameters = pars)
OBS <- BLOOD[, 1]
plot_errors(PRED, OBS, "HISTO_QUA")
plot_errors(PRED, OBS, "HISTO_DEN")
plot_errors(PRED, OBS, "DENS_KDE")
Correlation between the quantile functions of two histograms
Description
Computes the correlation between the quantile functions of two
distributionH objects.
Usage
rQQ(e1, e2)
Arguments
e1, e2 |
Two |
Value
A number, the correlation between the quantile functions.
References
Irpino, A., Verde, R. (2015) Basic statistics for distributional symbolic variables: a new metric-based approach, Advances in Data Analysis and Classification, 9(2), 143-175. doi:10.1007/s11634-014-0176-4
Examples
mydist1 <- distributionH(x = c(1, 2, 3), p = c(0, 0.4, 1))
mydist2 <- distributionH(x = c(7, 8, 10, 15), p = c(0, 0.2, 0.7, 1))
rQQ(mydist1, mydist2) # 0.916894
Register two histograms on a common cdf
Description
Given two distributionH objects, returns two equivalent
distributions sharing the same cdf values (the union of the two p
vectors). This is the basis for computing the statistics based on the L2
Wasserstein distance.
Usage
register(object1, object2)
Arguments
object1, object2 |
Two |
Value
A list: the two distributionH objects, with the same p
slot, and a matrix with their quantiles and the common cdf.
References
Irpino, A., Lechevallier, Y. and Verde, R. (2006): Dynamic clustering of histograms using Wasserstein metric In: Rizzi, A., Vichi, M. (eds.) COMPSTAT 2006. Physica-Verlag, Berlin, 869-876.
Examples
mydist1 <- distributionH(c(1, 2, 3), c(0, 0.4, 1))
mydist2 <- distributionH(c(7, 8, 10, 15), c(0, 0.2, 0.7, 1))
regDist <- register(mydist1, mydist2)
regDist[[1]]@p
regDist[[1]]@x
regDist[[2]]@x
Register the histograms of a matrix on a common cdf
Description
registerMH recomputes all the histograms of a MatH object so that
they share the same cdf values (the same p slot), without changing the
distributions. This allows a fast computation of all the methods based on the
L2 Wasserstein metric. is.registeredMH checks whether the histograms
already share the same cdf.
Usage
is.registeredMH(object)
registerMH(object)
Arguments
object |
A |
Value
registerMH returns a MatH object whose histograms share
the same cdf; is.registeredMH returns TRUE or FALSE.
References
Irpino, A., Lechevallier, Y. and Verde, R. (2006): Dynamic clustering of histograms using Wasserstein metric In: Rizzi, A., Vichi, M. (eds.) COMPSTAT 2006. Physica-Verlag, Berlin, 869-876.
Examples
mydist1 <- distributionH(c(1, 2, 3), c(0, 0.4, 1))
mydist2 <- distributionH(c(7, 8, 10, 15), c(0, 0.2, 0.7, 1))
mydist3 <- distributionH(c(9, 11, 20), c(0, 0.8, 1))
MyMAT <- MatH(x = list(mydist1, mydist2, mydist3), nrows = 1, ncols = 3)
is.registeredMH(MyMAT) # FALSE
MATregistered <- registerMH(MyMAT)
is.registeredMH(MATregistered) # TRUE
MATregistered@M[[1, 1]]@p
Print a matrix of histograms
Description
Prints a MatH object showing, for each histogram, its mean and its
standard deviation.
Usage
## S4 method for signature 'MatH'
show(object)
Arguments
object |
A |
Value
Invisibly NULL; called for its side effect.
Examples
BLOOD
Print a histogram
Description
Prints a distributionH object as a table of bins and probabilities.
If the histogram has many bins, only the first and the last five are shown.
Usage
## S4 method for signature 'distributionH'
show(object)
Arguments
object |
A |
Value
Invisibly NULL; called for its side effect.
Examples
mydist <- distributionH(x = c(7, 8, 10, 15), p = c(0, 0.2, 0.7, 1))
mydist
Skewness of a histogram
Description
Computes the skewness (third standardised moment) of a distributionH
object.
Usage
skewH(object)
Arguments
object |
A |
Value
A number, the skewness index.
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
skewH(mydist) # 0.7148855
Coordinates of the stations of the China datasets
Description
Geographical coordinates of the 60 stations of China_Month and
China_Seas.
Format
A data frame with 60 rows and 9 columns: ID, Name_ST
(name of the station), Code_ST (code of the station), LAT.deg,
LAT.min, LON.deg, LON.min (latitude and longitude, degrees
and minutes), Elevation, Beginning (first year of observation).
Source
Climate Data Bases of the People's Republic of China 1841-1988 (TR055), doi:10.3334/CDIAC/cli.tr055
Examples
head(stations_coordinates)
Standard deviation of a histogram
Description
Computes the standard deviation (square root of the second centred moment)
of a distributionH object.
Usage
stdH(object)
Arguments
object |
A |
Value
A non-negative number, the standard deviation of the distribution.
See Also
Examples
mydist <- distributionH(x = c(1, 2, 3, 10), p = c(0, 0.1, 0.5, 1))
stdH(mydist) # 2.563851
Subset of a histogram time series
Description
Extracts the elements of a histogram time series between two positions.
Usage
subsetHTS(object, from, to)
Arguments
object |
A |
from, to |
Integers, the positions of the first and of the last element. |
Value
A HTS object.
Examples
SUB_RetHTS <- subsetHTS(RetHTS, from = 1, to = 20) # the first 20 elements
Summary statistics of a histogram time series
Description
Computes basic statistics for each histogram of a HTS object.
Usage
summaryHTS(x)
Arguments
x |
A |
Value
A data frame with one row for each histogram: timestamp and period, mean, standard deviation, skewness, kurtosis, minimum, quartiles and maximum.
Examples
summaryHTS(subsetHTS(RetHTS, from = 1, to = 10))