fbplot {roahd} | R Documentation |
Functional boxplot of univariate and multivariate functional data
Description
This function can be used to perform the functional boxplot of univariate or multivariate functional data.
Usage
fbplot(
Data,
Depths = "MBD",
Fvalue = 1.5,
adjust = FALSE,
display = TRUE,
xlab = NULL,
ylab = NULL,
main = NULL,
...
)
## S3 method for class 'fData'
fbplot(
Data,
Depths = "MBD",
Fvalue = 1.5,
adjust = FALSE,
display = TRUE,
xlab = NULL,
ylab = NULL,
main = NULL,
...
)
## S3 method for class 'mfData'
fbplot(
Data,
Depths = list(def = "MBD", weights = "uniform"),
Fvalue = 1.5,
adjust = FALSE,
display = TRUE,
xlab = NULL,
ylab = NULL,
main = NULL,
...
)
Arguments
Data |
the univariate or multivariate functional dataset whose
functional boxplot must be determined, in form of |
Depths |
either a vector containing the depths for each element of the dataset, or:
In both cases the name of the functions to compute depths must be available in the caller's environment. |
Fvalue |
the value of the inflation factor |
adjust |
either
|
display |
either a logical value indicating whether you want the functional boxplot to be displayed, or the number of the graphical device where you want the functional boxplot to be displayed. |
xlab |
the label to use on the x axis when displaying the functional boxplot. |
ylab |
the label (or list of labels for the multivariate functional case) to use on the y axis when displaying the functional boxplot. |
main |
the main title (or list of titles for the multivariate functional case) to be used when displaying the functional boxplot. |
... |
additional graphical parameters to be used in plotting functions. |
Value
Even when used in graphical way to plot the functional boxplot, the function returns a list of three elements:
-
Depths
: contains the depths of each element of the functional dataset. -
Fvalue
: is the value of F used to obtain the outliers. -
ID_out
: contains the vector of indices of dataset elements flagged as outliers (if any).
Adjustment
In the univariate functional case, when the adjustment option is
selected, the value of is optimized for the univariate functional
dataset provided with
Data
.
In practice, a number adjust$N_trials
of times a synthetic population
(of size adjust$tiral_size
with the same covariance (robustly
estimated from data) and centerline as fData
is simulated without
outliers and each time an optimized value is computed so that a
given proportion (
adjust$TPR
) of observations is flagged as outliers.
The final value of F
for the functional boxplot is determined as an
average of . At each time step the
optimization problem is solved using
stats::uniroot
(Brent's method).
References
Sun, Y., & Genton, M. G. (2012). Functional boxplots. Journal of Computational and Graphical Statistics.
Sun, Y., & Genton, M. G. (2012). Adjusted functional boxplots for spatio-temporal data visualization and outlier detection. Environmetrics, 23(1), 54-64.
See Also
fData
, MBD
, BD
,
mfData
, multiMBD
, multiBD
Examples
# UNIVARIATE FUNCTIONAL BOXPLOT - NO ADJUSTMENT
set.seed(1)
N = 2 * 100 + 1
P = 2e2
grid = seq( 0, 1, length.out = P )
D = 10 * matrix( sin( 2 * pi * grid ), nrow = N, ncol = P, byrow = TRUE )
D = D + rexp(N, rate = 0.05)
# c( 0, 1 : (( N - 1 )/2), -( ( ( N - 1 ) / 2 ) : 1 ) )^4
fD = fData( grid, D )
dev.new()
oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 3))
plot( fD, lwd = 2, main = 'Functional dataset',
xlab = 'time', ylab = 'values' )
fbplot( fD, main = 'Functional boxplot', xlab = 'time', ylab = 'values', Fvalue = 1.5 )
boxplot(fD$values[,1], ylim = range(fD$values), main = 'Boxplot of functional dataset at t_0 ' )
par(oldpar)
# UNIVARIATE FUNCTIONAL BOXPLOT - WITH ADJUSTMENT
set.seed( 161803 )
P = 2e2
grid = seq( 0, 1, length.out = P )
N = 1e2
# Generating a univariate synthetic gaussian dataset
Data = generate_gauss_fdata( N, centerline = sin( 2 * pi * grid ),
Cov = exp_cov_function( grid,
alpha = 0.3,
beta = 0.4 ) )
fD = fData( grid, Data )
dev.new()
fbplot( fD, adjust = list( N_trials = 10,
trial_size = 5 * N,
VERBOSE = TRUE ),
xlab = 'time', ylab = 'Values',
main = 'My adjusted functional boxplot' )
# MULTIVARIATE FUNCTIONAL BOXPLOT - NO ADJUSTMENT
set.seed( 1618033 )
P = 1e2
N = 1e2
L = 2
grid = seq( 0, 1, length.out = 1e2 )
C1 = exp_cov_function( grid, alpha = 0.3, beta = 0.4 )
C2 = exp_cov_function( grid, alpha = 0.3, beta = 0.4 )
# Generating a bivariate functional dataset of gaussian data with partially
# correlated components
Data = generate_gauss_mfdata( N, L,
centerline = matrix( sin( 2 * pi * grid ),
nrow = 2, ncol = P,
byrow = TRUE ),
correlations = rep( 0.5, 1 ),
listCov = list( C1, C2 ) )
mfD = mfData( grid, Data )
dev.new()
fbplot( mfD, Fvalue = 2.5, xlab = 'time', ylab = list( 'Values 1',
'Values 2' ),
main = list( 'First component', 'Second component' ) )