matrixXD: Construct an 'xDensity' representation of a known...

Description Usage Arguments Value Examples

View source: R/matrixXD.R

Description

Construct an xDensity representation of a known distribution.

Usage

1

Arguments

XY

2-column matrix representation of a univariate density. The first column is a grid of x values giving the centers of bins. The second column are the corresponding densities.

mean, sd

Optional mean and standard deviation of the Normal distribution to use outside the grid values in XY. Defaults to grid-based approximation using XY.

Value

An xDensity object. See xDensity.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# xDensity approximation to a noncentral-t distribution

# true parameters
lambda <- rnorm(1) # noncentrality parameter
nu <- runif(1, 4, 6) # degrees of freedom

# xDensity encoding of known PDF
xlim <- qt(c(.005, .995), df = nu, ncp = lambda) # discretization range
xseq <- seq(xlim[1], xlim[2], len = 200) # where to evaluate density
xDens <- matrixXD(cbind(xseq, dt(xseq, df = nu, ncp = lambda)))

# true vs approximate PDFs
curve(dt(x, df = nu, ncp = lambda),
      from = xlim[1], to = xlim[2], ylab = "Density")
curve(dXD(x, xDens = xDens), add = TRUE, col = "red")
legend("topleft", legend = c("True PDF", "xDensity Approx."),
       fill = c("black", "red"))

mlysy/GaussCop documentation built on Nov. 6, 2019, 6:19 p.m.