This layer adds a 2D density estimate heat-map to a plot.
For 1D effect plots, it adds either the conditional density of the partial
residuals, p(r|x)
, or the joint density p(r, x)
. For 2D
effect plots it adds either p(x1|x2)
or p(x1, x2)
, where
x1
and x2
are the relevant covariates.
l_dens2D(type, n = c(50, 50), bw = NULL, tol = 1e-06, trans = sqrt, ...)l_dens(type, n = c(50, 50), bw = NULL, tol = 1e-06, trans = sqrt, ...)
An object of class gamLayer
.
for 1D effect plots, if set to "cond" then the conditional residual
density p(r|x)
is plotted. If set to "joint" the
joint density of residuals, p(r, x)
, is plotted.
The behaviour is similar for 2D effect plots, but r
indicates
the second covariate, not the residuals.
vector of two positive integers, indicating the number of grid points at which the density is evaluated on the x and y axes.
vector with two positive entries, indicating the bandwidth to be used
by the kernel density estimator of p(x1, x2)
along x1 and x2.
small positive numerical tolerance. The estimated density at a certain
location is set to NA
(hence it will appear white) when it falls
below tol/sqrt(2*pi*sig)
, where sig
is the standard
deviation of the residuals. Set tol
to -1 plot the density on
the whole x-y plane, no matter how low it is.
the density on x-y is transformed using this function before being plotted.
graphical arguments to be passed to ggplot2::geom_raster
.
The density function is estimated using the fast binned kernel density estimation
methods provided by the KernSmooth
package, hence this function should be
able to handle relatively large datasets (~ 10^6 observations).
See plot.mgcv.smooth.1D, plot.mgcv.smooth.2D and check1D for examples.