View source: R/dgp-lib-errors.R
generate_errors | R Documentation |
Generate simulated errors from the specified error function and passed arguments.
generate_errors(err = NULL, n, X, ...)
err |
Function from which to generate simulate error vector. Default
is |
n |
Number of samples. |
X |
Data matrix or data frame. Used to determine n if n is missing. |
... |
Other arguments to pass to err() to generate the error vector. |
The arguments n
and X
(if provided) are automatically
passed to the function err
under arguments of the same name.
Note however that they may be unused arguments if err
does not take
in arguments named n
and/or X
as input.
A vector of simulated errors with length n
.
# generate standard Gaussian error vector of length 150 errs <- generate_errors(err = rnorm, n = 150) # or alternatively, errs <- generate_errors(err = rnorm, X = iris) # generate Gaussian error vector with mean 0 and sd 2 errs <- generate_errors(err = rnorm, n = 150, sd = 2) # generate error vector of all 0s errs <- generate_errors(err = NULL, n = 150) # generate error vector from custom error function err_fun <- function(n, rho) { # simulate correlated errors from a autoregressive-1 Gaussian process row1 <- rho^(0:(n - 1)) Sigma <- stats::toeplitz(row1) return(MASS::mvrnorm(1, mu = rep(0, n), Sigma = Sigma)) } errs <- generate_errors(err = err_fun, n = 100, rho = 0.75)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.