Learn R Programming

RecordTest (version 2.0.0)

N.plot: 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 \(t\), \(\bar N_t^\omega\), and the expected values \(\textrm{E}(N_t)\) under the classical record model.

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 = "gray69"
)

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 \(\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 \(t\) for the backward series in times \(\{T,\ldots,1\}\) or the backward number of records shown for every \(t\) are the total number of records in the series with times \(\{t,\ldots,1\}\). While the first option considers the evolution of a series of records observed up to time \(T\), the second considers that until each time \(t\) the series has only been observed up to \(t\).

point.col, point.shape

Vector with four elements indicating the color 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 CIs are also shown.

conf.level

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

conf.aes

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

conf.col

Color used to plot the expected value and (if conf.int == TRUE) CIs.

Value

A ggplot object.

Details

This plot is associated with the N.test test. It calculates the sample means of the number of records in a set of vectors up to every time \(t\) (see Nmean.record). These sample means \(\bar N_t\) are calculated from the sample of \(M\) values obtained from \(M\) vectors, the columns of matrix X. Then, these values are plotted and compared with the expected values \(\textrm{E}(N_t)\) and their confidence intervals (CIs), under the hypothesis of the classical record model. The CIs of \(E(N_t)\) uses the fact that, under the classical record model, the statistic \(\bar N_t\) 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 \(t\) corresponds to the same year of observation, but for the backward series, time \(t\) corresponds to the year of observation \(T-t+1\) where \(T\) 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<U+00E1>n, Castillo-Mateo, As<U+00ED>n (2021).

References

Cebri<U+00E1>n A, Castillo-Mateo J, As<U+00ED>n J (2021). <U+201C>Record Tests to detect non stationarity in the tails with an application to climate change.<U+201D> Unpublished manuscript.

See Also

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

Examples

Run this code
# NOT RUN {
# Plot at Zaragoza, with linear weights and error bar as CIs 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 color 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 = "Forward (Year)", 
#   breaks = c(8, 28, 48, 68), 
#   labels=c("1960", "1980", "2000", "2020"), 
#   sec.axis = ggplot2::sec_axis(~ nrow(ZaragozaSeries) - . + 1953, name = "Backward (Year)")) +
# ggplot2::theme(axis.title.x = ggplot2::element_text(color = "red"), 
#   axis.text.x = ggplot2::element_text(color = "red"),
#   axis.title.x.top = ggplot2::element_text(color = "blue"), 
#   axis.text.x.top = ggplot2::element_text(color = "blue"))
# }

Run the code above in your browser using DataLab