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, ...)

Arguments

type

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.

n

vector of two positive integers, indicating the number of grid points at which the density is evaluated on the x and y axes.

bw

vector with two positive entries, indicating the bandwidth to be used by the kernel density estimator of p(x1, x2) along x1 and x2.

tol

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.

trans

the density on x-y is transformed using this function before being plotted.

...

graphical arguments to be passed to ggplot2::geom_raster.

Value

An object of class gamLayer.

Details

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 also