enhance
enhances the sandwich smoother by choosing
the optimal penalty value that minimizes the GCV
statistic. The optimx
function
is used to do the optimization.
enhance(
obj,
par = rep(0, length(obj$n)),
lower = rep(-20, length(par)),
upper = rep(20, length(par)),
method = "L-BFGS-B",
control = list(),
prepare = TRUE,
loggcv = FALSE,
...
)
By default, a prepared_data
object with
the optimal loglambda
values that minimize the
GCV, along with an additional component,
results
, that contains the optimization results.
A prepared_*
object from a
prepare
function.
a vector of initial values for the parameters for which optimal values are to be found. Names on the elements of this vector are preserved and used in the results data frame.
Bounds on the variables for methods such as "L-BFGS-B"
that can
handle box (or bounds) constraints.
The method to be used for optimization. The
default is L-BFGS-B
, which allows for
constraints on the parameters to optimize. See
optimx
for all available methods.
A list of control parameters. See ‘Details’.
A logical value. The default is TRUE
,
indicating that a prepared_data
object should be
returned. If FALSE
, then the results of the
call to the optimx
function is
returned.
A logical value indicating whether the log
of the GCV statistic should be used. Useful for very large
data sets. Default is TRUE
.
Additional arguments to pass to to the
optimx
function.
Joshua French
Internally, the loglambda2gcv
is used as
the objective function for the
optimx
function. Many different
optimization methods are available. The default is
L-BFGS-B
, which allows for constraints on the
parameters to optimize. Another excellent choice is the
nlminb
algorithm, which also allows for parameter
constraints.
# create b-splines
x1 = bspline(nbasis = 10)
x2 = bspline(nbasis = 12)
# observed data locations
evalarg1 = seq(0, 1, len = 60)
evalarg2 = seq(0, 1, len = 80)
# construct "true" data
mu = matrix(0, nrow = 60, ncol = 80)
for(i in seq_len(60)) {
for(j in seq_len(80)) {
mu[i, j] = sin(2*pi*(evalarg1[i]-.5)^3)*cos(4*pi*evalarg2[j])
}
}
# construct noisy data
data = mu + rnorm(60 * 80)
obj = prepare(data, list(evalarg1, evalarg2), list(x1, x2))
enhance(obj)
Run the code above in your browser using DataLab