spaMM (version 2.1.6)

simulate.HLfit: Simulate realizations of a fitted model.

Description

From an HLfit object, simulate.HLfit function generates new samples given the estimated fixed effects and dispersion parameters. Simulation may be conditional on the predicted values of random effects, or unconditional. Simulations may be run for the original values of fixed-effect predictor variables and of random effect levels (spatial locations for spatial random effects), or for new values of these. However, conditional simulation in mixed models with new such values is not yet handled.

Usage

# S3 method for HLfit
simulate(object, nsim = 1, seed = NULL, newdata=NULL,
                         type = "marginal", conditional=NULL, verbose=TRUE,
                         sizes = NULL, ...)
# S3 method for HLfitlist
simulate(object, nsim = 1, seed = NULL, 
                             newdata=object[[1]]$data, sizes=NULL, ...)

Arguments

object

The return object of HLfit or similar function.

nsim

number of response vectors to simulate. Defaults to '1'.

seed

A seed for set.seed. If such a value is provided, the initial state of the random number generator at a global level is restored on exit from simulate.

newdata

A data frame closely matching the original data, except that response values are not needed. May provide new values of fixed predictor variables, new spatial locations, or new individuals within a block.

type

character string specifying the type of simulation for (G)LMMs. "marginal" is for simulation from the marginal distribution of the random effect; "residual" acounts only for the residual variation of the fitted model; and "ranef|response" accounts both for residual variation and for the conditional distribution of the random effects given the response and the point estimates of model parameters. This distribution is known exactly in LMMs, and otherwise approximated as a Gaussian distribution with mean vector and covariance matrix given as per the Laplace approximation.

conditional

Obsolete and will be deprecated. Boolean; TRUE and FALSE are equivalent to type="residual" and type="marginal", respectively.

verbose

Boolean; whether to print some information or not.

sizes

A vector of sample sizes to simulate in the case of a binomial fit. Defaults to the sizes in the original data.

further arguments passed to or from other methods.

Value

For the HLfitlist method (i.e., the result of a multinomial fit), a list of simulated responses. Otherwise, a vector (if nsim=1) or a matrix with nsim columns, each containing a simulated response.

Examples

Run this code
# NOT RUN {
data(Loaloa)
HLC <- HLCor(cbind(npos,ntot-npos)~Matern(1|longitude+latitude),
           data=Loaloa,family=binomial(),
           ranPars=list(lambda=1,nu=0.5,rho=1/0.7)) 
simulate(HLC,nsim=2)
# }

Run the code above in your browser using DataLab