CreateDensity: Create density from raw data

Description Usage Arguments Details Value References Examples

Description

Create kernel density estimate along the support of the raw data using the HADES method

Usage

1
CreateDensity(y, optns = list())

Arguments

y

A vector of raw readings.

optns

A list of options control parameters specified by list(name=value). See ‘Details’.

Details

Available control options are

userBwMu

The bandwidth value for the smoothed mean function (using 'CV' or 'GCV'); positive numeric - default: determine automatically based on CV

nRegGrid

The number of support points the KDE; numeric - default: 101

delta

The size of the bin to be used; numeric - default: determine automatically as "max(c(diff(range(y))/1000, min(diff(sort(unique(y))))))"

kernel

smoothing kernel choice, "rect", "gauss", "epan", "gausvar", "quar" - default: "gauss"

infSupport

logical if we expect the distribution to have infinite support or not; logical - default: TRUE

outputGrid

User defined output grid for the support of the KDE, it overrides nRegGrid; numeric - default: NULL

Value

A list containing the following fields:

bw

Variance for measure error.The bandwidth used by smoothing.

x

A vector of length nGridReg with the values of the KDE's support points.

y

A vector of length nGridReg with the values of the KDE at the support points.

References

HG Mueller, JL Wang and WB Capra (1997). "From lifetables to hazard rates: The transformation approach." Biometrika 84, 881-892.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
par(mfrow=c(1,2))
makeComparisonPlotE <- function(N, mySeed = 123){
  set.seed(mySeed)
  asdf2  = (rexp(N, rate = 1.5))
  plot(density(asdf2, bw = "SJ"), main= "Exponential (rate=1.5)", 
    xlab = paste0(collapse = '', c( "N = ", as.character(N))) , ylim = c(0, 1.45))
  lines(density(asdf2), col='red')
  Unormal = CreateDensity(y = asdf2, optns = list(infSupport = FALSE))
  lines(col='green', x = Unormal$x, y = Unormal$y)
  lines(col='magenta' , Unormal$x, dexp(Unormal$x, rate = 1.5))
  abline(v = min(asdf2))
  abline(v = max(asdf2))
  legend(legend = c("SJ", "R-default", "HADES-like", "True PDF"),
    lwd= 2, col=c("black", "red", "green", "magenta"), bty = 'n', 'topright')
}

makeComparisonPlotE(100)
makeComparisonPlotE(2000)

functionaldata/tDENS documentation built on May 16, 2019, 3:38 p.m.