Learn R Programming

asremlPlus (version 2.0-2)

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

Description

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

Usage

## 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", ...)

Arguments

object
An asreml object from a call to asreml in which the data argument has been set.
means
The vector of means to be used in generating simulated data sets. If it is NULL, the fitted values based on object are used.
V
The fitted variance matrix, i.e. having the pattern and values that conform to the model fit stored in the supplied object.
nsim
The number of data sets to be simulated.
seed
A single value, interpreted as an integer, that specifies the starting value of the random number generator.
tolerance
The value such that eigenvalues less than it are consdered to be zero.
update
if TRUEthen 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 mo
trace
if TRUE then partial iteration details are displayed when ASReml-R functions are invoked; if FALSE then no output is displayed.
which
The quantites from the simulated data set to be stored. Any combination of "response", "residuals" and "fitted", or "all". If residuals and/or fitted
units
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
...
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.

Value

  • An list with the following components whose presence depends on the setting of which:
    1. observed:present ifwhichincludesresidualsorfitted, in which case it will be thedata.frameon which the fit inobjectis based, withresidualsand/orfitted.
  • data: present if which includes data, a data.frame containing the simulated data sets.
  • fitted: present if which includes fitted, a data.frame containing the fitted values from the analyses of the simulated data sets.
  • resduals: present if which includes residuals, a data.frame containing the residuals from the analyses of the simulated data sets.

Details

Generate nsim set of data and analyse them using asreml using the model in object. 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.

See Also

asreml, variofaces.asreml, plotvariofaces.asreml.

Examples

Run this code
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety, 
                      random = ~ Row + Column + units,
                      rcov = ~ ar1(Row):ar1(Column), 
                      data=Wheat.dat)
current.asrt <- 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")

Run the code above in your browser using DataLab