Learn R Programming

spedecon (version 0.1)

compute_ephemera: Pre-computations for sped

Description

compute_ephemera() does data-independent pre-computations for sped and can speed up repeated applications

Usage

compute_ephemera(gtwid, hn, padding, spline_dim, perknot = 2)

Value

Object of class spedecon_ephemera, a list containing the pre-computed values.

Arguments

gtwid

Object of class spedecon_gtwid describing the density of \(Z\) in the model \(Y = X + Z\)

hn

Object of class histogram holding any histogram with the desired bins. The bins must be equally-spaced, i.e. hn$equidist must be TRUE, but otherwise only hn$breaks and hn$mids are used.

padding

Support of spline space is extended by padding/2 beyond the data on each side

spline_dim

Numeric integer, dimension of spline space

perknot

Number of positivity constraints per knot

Details

The computations in sped rely on several matrices and vectors that are determined by the error density, spline space, and histogram bins, but do not depend on the data. Computing these is the most time-intensive element of the process, so if the estimator will be applied several times to different data, but the same error density, spline space, and histogram bins (likely in simulations), gains can be had by pre-computing those matrices and vectors just one time.

For comparison, the sped function internally uses padding = 0.4, and perknot = 2.

References

Kent D, Ruppert D (2023). “Smoothness-Penalized Deconvolution (SPeD) of a Density Estimate.” Journal of the American Statistical Association, to appear. ISSN 0162-1459, tools:::Rd_expr_doi("10.1080/01621459.2023.2259028")

Examples

Run this code
alpha <- 1e-3; n <- 1e3; s <- 0.3
Y <- rgamma(n,5,2) + rnorm(n,0,s)
gtwid <- gaussian_gtwid(sd=s)
hn <- hist(Y,breaks="FD",plot=FALSE)
ephemera <- compute_ephemera(gtwid=gtwid,hn=hn,padding=0.4,spline_dim=30,perknot=2)
sol1 <- sped(Y,gtwid,1e-3,ephemera=ephemera) # fast
sol2 <- sped(Y,gtwid,1e-3) # slow
attr(sol1,"coef") - attr(sol2,"coef")

Run the code above in your browser using DataLab