simulate.tinyVAST | R Documentation |
simulate.tinyVAST
is an S3 method for producing a matrix of simulations from
a fitted model. It can be used with the DHARMa package
among other uses. Code is modified from the version in sdmTMB
## S3 method for class 'tinyVAST'
simulate(
object,
nsim = 1L,
seed = sample.int(1e+06, 1L),
type = c("mle-eb", "mle-mvn"),
...
)
object |
output from |
nsim |
how many simulations to do |
seed |
random seed |
type |
How parameters should be treated. |
... |
not used |
A matrix with row for each row of data
in the fitted model and nsim
columns, containing new samples from the fitted model.
set.seed(101)
x = seq(0, 2*pi, length=100)
y = sin(x) + 0.1*rnorm(length(x))
fit = tinyVAST( data=data.frame(x=x,y=y), formula = y ~ s(x) )
sims = simulate(fit, nsim=100, type="mle-mvn")
if(requireNamespace("DHARMa")){
# simulate new data conditional on fixed effects
# and sampling random effects from their predictive distribution
y_iz = simulate(fit, nsim=500, type="mle-mvn")
# Visualize using DHARMa
res = DHARMa::createDHARMa( simulatedResponse = y_iz,
observedResponse = y,
fittedPredictedResponse = fitted(fit) )
plot(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.