update.distfreereg {distfreereg} | R Documentation |
Update distfreereg
Objects
Description
This is an update
method for objects of class distfreereg
. The method takes advantage of the override
argument of distfreereg
to prevent unnecessary recalculation of potentially computationally expensive objects.
Usage
## S3 method for class 'distfreereg'
update(object, ..., smart = TRUE, envir = parent.frame())
Arguments
object |
Object of class |
... |
Additional named parameters to pass to |
smart |
Logical. If |
envir |
Environment passed to |
Details
This function updates an object of class distfreereg
. By default, it does so "intelligently" in the sense that it does not unnecessarily recompute elements that are already saved in object
. For example, if a new value for covariance
is not included in ...
, then the value of covariance
saved in object
is automatically passed to the new call, preventing recalculating Q
. If a new value of covariance
is specified, then all objects dependent on that (e.g., \hat\theta
) are recomputed.
In particular, the simulated samples depend on the data and function only through the number of observations, the covariates (if any), and the dimension of the parameter space of the function. If none of these change, then the updated object reuses the simulated samples from the supplied object
.
The price we pay for this efficiency is a potentially "large" value of call
in the updated object.
Value
An updated object of class distfreereg
.
Note
The default behavior of update
is to create an updated call and then evaluate that call. This means, among other things, that a call to update
made after one of the arguments in the original call is modified will use the modified version of that argument. This is not always true for update.distfreereg
. Values for the override arguments are drawn from the distfreereg
object itself, not from any objects used as values for the original call to distfreereg
.
In general, an object created by update.distfreereg
will therefore not be identical
to the object created by distfreereg
using corresponding arguments, because the call
values will differ.
Author(s)
Jesse Miller
See Also
Examples
set.seed(20240218)
n <- 1e2
func <- function(X, theta) X[,1]^theta[1] + theta[2]*X[,2]
Sig <- runif(n, min = 1, max = 3)
theta <- c(2,5)
X <- matrix(runif(2*n, min = 1, max = 5), nrow = n)
Y <- X[,1]^theta[1] + theta[2]*X[,2] + rnorm(n, sd = sqrt(Sig))
dfr_1 <- distfreereg(Y = Y, X = X, test_mean = func,
covariance = list(Sigma = Sig),
theta_init = c(1,1))
func_updated <- function(X, theta) X[,1]^theta[1] + theta[2]*X[,2]^2
dfr_2 <- update(dfr_1, test_mean = func_updated)
# The following are identical, since the Monte Carlo simulation did not need to
# be rerun for dfr_2, and was therefore copied from dfr_1.
identical(dfr_1$mcsim_stats, dfr_2$mcsim_stats)