N.plot {RecordTest}R Documentation

Number of Records Plot

Description

This function builds a ggplot object to compare the sample means of the (weighted) number of records in a vector up to time tt, Nˉtω\bar N_{t}^\omega, and the expected values E(Ntω)\textrm{E}(N_t^{\omega}) under the classical record model (i.e., of IID continuous RVs).

Usage

N.plot(
  X,
  weights = function(t) 1,
  record = c(FU = 1, FL = 1, BU = 1, BL = 1),
  backward = c("T", "t"),
  point.col = c(FU = "red", FL = "blue", BU = "red", BL = "blue"),
  point.shape = c(FU = 19, FL = 19, BU = 4, BL = 4),
  conf.int = TRUE,
  conf.level = 0.9,
  conf.aes = c("ribbon", "errorbar"),
  conf.col = "grey69"
)

Arguments

X

A numeric vector, matrix (or data frame).

weights

A function indicating the weight given to the different records according to their position in the series, e.g., if function(t) t-1 then ωt=t1\omega_t = t-1.

record

Logical vector. Vector with four elements indicating if forward upper, forward lower, backward upper and backward lower are going to be shown, respectively. Logical values or 0,1 values are accepted.

backward

A character string "T" or "t" indicating if the backward number of records shown are calculated up to time tt in the backward series {XT,,X1}\{X_T,\ldots,X_1\} or in the series {Xt,,X1}\{X_t,\ldots,X_1\}. While the first option considers the evolution of a series of records observed up to time TT, the second considers that until each time tt the series has only been observed up to tt.

point.col, point.shape

Vector with four elements indicating the colour and shape of the points. Every one of the four elements represents forward upper, forward lower, backward upper and backward lower, respectively.

conf.int

Logical. Indicates if the RIs are also shown.

conf.level

(If conf.int == TRUE) Confidence level of the RIs.

conf.aes

(If conf.int == TRUE) A character string indicating the aesthetic to display for the RIs, "ribbon" (grey area) or "errorbar" (vertical lines).

conf.col

Colour used to plot the expected value and (if conf.int == TRUE) RIs.

Details

This plot is associated to the test N.test. It calculates the sample means of the number of records in a set of vectors up to every time tt (see Nmean.record). These sample means Nˉtω\bar N_{t}^\omega are calculated from the sample of MM values obtained from MM vectors, the columns of matrix X. Then, these values are plotted and compared with the expected values E(Ntω)\textrm{E}(N_t^{\omega}) and their reference intervals (RIs), under the hypothesis of the classical record model. The RIs of Nˉtω\bar N_{t}^\omega uses the fact that, under the classical record model, the statistic is asymptotically Normal.

The plot can show the four types of record at the same time (i.e., forward upper, forward lower, backward upper and backward lower). In their interpretations one must be careful, for forward records each time tt corresponds to the same year of observation, but for the backward series, time tt corresponds to the year of observation Tt+1T-t+1 where TT is the total number of observations in every series. Two types of backward records can be considered (see argument backward).

More details of this plot are shown in Cebrián, Castillo-Mateo, Asín (2022).

Value

A ggplot object.

Author(s)

Jorge Castillo-Mateo

References

Cebrián AC, Castillo-Mateo J, Asín J (2022). “Record Tests to Detect Non Stationarity in the Tails with an Application to Climate Change.” Stochastic Environmental Research and Risk Assessment, 36(2): 313-330. doi:10.1007/s00477-021-02122-w.

See Also

N.record, N.test, foster.test, foster.plot

Examples

# Plot at Zaragoza, with linear weights and error bar as RIs aesthetic
N.plot(ZaragozaSeries, weights = function(t) t-1, conf.aes = "errorbar")

# Plot only upper records
N.plot(ZaragozaSeries, record = c(1, 0, 1, 0))

# Change point colour and shape
Zplot <- N.plot(ZaragozaSeries, 
  point.col = c("red", "red", "blue", "blue"), 
  point.shape = c(19, 4, 19, 4))

## Not run: Load package ggplot2 to change the plot
#library("ggplot2")
## Remove legend
#Zplot + ggplot2::theme(legend.position = "none")
## Fancy axis
# Zplot + 
#   ggplot2::scale_x_continuous(name = "Year (forward)",
#     breaks = c(10, 30, 50, 70), 
#     labels=c("1960", "1980", "2000", "2020"), 
#     sec.axis = ggplot2::sec_axis(~ 2021 - ., name = "Year (backward)",
#                                  breaks = 1950 + c(10, 30, 50, 70))) +
#   ggplot2::theme(axis.title.x = ggplot2::element_text(colour = "red"), 
#     axis.text.x = ggplot2::element_text(colour = "red"),
#     axis.title.x.top = ggplot2::element_text(colour = "blue"), 
#     axis.text.x.top = ggplot2::element_text(colour = "blue"))

[Package RecordTest version 2.2.0 Index]