Title: | Kernel Density Estimation |
---|---|
Description: | A collection of functions related to density estimation by using Chen's (2000) idea. Mean Squared Errors (MSE) are calculated for estimated curves. For this purpose, R functions allow the distribution to be Gamma, Exponential or Weibull. For details see Chen (2000), Scaillet (2004) <doi:10.1080/10485250310001624819> and Khan and Akbar. |
Authors: | Javaria Ahmad Khan, Atif Akbar. |
Maintainer: | Javaria Ahmad Khan <[email protected]> |
License: | GPL-2 |
Version: | 1.5.5 |
Built: | 2025-02-14 04:10:40 UTC |
Source: | https://github.com/cran/AsyK |
A collection of functions related to density estimation by using Chen's (2000) idea. For observing estimated values see Laplace
and RIG
. Plots by using these kernels can be drawn by plot.Laplace
and plot.RIG
. Mean squared errors (MSE) can be calculated by mse
.
Here we also present a normal scale rule bandwidth which is given by Silverman (1986) for non-normal data.
Kernel Density Estimation
Javaria Ahmad Khan, Atif Akbar.
Useful links:
Estimated Kernel density values by using Laplace Kernel.
Laplace(x = NULL, y, k = NULL, h = NULL)
Laplace(x = NULL, y, k = NULL, h = NULL)
x |
scheme for generating grid points |
y |
a numeric vector of positive values. |
k |
gird points. |
h |
the bandwidth |
Laplace kernel is developed by Khan and Akbar. Kernel is developed by using Chen's idea. Laplace kernel is;
x |
grid points |
y |
estimated values of density |
Javaria Ahmad Khan, Atif Akbar.
Khan, J. A.; Akbar, A. Density Estimation by Laplace Kernel. Working paper, Department of Statistics, Bahauddin Zakariya University, Multan, Pakistan.
To examine Laplace density plot see plot.Laplace
and for Mean Squared Error mse
. Similarly, for RIG kernel RIG
.
#Data can be simulated or real data ## Number of grid points "k" should be at least equal to the data size. ### If user define the generating scheme of gridpoints than number of gridpoints should ####be equal or greater than "k" ###### otherwise NA will be produced. y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) h <- 2 den <- Laplace(x = xx, y = y, k = 200, h = h) ##If scheme for generating gridpoints is unknown y <- rexp(50, 1) h <- 3 den <- Laplace(y = y, k = 90, h = h) ##If user do not mention the number of grid points y <- rexp(23, 1) xx <- seq(min(y) + 0.05, max(y), length = 90) ## Not run: #any bandwidth can be used require(KernSmooth) h <- dpik(y) den <- Laplace(x = xx, y = y, h = h) ## End(Not run) #if bandwidth is missing y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- Laplace(x = xx, y = y, k = 90)
#Data can be simulated or real data ## Number of grid points "k" should be at least equal to the data size. ### If user define the generating scheme of gridpoints than number of gridpoints should ####be equal or greater than "k" ###### otherwise NA will be produced. y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) h <- 2 den <- Laplace(x = xx, y = y, k = 200, h = h) ##If scheme for generating gridpoints is unknown y <- rexp(50, 1) h <- 3 den <- Laplace(y = y, k = 90, h = h) ##If user do not mention the number of grid points y <- rexp(23, 1) xx <- seq(min(y) + 0.05, max(y), length = 90) ## Not run: #any bandwidth can be used require(KernSmooth) h <- dpik(y) den <- Laplace(x = xx, y = y, h = h) ## End(Not run) #if bandwidth is missing y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- Laplace(x = xx, y = y, k = 90)
This function calculates the mean squared error (MSE) by using user specified kernel.This function is same as provided in package "DELTD". For details see https://CRAN.R-project.org/package=DELTD.
MSE(kernel, type)
MSE(kernel, type)
kernel |
type of kernel which is to be used |
type |
mention distribution of vector.If exponential distribution then use |
Mean Squared Error (MSE)
Javaria Ahmad Khan, Atif Akbar.
https://CRAN.R-project.org/package=DELTD
Calculate Bandwidth proposed by Silverman for non-normal data.
NSR(y)
NSR(y)
y |
a numeric vector of positive values. |
h
Javaria Ahmad Khan, Atif Akbar.
Silverman, B. W. 1986. Density Estimation. Chapman & Hall/ CRC, London.
y <- rexp(10, 1) NSR(y)
y <- rexp(10, 1) NSR(y)
Plot density by using Laplace Kernel.
## S3 method for class 'Laplace' plot(x, ...)
## S3 method for class 'Laplace' plot(x, ...)
x |
an object of class "Laplace" |
... |
Not presently used in this implementation |
nothing
Javaria Ahmad Khan, Atif Akbar.
Khan, J. A.; Akbar, A. Density Estimation by Laplace Kernel. Working paper, Department of Statistics, Bahauddin Zakariya University, Multan, Pakistan.
To examine Laplace estimated values for density see Laplace
and for Mean Squared Error mse
. Similarly, for plot of Laplace kernel plot.RIG
.
y <- rexp(100, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- Laplace(x = xx, y = y, k = 100, h = h) plot(den, type = "l") ##other details can also be added y <- rexp(100, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) den <- Laplace(x = xx, y = y, k = 100, h = h) plot(den, type = "s", ylab = "Density Function", lty = 1, xlab = "Time") ## To add true density along with estimated d1 <- density(y, bw = h) lines(d1, type = "p", col = "red") legend("topright", c("Real Density", "Density by RIG Kernel"), col = c("red", "black"), lty = c(1, 2))
y <- rexp(100, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- Laplace(x = xx, y = y, k = 100, h = h) plot(den, type = "l") ##other details can also be added y <- rexp(100, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) den <- Laplace(x = xx, y = y, k = 100, h = h) plot(den, type = "s", ylab = "Density Function", lty = 1, xlab = "Time") ## To add true density along with estimated d1 <- density(y, bw = h) lines(d1, type = "p", col = "red") legend("topright", c("Real Density", "Density by RIG Kernel"), col = c("red", "black"), lty = c(1, 2))
Plot density by using Reciprocal Inverse Gaussian Kernel.
## S3 method for class 'RIG' plot(x, ...)
## S3 method for class 'RIG' plot(x, ...)
x |
an object of class "RIG" |
... |
Not presently used in this implementation |
nothing
Javaria Ahmad Khan, Atif Akbar.
Scaillet, O. 2004. Density estimation using inverse and reciprocal inverse Gaussian kernels. Nonparametric Statistics, 16, 217-226.
To examine RIG estimated values for density see RIG
and for Mean Squared Error mse
. Similarly, for plot of Laplace kernel plot.Laplace
.
y <- rexp(200, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) xx <- seq(min(y) + 0.05, max(y), length = 200) den <- RIG(x = xx, y = y, k = 200, h = h) plot(den, type = "l") ##other details can also be added y <- rexp(200, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) den <- RIG(x = xx, y = y, k = 200, h = h) plot(den, type = "s", ylab = "Density Function", lty = 1, xlab = "Time") ## To add true density along with estimated d1 <- density(y, bw = h) lines(d1, type = "p", col = "red") legend("topright", c("Real Density", "Density by RIG Kernel"), col = c("red", "black"), lty = c(1, 2))
y <- rexp(200, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) xx <- seq(min(y) + 0.05, max(y), length = 200) den <- RIG(x = xx, y = y, k = 200, h = h) plot(den, type = "l") ##other details can also be added y <- rexp(200, 1) h <- 0.79 * IQR(y) * length(y) ^ (-1/5) den <- RIG(x = xx, y = y, k = 200, h = h) plot(den, type = "s", ylab = "Density Function", lty = 1, xlab = "Time") ## To add true density along with estimated d1 <- density(y, bw = h) lines(d1, type = "p", col = "red") legend("topright", c("Real Density", "Density by RIG Kernel"), col = c("red", "black"), lty = c(1, 2))
Estimated Kernel density values by using Reciprocal Inverse Gaussian Kernel.
RIG(x = NULL, y, k = NULL, h = NULL)
RIG(x = NULL, y, k = NULL, h = NULL)
x |
scheme for generating grid points |
y |
a numeric vector of positive values. |
k |
gird points. |
h |
the bandwidth |
Scaillet 2003. proposed Reciprocal Inverse Gaussian kerenl. He claimed that his proposed kernel share the same properties as those of gamma kernel estimator.
x |
grid points |
y |
estimated values of density |
Javaria Ahmad Khan, Atif Akbar.
Scaillet, O. 2004. Density estimation using inverse and reciprocal inverse Gaussian kernels. Nonparametric Statistics, 16, 217-226.
To examine RIG density plot see plot.RIG
and for Mean Squared Error mse
. Similarly, for Laplace kernel Laplace
.
#Data can be simulated or real data ## Number of grid points "k" should be at least equal to the data size. ### If user define the generating scheme of gridpoints than number of gridpoints should ####be equal or greater than "k" ###### otherwise NA will be produced. y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) h <- 2 den <- RIG(x = xx, y = y, k = 200, h = h) ##If scheme for generating gridpoints is unknown y <- rexp(50, 1) h <- 3 den <- RIG(y = y, k = 90, h = h) ## Not run: ##If user do not mention the number of grid points y <- rexp(23, 1) xx <- seq(min(y) + 0.05, max(y), length = 90) #any bandwidth can be used require(KernSmooth) h <- dpik(y) den <- RIG(x = xx, y = y, h = h) ## End(Not run) #if bandwidth is missing y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- RIG(x = xx, y = y, k = 90)
#Data can be simulated or real data ## Number of grid points "k" should be at least equal to the data size. ### If user define the generating scheme of gridpoints than number of gridpoints should ####be equal or greater than "k" ###### otherwise NA will be produced. y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) h <- 2 den <- RIG(x = xx, y = y, k = 200, h = h) ##If scheme for generating gridpoints is unknown y <- rexp(50, 1) h <- 3 den <- RIG(y = y, k = 90, h = h) ## Not run: ##If user do not mention the number of grid points y <- rexp(23, 1) xx <- seq(min(y) + 0.05, max(y), length = 90) #any bandwidth can be used require(KernSmooth) h <- dpik(y) den <- RIG(x = xx, y = y, h = h) ## End(Not run) #if bandwidth is missing y <- rexp(100, 1) xx <- seq(min(y) + 0.05, max(y), length = 100) den <- RIG(x = xx, y = y, k = 90)