| simulate.asreml {asremlPlus} | R Documentation |
Produce sets of simulated data from a multivariate normal distribution and save quantities related to the simulated data
Description
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.
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",
ncores = 2, ...)
Arguments
object |
An |
means |
The |
V |
The fitted variance |
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. The "L'Ecuyer-CMRG" random
generator is used and |
tolerance |
The value such that eigenvalues less than it are considered to be zero. |
update |
If |
trace |
If |
which |
The quantities from the simulated data set to be stored. Any combination of
|
units |
A |
ncores |
A |
... |
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. |
Details
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.
Value
A list with the following components whose presence depends on the setting of
which:
observed: present if
whichincludesresidualsorfitted, in which case it will be thedata.frameon which the fit inobjectis based, withresidualsand/orfitted.data: present if
whichincludesdata, adata.framecontaining the simulated data sets.fitted: present if
whichincludesfitted, adata.framecontaining the fitted values from the analyses of the simulated data sets.residuals: present if
whichincludesresiduals, adata.framecontaining the residuals from the analyses of the simulated data sets.
Author(s)
Chris Brien
See Also
asreml, newfit.asreml, variofaces.asreml, plotVariofaces.data.frame,
set.seed.
Examples
## Not run:
data(Wheat.dat)
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
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 = parallel::detectCores())
## End(Not run)