Last data update: 2014.03.03

R: Kernel density estimation for classified data
dclassR Documentation

Kernel density estimation for classified data

Description

Kernel density estimation for classified data

Usage

dclass(xclass, classes, burnin = 2, samples = 5, boundary = FALSE,
  bw = "nrd0", evalpoints = 200, adjust = 1)

Arguments

xclass

classified values; factor with ordered factor values

classes

numeric vector of classes; Inf as last value is allowed

burnin

burn-in sample size

samples

sampling iteration size

boundary

TRUE for positive only data (no positive density for negative values)

bw

bandwidth selector method, defaults to "nrd0" see density for more options

evalpoints

number of evaluation grid points

adjust

as in density, the user can multiply the bandwidth by a certain factor such that bw=adjust*bw

Value

The function returns a list object with the following objects (besides all input objects):

Mestimates

kde object containing the corrected density estimate

gridx

Vector Grid on which density is evaluated

resultDensity

Matrix with Estimated Density for each iteration

resultX

Matrix of true latent values X estimates

Examples

x=rlnorm(500, meanlog = 8, sdlog = 1)
classes <- c(0,500,1000,1500,2000,2500,3000,4000,5000,6000,8000,10000,15000,Inf)
xclass <- cut(x,breaks=classes)
densityEst <- dclass(xclass=xclass, classes=classes, burnin=2, samples=5, evalpoints=1000)
hist(densityEst$xclass,breaks=densityEst$classes)
lines(densityEst$Mestimates~densityEst$gridx,col="purple",lwd=2)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Kernelheaping)
Loading required package: MASS
Loading required package: ks
Loading required package: KernSmooth
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
Loading required package: misc3d
Loading required package: mvtnorm
Loading required package: rgl
Loading required package: sparr
Loading required package: spatstat
Loading required package: nlme
Loading required package: rpart

spatstat 1.45-2       (nickname: 'Caretaker Mode') 
For an introduction to spatstat, type 'beginner' 


Attaching package: 'spatstat'

The following object is masked from 'package:MASS':

    area



Welcome to 'sparr': SPAtial Relative Risk (v0.3-8)
T.M. Davies, M.L. Hazelton & J.C. Marshall
-type 'help("sparr")' for details
-type 'citation("sparr")' for how to cite use of this package

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Kernelheaping/dclass.Rd_%03d_medium.png", width=480, height=480)
> ### Name: dclass
> ### Title: Kernel density estimation for classified data
> ### Aliases: dclass
> 
> ### ** Examples
> 
> x=rlnorm(500, meanlog = 8, sdlog = 1)
> classes <- c(0,500,1000,1500,2000,2500,3000,4000,5000,6000,8000,10000,15000,Inf)
> xclass <- cut(x,breaks=classes)
> densityEst <- dclass(xclass=xclass, classes=classes, burnin=2, samples=5, evalpoints=1000)
[1] "Iteration: 1 of 7"
[1] "Iteration: 2 of 7"
[1] "Iteration: 3 of 7"
[1] "Iteration: 4 of 7"
[1] "Iteration: 5 of 7"
[1] "Iteration: 6 of 7"
[1] "Iteration: 7 of 7"
> hist(densityEst$xclass,breaks=densityEst$classes)
> lines(densityEst$Mestimates~densityEst$gridx,col="purple",lwd=2)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>