Package 'rlcv'

Title: Robust Likelihood Cross Validation Bandwidth Selection
Description: Robust likelihood cross validation bandwidth for uni- and multi-variate kernel densities. It is robust against fat-tailed distributions and/or outliers. Based on "Robust Likelihood Cross-Validation for Kernel Density Estimation," Wu (2019) <doi:10.1080/07350015.2018.1424633>.
Authors: Ximing Wu [aut, cre]
Maintainer: Ximing Wu <[email protected]>
License: GPL (>= 3)
Version: 1.0.0
Built: 2024-11-15 06:35:38 UTC
Source: CRAN

Help Index


Univariate kernel density

Description

Univariate kernel density

Usage

kde(x.obs, x.new = NULL, h)

Arguments

x.obs

Training (observed) data (n1 vector)

x.new

Evaluation data (n2 vector); default to x.obs

h

Bandwidth

Value

Density evaluated at x.new

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

x=rnorm(100)
x.new=seq(-5,5,length=50)
h=1.06*sd(x)*(length(x))^(-1/5)
f=kde(x.new=x.new,x.obs=x,h=h)

Multivariate kernel density

Description

Multivariate kernel density

Usage

kde_d(x.obs, x.new = NULL, h, stud = FALSE)

Arguments

x.obs

Training (observed) data (n1 by d matrix, d>=2)

x.new

Evaluation data (n2 by d matrix, d>=2); default to x.obs

h

Bandwidth (d vector)

stud

Indicator for whether data are studentized; default to FALSE

Details

For multivariate distributions, bandwidth is calculated for studentized data.

Value

Density evaluated at x.new

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

x=matrix(rnorm(200),ncol=2)
x.new=matrix(rnorm(100),ncol=2)
h=c(1,1)
f=kde_d(x.new=x.new,x.obs=x,h=h)

Likelihood cross validation bandwidth for univariate densities

Description

Likelihood cross validation bandwidth for univariate densities

Usage

lcv(x.obs, x.new = NULL)

Arguments

x.obs

Training (observed) data

x.new

Evaluation data; default to x.obs

Value

fhat: density evaluated at x.new; h: bandwidth

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

x=rt(200,df=5)
x.new=seq(-5,5,length=100)
fit=lcv(x.obs=x,x.new=x.new)
# Mean squared errors
f0=dt(x.new,df=5)
mean((f0-fit$fhat)^2)

matplot(x.new,cbind(f0,fit$fhat),type='l')

Likelihood cross validation bandwidth for multivariate kernel densities

Description

Likelihood cross validation bandwidth for multivariate kernel densities

Usage

lcv_d(x.obs, x.new = NULL)

Arguments

x.obs

Training (observed) data (n1 by d matrix, d>=2)

x.new

Evaluation data (n2 by d matrix, d>=2); default to x.obs

Value

fhat: density evaluated at x.new; h: bandwidth

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

# old faithful data
x=datasets::faithful
x=cbind(x[,1],x[,2])
fit=lcv_d(x.obs=x)
# evaluation data
x1=seq(min(x[,1])*.8,max(x[,1])*1.2,length=30)
x2=seq(min(x[,2])*.8,max(x[,2])*1.2,length=30)
x11=rep(x1,each=30)
x22=rep(x2,30)
fhat=kde_d(x.new=cbind(x11,x22),x.obs=x,h=fit$h)
persp(x1,x2,matrix(fhat,30,30))

Robust likelihood cross validation bandwidth for univariate densities

Description

Robust likelihood cross validation bandwidth for univariate densities

Usage

rlcv(x.obs, x.new = NULL)

Arguments

x.obs

Training (observed) data

x.new

Evaluation data; default to x.obs

Value

fhat: density evaluated at x.new; h: bandwidth

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

x=rt(200,df=5)
x.new=seq(-5,5,length=100)
fit=rlcv(x.obs=x,x.new=x.new)
# Mean squared errors
f0=dt(x.new,df=5)
mean((f0-fit$fhat)^2)

matplot(x.new,cbind(f0,fit$fhat),type='l')

Robust likelihood cross validation bandwidth for multivariate kernel densities

Description

Robust likelihood cross validation bandwidth for multivariate kernel densities

Usage

rlcv_d(x.obs, x.new = NULL)

Arguments

x.obs

Training (observed) data (n1 by d matrix, d>=2)

x.new

Evaluation data (n2 by d matrix, d>=2); default to x.obs

Value

fhat: density evaluated at x.new; h: bandwidth

Author(s)

Ximing Wu [email protected]

References

Wu, Ximing (2019), "Robust Likelihood Cross Validation for Kernel Density Estimation," Journal of Business and Economic Statistics, 37(4): 761-770.

Examples

# old faithful data
x=datasets::faithful
x=cbind(x[,1],x[,2])
fit=rlcv_d(x.obs=x)
# evaluation data
x1=seq(min(x[,1])*.8,max(x[,1])*1.2,length=30)
x2=seq(min(x[,2])*.8,max(x[,2])*1.2,length=30)
x11=rep(x1,each=30)
x22=rep(x2,30)
fhat=kde_d(x.new=cbind(x11,x22),x.obs=x,h=fit$h)
persp(x1,x2,matrix(fhat,30,30))