View source: R/lpdensity_methods.R
plot.lpdensity | R Documentation |
The plot method for local polynomial density objects.
## S3 method for class 'lpdensity'
plot(
...,
alpha = NULL,
type = NULL,
lty = NULL,
lwd = NULL,
lcol = NULL,
pty = NULL,
pwd = NULL,
pcol = NULL,
grid = NULL,
CItype = NULL,
CIuniform = FALSE,
CIsimul = 2000,
CIshade = NULL,
CIcol = NULL,
hist = FALSE,
histData = NULL,
histBreaks = NULL,
histFillCol = 3,
histFillShade = 0.2,
histLineCol = "white",
title = NULL,
xlabel = NULL,
ylabel = NULL,
legendTitle = NULL,
legendGroups = NULL
)
... |
Class "lpdensity" object, obtained from calling |
alpha |
Numeric scalar between 0 and 1, specifies the significance level for plotting confidence intervals/bands. If more than one is provided, they will be applied to each data series accordingly. |
type |
String, one of |
lty |
Line type for point estimates, only effective if |
lwd |
Line width for point estimates, only effective if |
lcol |
Line color for point estimates, only effective if |
pty |
Scatter plot type for point estimates, only effective if |
pwd |
Scatter plot size for point estimates, only effective if |
pcol |
Scatter plot color for point estimates, only effective if |
grid |
Numeric vector, specifies a subset of grid points
to plot point estimates. This option is effective only if |
CItype |
String, one of |
CIuniform |
|
CIsimul |
Positive integer, specifies the number of simulations used to construct critical values (default is |
CIshade |
Numeric, specifies the opaqueness of the confidence region, should be between 0 (transparent) and 1. Default is 0.2. If more than one is provided, they will be applied to each data series accordingly. |
CIcol |
Color of the confidence region. |
hist |
|
histData |
Numeric vector, specifies the data used to construct the histogram plot. |
histBreaks |
Numeric vector, specifies the breakpoints between histogram cells. |
histFillCol |
Color of the histogram cells. |
histFillShade |
Opaqueness of the histogram cells, should be between 0 (transparent) and 1. Default is 0.2. |
histLineCol |
Color of the histogram lines. |
title , xlabel , ylabel |
Strings, specifies the title of the plot and labels for the x- and y-axis. |
legendTitle |
String, specifies the legend title. |
legendGroups |
String vector, specifies the group names used in legend. |
A stadnard ggplot
object is returned, hence can be used for further customization.
Matias D. Cattaneo, Princeton University. cattaneo@princeton.edu.
Michael Jansson, University of California Berkeley. mjansson@econ.berkeley.edu.
Xinwei Ma (maintainer), University of California San Diego. x1ma@ucsd.edu.
lpdensity
for local polynomial density estimation.
Supported methods: coef.lpdensity
, confint.lpdensity
,
plot.lpdensity
, print.lpdensity
, summary.lpdensity
,
vcov.lpdensity
.
# Generate a random sample
set.seed(42); X <- rnorm(2000)
# Generate a density discontinuity at 0
X <- X - 0.5; X[X>0] <- X[X>0] * 2
# Density estimation, left of 0 (scaled by the relative sample size)
est1 <- lpdensity(data = X[X<=0], grid = seq(-2.5, 0, 0.05), bwselect = "imse-dpi",
scale = sum(X<=0)/length(X))
# Density estimation, right of 0 (scaled by the relative sample size)
est2 <- lpdensity(data = X[X>0], grid = seq(0, 2, 0.05), bwselect = "imse-dpi",
scale = sum(X>0)/length(X))
# Plot
plot(est1, est2, legendTitle="My Plot", legendGroups=c("Left", "Right"))
# Plot uniform confidence bands
set.seed(42) # fix the seed for simulating critical values
plot(est1, est2, legendTitle="My Plot", legendGroups=c("Left", "Right"), CIuniform=TRUE)
# Adding a histogram to the background
plot(est1, est2, legendTitle="My Plot", legendGroups=c("Left", "Right"),
hist=TRUE, histBreaks=seq(-2.4, 2, 0.2), histData=X)
# Plot point estimates for a subset of evaluation points
plot(est1, est2, legendTitle="My Plot", legendGroups=c("Left", "Right"),
type="both", CItype="all", grid=seq(-2, 2, 0.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.