fbplot: Functional boxplot of univariate and multivariate functional...

Description Usage Arguments Value Adjustment References See Also Examples

View source: R/fbplot.R

Description

This function can be used to perform the functional boxplot of univariate or multivariate functional data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 fData or mfData object.

Depths

either a vector containing the depths for each element of the dataset, or:

  • univariate case: a string containing the name of the method you want to use to compute it. The default is 'MBD'.

  • multivariate case: a list with elements def, containing the name of the depth notion to be used to compute depths (BD or MBD), and weights, containing the value of parameter weights to be passed to the depth function. Default is list(def = 'MBD', weights = 'uniform').

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 F, default is F = 1.5.

adjust

either FALSE if you would like the default value for the inflation factor, F = 1.5, to be used, or (for now only in the univariate functional case) a list specifying the parameters required by the adjustment:

  • N_trials: the number of repetitions of the adjustment procedure based on the simulation of a gaussian population of functional data, each one producing an adjusted value of F, which will lead to the averaged adjusted value \bar{F}. Default is 20.

  • trial_size: the number of elements in the gaussian population of functional data that will be simulated at each repetition of the adjustment procedure. Default is 8 * Data$N.

  • TPR: the True Positive Rate of outliers, i.e. the proportion of observations in a dataset without amplitude outliers that have to be considered outliers. Default is 2 * pnorm(4 * qnorm(0.25)).

  • F_min: the minimum value of F, defining the left boundary for the optimization problem aimed at finding, for a given dataset of simulated gaussian data associated to Data, the optimal value of F. Default is 0.5.

  • F_max: the maximum value of F, defining the right boundary for the optimization problem aimed at finding, for a given dataset of simulated gaussian data associated to Data, the optimal value of F. Default is 5.

  • tol: the tolerance to be used in the optimization problem aimed at finding, for a given dataset of simulated gaussian data associated to Data, the optimal value of F. Default is 1e-3.

  • maxiter: the maximum number of iterations to solve the optimization problem aimed at finding, for a given dataset of simulated gaussian data associated to Data, the optimal value of F. Default is 100.

  • VERBOSE: a parameter controlling the verbosity of the adjustment process.

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:

Adjustment

In the univariate functional case, when the adjustment option is selected, the value of F 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 F_i 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 F_1, F_2, …, F_{N_{trials}}. At each time step the optimization problem is solved using stats::uniroot (Brent's method).

References

  1. Sun, Y., & Genton, M. G. (2012). Functional boxplots. Journal of Computational and Graphical Statistics.

  2. 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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' ) )

roahd documentation built on Nov. 4, 2021, 1:07 a.m.