% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/EL.R
\name{EL.plot}
\alias{EL.plot}
\title{Draws plots using the smoothed two-sample empirical likelihood method}
\usage{
EL.plot(
  method,
  X,
  Y,
  bw = bw.nrd0,
  conf.level = NULL,
  simultaneous = FALSE,
  bootstrap.samples = 300,
  more.warnings = FALSE,
  ...
)
}
\arguments{
\item{method}{One of \code{"pp"}, \code{"qq"}, \code{"roc"}, \code{"qdiff"},
or \code{"fdiff"}.}

\item{X}{A numeric vector of data values.}

\item{Y}{A numeric vector of data values.}

\item{bw}{A function taking a numeric vector and returning a bandwidth, or a
numeric vector of length two giving the bandwidths for \code{X} and \code{Y}
respectively. Default is \code{\link[stats]{bw.nrd0}}.}

\item{conf.level}{Confidence level for the intervals, a number in \eqn{(0,1)},
or \code{NULL} to skip confidence band calculation.}

\item{simultaneous}{Logical. If \code{TRUE}, simultaneous confidence bands are
constructed via a nonparametric bootstrap. Default is \code{FALSE} (pointwise
intervals).}

\item{bootstrap.samples}{Integer. Number of bootstrap samples used when
\code{simultaneous = TRUE}. Default is \code{300}.}

\item{more.warnings}{Logical. If \code{FALSE} (default), a single warning is
issued if any problem occurs. If \code{TRUE}, a warning is produced for every
point with a problem.}

\item{...}{Further arguments passed to the plot function.}
}
\value{
A \code{ggplot} object. The plot can be further customized using
  \pkg{ggplot2} functions, as shown in the examples.
}
\description{
Draws P-P and Q-Q plots, ROC curves, quantile differences (\code{qdiff}) and
CDF differences (\code{ddiff}) and their respective confidence bands (pointwise
or simultaneous) using the empirical likelihood method.
}
\details{
The plotting interval for P-P plots, ROC curves and differences of quantile
functions is \eqn{[0, 1]}. The Q-Q plot is drawn from the minimum to the
maximum of \code{Y}. For the plot of distribution function differences the
interval from \eqn{\max(\min(X), \min(Y))} to \eqn{\min(\max(X), \max(Y))}
is used.

Confidence bands are drawn only if \code{conf.level} is not \code{NULL}.

When constructing simultaneous confidence bands, the plot is drawn on an
interval narrowed by 5\% on both sides, since the procedure is usually
sensitive at the endpoints. The confidence level is bootstrapped using 50
evenly spaced points in this interval. If the default interval produces
excessively wide bands, use \code{\link{EL.smooth}} where intervals are
specified manually. Note that calculation of simultaneous confidence bands
can be slow.
}
\examples{
## The examples showcase all available graphs
set.seed(42)
X1 <- rnorm(100, 0.5, 1.5)
X2 <- rnorm(100, 0, 1)

\donttest{
xlim <- c(min(X1, X2) - 0.5, max(X1, X2) + 0.5)
D1 <- density(X1)
D2 <- density(X2)
df <- data.frame(x1 = D1$x, y1 = D1$y, x2 = D2$x, y2 = D2$y)
p1 <- ggplot2::ggplot(data = df) +
    ggplot2::geom_line(ggplot2::aes(x = x2, y = y2,
        color = paste0('X2 (bw=', round(D2$bw, 2), ')'))) +
    ggplot2::geom_line(ggplot2::aes(x = x1, y = y1,
        color = paste0('X1 (bw=', round(D1$bw, 2), ')'))) +
    ggplot2::guides(color = ggplot2::guide_legend(title = NULL)) +
    ggplot2::theme_minimal() +
    ggplot2::theme(legend.position = "top") +
    ggplot2::labs(x = "X", y = "Density")
p1

# CDF differences
p2 <- EL.plot("fdiff", X1, X2, main = "F difference", conf.level = 0.95)
tt <- seq(max(c(min(X1), min(X2))), min(c(max(X1), max(X2))), length = 30)
ee <- ecdf(X2)(tt) - ecdf(X1)(tt)
p2 <- p2 + ggplot2::geom_point(data = data.frame(tt = tt, ee = ee),
                                ggplot2::aes(x = tt, y = ee))
p2

# Quantile differences
p3 <- EL.plot("qdiff", X1, X2, main = "Quantile difference", conf.level = 0.95)
tt <- seq(0.01, 0.99, length = 30)
ee <- quantile(X2, tt) - quantile(X1, tt)
p3 <- p3 + ggplot2::geom_point(data = data.frame(tt = tt, ee = ee),
                                ggplot2::aes(x = tt, y = ee))
p3

# Q-Q plot
p4 <- EL.plot("qq", X1, X2, main = "Q-Q plot", conf.level = 0.95)
tt <- seq(min(X2), max(X2), length = 30)
ee <- quantile(X1, ecdf(X2)(tt))
p4 <- p4 + ggplot2::geom_point(data = data.frame(tt = tt, ee = ee),
                                ggplot2::aes(x = tt, y = ee))
p4

# P-P plot
p5 <- EL.plot("pp", X1, X2, main = "P-P plot", conf.level = 0.95, ylim = c(0, 1))
tt <- seq(0.01, 0.99, length = 30)
ee <- ecdf(X1)(quantile(X2, tt))
p5 <- p5 + ggplot2::geom_point(data = data.frame(tt = tt, ee = ee),
                                ggplot2::aes(x = tt, y = ee))
p5

# ROC curve
p6 <- EL.plot("roc", X1, X2, main = "ROC curve", conf.level = 0.95, ylim = c(0, 1))
tt <- seq(0.01, 0.99, length = 30)
ee <- 1 - ecdf(X1)(quantile(X2, 1 - tt))
p6 <- p6 + ggplot2::geom_point(data = data.frame(tt = tt, ee = ee),
                                ggplot2::aes(x = tt, y = ee))
p6

# To show all plots at once:
# require(cowplot)
# cowplot::plot_grid(p1, p2, p3, p4, p5, p6, ncol = 2)
}

}
\references{
Valeinis, J. and Cers, E. Extending the two-sample empirical likelihood.
Preprint: \url{http://home.lu.lv/~valeinis/lv/petnieciba/EL_TwoSample_2011.pdf}

Hall, P. and Owen, A. (1993). Empirical likelihood bands in density estimation.
\emph{Journal of Computational and Graphical Statistics}, \strong{2}(3), 273--289.
}
\seealso{
\code{\link{EL.smooth}}, \code{\link{EL.statistic}}
}
\author{
E. Cers, J. Valeinis
}
\keyword{hplot}
\keyword{nonparametric}
\keyword{smooth}
