Title: | Creation of Empirical Density Functions Based on Multivariate Data |
---|---|
Description: | Based on the input data an n-dimensional cube with sub cells of user specified side length is created. The number of sample points which fall in each sub cube is counted, and with the cell volume and overall sample size an empirical probability can be computed. A number of cubes of higher resolution can be superimposed. The basic method stems from J.L. Bentley in "Multidimensional Divide and Conquer". J. L. Bentley (1980) <doi:10.1145/358841.358850>. Furthermore a simple kernel density estimation method is made available, as well as an expansion of Bentleys method, which offers a kernel approach for the grid method. |
Authors: | Martin Wiegand, Saralees Nadarajah |
Maintainer: | Martin Wiegand <[email protected]> |
License: | GPL-2 |
Version: | 3.0 |
Built: | 2024-10-31 19:53:01 UTC |
Source: | CRAN |
Single grid size empirical density function. To be used to construct the epdf function.
cube(data,mx,mn,grid.sizes)
cube(data,mx,mn,grid.sizes)
data |
N-dimensional data set. |
mx |
Upper cropping point of the data. |
mn |
Lower cropping point of the data. |
grid.sizes |
Vector of grid sizes for the grid. |
library("pracma") library("plyr") data<-cbind(rnorm(1000),rnorm(1000)) pdf<-cube(data,mx=c(1,1),mn=c(-1,-1),grid.sizes = c(0.01,0.01))
library("pracma") library("plyr") data<-cbind(rnorm(1000),rnorm(1000)) pdf<-cube(data,mx=c(1,1),mn=c(-1,-1),grid.sizes = c(0.01,0.01))
Kernel function based on the normal distribution.
ekde(x,data,H,rule,kernel)
ekde(x,data,H,rule,kernel)
x |
Evaluation point. |
data |
Input data. |
H |
Positive-definite, symmetric matrix as bandwidth. |
rule |
In absence of a bandwidth matrix a rule-of-thumb can be chosen, either the "silverman" or "scott" rule. |
kernel |
The kernel function of choice. |
library("pracma") library("plyr") data<-cbind(rnorm(1000),rnorm(1000)) pdf<-ekde(x = 0,data = data, rule = "silverman",kernel = normkernel)
library("pracma") library("plyr") data<-cbind(rnorm(1000),rnorm(1000)) pdf<-ekde(x = 0,data = data, rule = "silverman",kernel = normkernel)
Kernel function based on the normal distribution.
epakernel(x,H)
epakernel(x,H)
x |
Evaluation point. |
H |
Positive-definite, symmetric matrix as bandwidth. |
epakernel(c(1,1),H = diag(2))
epakernel(c(1,1),H = diag(2))
Assembles main grid and superimposes grids of different resolution.
epdf(data,max.corner,min.corner,main.gridsize,rescubes)
epdf(data,max.corner,min.corner,main.gridsize,rescubes)
data |
N-dimensional data set. |
max.corner |
Upper cropping point of the data. |
min.corner |
Lower cropping point of the data. |
main.gridsize |
Vector of grid sizes for the main grid. |
rescubes |
List of upper and lower cropping points, as well as grid sizes for cubes that are to be superimposed |
library("pracma") library("plyr") a<-list(c(-1,-1),c(1,1),c(0.01,0.01)) b<-list(c(-2,-2),c(2,2),c(0.02,0.02)) cubes<-list(a,b) min.corner = c(-4,-4) max.corner= c(4,4) main.gridsize = c(0.05,0.05) # Data & Density data<-cbind(rnorm(1000),rnorm(1000)) pdf<-epdf(data,max.corner,min.corner,main.gridsize,rescubes = cubes)
library("pracma") library("plyr") a<-list(c(-1,-1),c(1,1),c(0.01,0.01)) b<-list(c(-2,-2),c(2,2),c(0.02,0.02)) cubes<-list(a,b) min.corner = c(-4,-4) max.corner= c(4,4) main.gridsize = c(0.05,0.05) # Data & Density data<-cbind(rnorm(1000),rnorm(1000)) pdf<-epdf(data,max.corner,min.corner,main.gridsize,rescubes = cubes)
Kernel function based on the Epanechnikov kernel.
normkernel(x,H)
normkernel(x,H)
x |
Evaluation point. |
H |
Positive-definite, symmetric matrix as bandwidth. |
normkernel(c(1,1),H = diag(2))
normkernel(c(1,1),H = diag(2))
Single grid size empirical density function. Offers a modified kernel density approach via the optional argument "rings"
pseudokernel(data,mn,mx,grid.sizes,rings)
pseudokernel(data,mn,mx,grid.sizes,rings)
data |
N-dimensional data set. |
mx |
Upper cropping point of the data. |
mn |
Lower cropping point of the data. |
grid.sizes |
Vector of grid sizes for the grid. |
rings |
Number of additional cell grid smoothing layers. |
data<-mvtnorm::rmvnorm(n = 100,mean = c(0,0),sigma = diag(2)) pdf<-pseudokernel(data = data,mn = c(-2,-2),mx = c(2,2),grid.sizes = c(0.1,0.1),rings = 1)
data<-mvtnorm::rmvnorm(n = 100,mean = c(0,0),sigma = diag(2)) pdf<-pseudokernel(data = data,mn = c(-2,-2),mx = c(2,2),grid.sizes = c(0.1,0.1),rings = 1)