View source: R/simulate.default.R
simulate.default | R Documentation |
Default method for simulating new responses from any model object
with a prodist
method (for extracting a
probability distribution object).
## Default S3 method:
simulate(object, nsim = 1, seed = NULL, ...)
object |
An object for which a |
nsim |
The number of response vectors to simulate. Should be a positive integer. Defaults to 1. |
seed |
An optional random seed that is to be set using |
... |
Arguments passed to |
This default method simply combines two building blocks provided in this
package: (1) prodist
for extracting the probability
distribution from a fitted model object, (2) simulate.distribution
for simulating new observations from this distribution (internally calling
random
).
Thus, this enables simulation from any fitted model object that provides a
prodist
method. It waives the need to implement a dedicated
simulate
method for this model class.
A data frame with an attribute "seed"
containing the
.Random.seed
from before the simulation.
## Poisson GLM for FIFA 2018 goals
data("FIFA2018", package = "distributions3")
m <- glm(goals ~ difference, data = FIFA2018, family = poisson)
## simulate new goals via glm method
set.seed(0)
g_glm <- simulate(m, n = 3)
## alternatively use the new default method
set.seed(0)
g_default <- simulate.default(m, n = 3)
## same results
all.equal(g_glm, g_default, check.attributes = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.