simulate.asreml {asremlPlus}R Documentation

Produce sets of simulated data from a multivariate normal distribtion and save quantites related to the simulated data


Produce in parallel sets of simulated data corresponding to an asreml model, along with its fitted values and residuals. A variance matrix V, corresponding to the random and residual models must be supplied. What to save is specified by the which argument.


## S3 method for class 'asreml'
simulate(object, nsim=100, seed = NULL, means=NULL, V, tolerance = 1E-10, 
         update = TRUE, trace = FALSE, which="data", units = "ignore", 
         ncores = detectCores(), ...)



An asreml object from a call to asreml in which the data argument has been set.


The vector of means to be used in generating simulated data sets. If it is NULL, the fitted values based on object are used. It must be the same length as the response variable for object.


The fitted variance matrix, i.e. having the pattern and values that conform to the model fit stored in the supplied object.


The number of data sets to be simulated.


A single value, interpreted as an integer, that specifies the starting value of the random number generator. The "L'Ecuyer-CMRG" random generator is used and nextRNGStream is used to seed each core from the original seed.


The value such that eigenvalues less than it are considered to be zero.


If TRUE then the arguments R.param and G.param are set to those in the asreml object supplied in object so that the values from the original model are used as starting values. If FALSE then calls are made to asreml in which the only changes from the previous call are (i) the model is fitted to simulated data and (ii) modifications specified via ... are made, except that changes cannot be made to any of the models.


If TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed.


The quantites from the simulated data set to be stored. Any combination of "response", "residuals" and "fitted", or "all". If residuals and/or fitted is specified, those for the analysis stored in object will be added to the data.frame nominated in the data argument of object and the modified data.frame added as a component named data in the list that is the value returned by the function.


A character indicating whether the BLUPs for units are added to the residuals when this reserved factor is included in the random model. Possible values are addtoresiduals and ignore.


A numeric specifying the number of cores to use in doing the simulations.


Other arguments that are passed down to the function asreml. Changes to the models are not allowed. Other changes are dangerous and generally should be avoided.


Generate nsim sets of data and analyse them using asreml using the model in object, performing the generation and analysis of several sets in parallel. Note, if the analysis for a data set does not converge in maxiter iterations, it is discarded and a replacement data set generated. The value of maxiter can be specified in the call to simulate.asreml. The fitted values and residuals are extracted as required. If aom = TRUE when the simulated data are analysed, standardised conditional residuals are stored. If which includes residuals or fitted, the specified quantities for the observed data are added to the data.frame on which the fit in object is based.


A list with the following components whose presence depends on the setting of which:

  1. observed: present if which includes residuals or fitted, in which case it will be the data.frame on which the fit in object is based, with residuals and/or fitted.

  2. data: present if which includes data, a data.frame containing the simulated data sets.

  3. fitted: present if which includes fitted, a data.frame containing the fitted values from the analyses of the simulated data sets.

  4. residuals: present if which includes residuals, a data.frame containing the residuals from the analyses of the simulated data sets.


Chris Brien

See Also

asreml, variofaces.asreml,, set.seed.


## Not run: 
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety, 
                      random = ~ Row + Column + units,
                      residual = ~ ar1(Row):ar1(Column), 
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary.asrtests(current.asrt)
# Form variance matrix based on estimated variance parameters
s2 <- current.asr$sigma2
gamma.Row <- current.asr$gammas[1]
gamma.unit <- current.asr$gammas[2]
rho.r <- current.asr$gammas[4]
rho.c <- current.asr$gammas[5]
row.ar1 <- mat.ar1(order=10, rho=rho.r)
col.ar1 <- mat.ar1(order=15, rho=rho.c)
V <- gamma.Row * fac.sumop(Wheat.dat$Row) + 
     gamma.unit * diag(1, nrow=150, ncol=150) + 
     mat.dirprod(col.ar1, row.ar1)
V <- s2*V

#Produce residuals from 100 simulated data sets
resid <- simulate(current.asr, V=V, which="residuals", ncores = 2)

## End(Not run)

[Package asremlPlus version 4.2-32 Index]