glmmTMB
has the capability to simulate from a fitted model. These simulations resample random effects from their estimated distribution. In future versions of glmmTMB
, it may be possible to condition on estimated random effects.
library(glmmTMB)
library(ggplot2); theme_set(theme_bw())
Fit a typical model:
data(Owls)
glmmTMB(SiblingNegotiation ~ FoodTreatment*SexParent +
owls_nb1 <- (1|Nest)+offset(log(BroodSize)),
family = nbinom1,
ziformula = ~1, data=Owls)
Then we can simulate from the fitted model with the simulate.glmmTMB
function. It produces a list of simulated observation vectors, each of which is the same size as the original vector of observations. The default is to only simulate one vector (nsim=1
) but we still return a list for consistency.
simulate(owls_nb1, seed=1)
simo=
Simdat=Owls$SiblingNegotiation=simo[[1]]
Simdattransform(Simdat,
Simdat=NegPerChick = SiblingNegotiation/BroodSize,
type="simulated")
$type = "observed"
Owlsrbind(Owls, Simdat) Dat=
Then we can plot the simulated data against the observed data to check if they are similar.
ggplot(Dat, aes(NegPerChick, colour=type))+geom_density()+facet_grid(FoodTreatment~SexParent)