cont_plot: Produce contribution plots

Description Usage Arguments Value Examples

View source: R/05_fault_detection.R

Description

This function produces a contribution plot from functional control charts for a given observation of a phase II data set, using ggplot.

Usage

1
cont_plot(cclist, id_num, which_plot = c("T2", "spe"), print_id = FALSE)

Arguments

cclist

A data.frame produced by control_charts_pca, control_charts_sof_pc regr_cc_fof, or regr_cc_sof.

id_num

An index number giving the observation in the phase II data set to be plotted, i.e. 1 for the first observation, 2 for the second, and so on.

which_plot

A character vector. Each value indicates which contribution you want to plot:

"T2" indicates contribution to the Hotelling's T^2 statistic,

"spe" indicates contribution to the squared prediction error statistic.

print_id

A logical value, if TRUE, it prints also the id of the observation in the title of the ggplot. Default is FALSE.

Value

A ggplot containing the contributions of functional variables to the monitoring statistics. Each plot is a bar plot, with bars corresponding to contribution values and horizontal black segments denoting corresponding (empirical) upper limits. Bars are coloured by red if contributions exceed their limit.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(funcharts)
data("air")
air <- lapply(air, function(x) x[201:300, , drop = FALSE])
fun_covariates <- c("CO", "temperature")
mfdobj_x <- get_mfd_list(air[fun_covariates],
                         n_basis = 15,
                         lambda = 1e-2)
y <- rowMeans(air$NO2)
y1 <- y[1:60]
y2 <- y[91:100]
mfdobj_x1 <- mfdobj_x[1:60]
mfdobj_x_tuning <- mfdobj_x[61:90]
mfdobj_x2 <- mfdobj_x[91:100]
mod <- sof_pc(y1, mfdobj_x1)
cclist <- control_charts_sof_pc(mod = mod,
                                y_test = y2,
                                mfdobj_x_test = mfdobj_x2,
                                mfdobj_x_tuning = mfdobj_x_tuning)
get_ooc(cclist)
cont_plot(cclist, 3)

funcharts documentation built on March 15, 2021, 5:07 p.m.