prepare.numeric {hero} | R Documentation |
Prepare data vector for sandwich smooth
Description
prepare.vector
prepares a data vector for the
sandwich smooth. Unlike the other prepare.*
functions, x
and splines
do not
need to be lists since the data are 1-dimensional.
Usage
## S3 method for class 'numeric'
prepare(data, x, splines, m = 2, sparse = TRUE, ...)
Arguments
data |
A numeric data vector |
x |
A sequence of equidistant values corresponding to where the data are observed. Equidistant spacing between 0 and 1 is assumed if not supplied. See Details. |
splines |
A spline-related object, e.g.,
produced by |
m |
A positive integer indicating order of the difference penalty. |
sparse |
A logical value indicating if the result
should be a sparse version of the
|
... |
Not currently implemented. |
Details
If x
is not supplied and n
is
the length(data)
, then the function automatically
sets x = seq(0, 1, length = n)
.
If splines
is not supplied, and n
is the
length(data)
, then the function automatically sets
splines = bspline(range(x), nknots = min(ceiling(n/4), 35))
.
Value
A prepared_numeric
object.
Author(s)
Joshua French. Based off code by Luo Xiao (see References).
References
Xiao, L. , Li, Y. and Ruppert, D. (2013), Fast bivariate P-splines: the sandwich smoother. J. R. Stat. Soc. B, 75: 577-599. <doi:10.1111/rssb.12007>
Ruppert, D., Wand, M. P., & Carroll, R. J. (2003). Semiparametric Regression. Cambridge University Press. <doi:10.1017/CBO9780511755453>
See Also
bspline
,
default.evalargs
,
default.splines
Examples
# create data
n = 160
x = seq(0, 4 * pi, len = n)
# "true" data
mu = sin(x)
# plot true data
plot(x, mu, type = "l")
# construct noisy data
set.seed(4)
data = mu + rnorm(n)
# construct spline
splines = bspline(c(0, 4 * pi), nknots = 20)
# prepare/enhance data
obj = prepare(data, x, splines)
obj = enhance(obj)
sandmod = hero(obj)
plot(sandmod, ylim = range(data), lty = 2)
lines(x, data, col = "lightgrey")
lines(x, mu)
legend("bottomleft",
legend = c("smoothed", "true", "observed"),
lty = c(2, 1, 1),
col = c("black", "black", "grey"))