The goal of rlcv is to provide a robust likelihood cross validation bandwidth selector for kernel density estimation. It allows for both uni-variate and multi-variate densities. It is resistant against fat-tailed distributions and outliers.
You can install the development version of rlcv like so:
install.packages('rlcv')
This is a basic example which shows you how to use rlcv
to fit a fat-tailed bivariate distribution:
library(rlcv)
## basic example code
# fat-tailed marginals + fat-tailed copula
library(copula)
=tCopula(.5,df=5)
ncop=500
n=rCopula(n,ncop)
u=qt(u[,1],5)
x1=qt(u[,2],5)
x2=cbind(x1,x2)
x=rlcv_d(x.obs=x)
fit# evaluation data
=x2=seq(-5,5,length=50)
x1=rep(x1,each=50)
x11=rep(x2,50)
x22=kde_d(x.new=cbind(x11,x22),x.obs=x,,h=fit$h)
fhat=dCopula(cbind(pt(x11,5),pt(x22,5)),ncop)*dt(x11,5)*dt(x22,5)
f0# Mean squared errors
mean((f0-fhat)^2)
#> [1] 2.131485e-05
persp(x1,x2,matrix(fhat,50,50))
contour(x1,x2,matrix(fhat,50,50))
contour(x1,x2,matrix(f0,50,50),add=TRUE,col='red')