write.MCMC(indata, dtafile, oldsyntax = FALSE, resp, levID, expl, rp, D = "Normal", nonlinear = c(0, 1), categ = NULL, notation = NULL, nonfp = NULL, clre = NULL, Meth = 1, merr = NULL, carcentre = FALSE, maxiter = 20, convtol = 2, seed = 1, iterations = 5000, burnin = 500, scale = 5.8, thinning = 1, priorParam = "default", refresh = 50, fixM = 1, residM = 1, Lev1VarM = 1, OtherVarM = 1, adaption = 1, priorcode = c(gamma = 1), rate = 50, tol = 10, lclo = 0, mcmcOptions, fact = NULL, xc = NULL, mm = NULL, car = NULL, BUGO = NULL, mem.init = "default", optimat = FALSE, modelfile, initfile, datafile, macrofile, IGLSfile, MCMCfile, chainfile, MIfile, resifile, resi.store = FALSE, resioptions, resichains, FACTchainfile, resi.store.levs = NULL, debugmode = FALSE, startval = NULL, dami = NULL, namemap = sapply(colnames(indata), as.character), saveworksheet = NULL)FALSE if new syntax has been used in
Formula object, else specified as TRUE (to enable
backcompatibility).levID = c('level2', 'level1') where 'level2' is the higher
level).'Normal' (the default), 'Binomial', 'Poisson',
'Unordered Multinomial', 'Ordered Multinomial',
'Multivariate Normal', or 'Mixed'. In the case of the latter,
'Mixed' precedes the response types which also need to be listed in
D, e.g. c('Mixed', 'Normal', 'Binomial'); these need to be
be listed in the same order to which they are referred to in the
Formula object (see runMLwiN, Formula.translate,
Formula.translate.compat. 'Mixed' combinations can only consist of
'Normal' and 'Binomial' for MCMC estimation.N = 0 specifies marginal quasi-likelihood
linearization (MQL), whilst N = 1 specifies penalised quasi-
likelihood linearization (PQL); M = 1 specifies first order
approximation, whilst M = 2 specifies second order approximation.
nonlinear = c(N = 0, M = 1) by default. First order marginal
quasi-likelihood (MQL1) only option for single-level discrete response
models.NA(s) if no reference group; the third row states the number of
categories for each variable.'class' means no multiple subscripts, whereas
'level' has multiple subscripts.NA if no
variable is removed.Meth = 0 estimation method is set to RIGLS. If Meth = 1
estimation method is set to IGLS (the default setting). If Meth is
absent, alternate between IGLS and RIGLS.N defines the number of variables that
have measurement errors. Then, for each variable with measurement error, a
pair of inputs is required: the first of which is the explanatory variable
name as a character string, and the second of which is the variance of
the measurement error for this variable. See demo(MCMCGuide14) for an
example.car is non-NULL),
carcentre = TRUE mean-centres all random effects at that level.startval = NULL).tol option within estoptions, where
startval = NULL) (see runMLwiN). If value of
convtol is m, estimation will be deemed to have converged when the
relative change in the estimate for any parameter from one iteration to the
next is less than 10(-m). Defaults to value of 2 for m if not
otherwise specified.thinning = 1.prior2macro.debugmode = TRUE in estoptions:
see runMLwiN.1 for Gibbs Sampling,
2 for univariate MH Sampling and 3 for multivariate MH
Sampling.1 for Gibbs Sampling,
2 for univariate MH Sampling and 3 for multivariate MH
Sampling.1 for Gibbs
Sampling, 2 for univariate MH Sampling and 3 for multivariate
MH Sampling.1
for Gibbs Sampling, 2 for univariate MH Sampling and 3 for
multivariate MH Sampling.adaption = 1 indicates adaptation is to be used;
0 otherwise.c(gamma = 1) in which case
Gamma priors are used with MLwiN's defaults of Gamma a value (shape) = 0.001
and Gamma b value (scale) = 0.001, although alternative values for shape and
scale can be specified in subsequent elements of the vector,
e.g. c(gamma = 1, shape = 0.5, scale = 0.2)). Alternatively
c(uniform = 1) specifies Uniform priors on the variance scale. To allow
for back-compatibility with deprecated syntax used in versions of
R2MLwiN prior to 0.8-2, if priorcode is instead specified as
an integer, then 1 indicates that Gamma priors are used, whereas
0 indicates that Uniform priors are used. See the section on 'Priors' in the
MLwiN help system for more details on the meaning of these priors.adaption = 0.lclo = 0 expresses the level
1 variation as a function of the predictors, whereas lclo = 1 expresses the
log of the level 1 precision (1/variance) as a function of the predictors.TRUE) or
nested (FALSE). xc = NULL by default (corresponding to
FALSE), unless either mm or car are not null, in
which case xc = TRUE.df2matrix). In the case of the former, each
element of the list corresponds to a level (classification) of the model,
in descending order. If a level is not a multiple membership classification,
then NA is specified. Otherwise, lists need to be assigned to
mmvar and weights, with the former containing columns
specifying the classification units, and the latter containing columns
specifying the weights. Ignored if EstM = 0, i.e. only applicable to models estimated via
MCMC. mm = NULL by default. Supersedes deprecated xclass.
E.g. (from demo(MCMCGuide16)) for
logearn ~ 1 + age_40 + sex + parttime + (company|1) + (id|1), if
company is a multiple membership classification with the variables
indicating the classifications in company, company2,
company3, company4 and their weights in weight1, weight2,
weight3 and weight4 then
mm = list(list(mmvar = list('company', 'company2', 'company3', 'company4'),
weights = list('weight1', 'weight2', 'weight3', 'weight4')), NA)
with the NA, listed last, corresponding to the level 1 identifier (id).NA is specified. Otherwise, lists need to be assigned to
carvar and weights, with the former containing columns
specifying the spatial classification units, and the latter containing
columns specifying the weights. See demo(MCMCGuide17) for examples.
car = NULL by default.NULL uses BUGS for MCMC estimation using files
specified in modelfile, initfile and datafile.nlev+1; worksheet size in thousands of cells
is 6000; the number of columns is 2500; the number of explanatory variables
is num_vars+10; the number of group labels is 20. nlev is the
number of levels specified by levID, and num_vars is
approximately the number of explanatory variables calculated initially.optimat = TRUE
if MLwiN gives the following error message 'Overflow allocating smatrix'.
This error message arises if one more higher-level units is extremely large
(contains more than 800 lower-level units). In this situation runmlwin's
default behaviour is to instruct MLwiN to allocate a larger matrix size to
the (R)IGLS algorithm than is currently possible. Specifying
optimat = TRUE caps the maximum matrix size at 800 lower-level units,
circumventing the MLwiN error message, and allowing most MLwiN
functionality.TRUE) or not (FALSE).'variance' option calculates the posterior variances instead of
the posterior standard errors; the 'standardised' option calculates standardised
residuals.FALSE: i.e. MLwiN is run in
the background. If TRUE the MLwiN GUI is opened, and then pauses after the model
has been set-up, allowing user to check starting values; pressing 'Resume macro'
will then fit the model. Once fit, pressing 'Resume macro' once more will save
the outputs to the workdir ready to be read by R2MLwiN. Users can
instead opt to 'Abort macro' in which case the outputs are not saved to the
workdir. This option currently
works for 32 bit version of MLwiN only (automatically switches unless
MLwiNPath or options(MLwiNPath)
has been set directly to the executable).FP.b corresponds to the estimates for the fixed
part; FP.v specifies the variance/covariance estimates for the fixed
part; RP.b specifies the variance estimates for the random part;
RP.v corresponds to the variance/covariance matrix of the variance
estimates for the random part.dami = c(0, , ,...) then
the response variables returned will be the value of y at the iterations
quoted (as integers , , etc.); these can be used for
multiple imputation. If dami = 1 the value of y will be the mean
estimate from the iterations produced. dami = 2 is as for dami = 1
but with the standard errors of the estimate additionally being stored.mcmcOptions:
orth: If orth = 1, orthogonal fixed effect
vectors are used; zero otherwise.
hcen: An integer specifying the
level where we use hierarchical centering.
smcm: If smcm = 1,
structured MCMC is used; zero otherwise.
smvn: If smvn = 1, the
structured MVN framework is used; zero otherwise.
paex: A matrix of Nx2; in each row, if the second digit is 1, parameter expansion
is used at level mcco: This
command allows the user to have constrained settings for the lowest level
variance matrix in a multivariate Normal model. If value is 0,
it estimates distinct variances for each residual error and distinct covariances
for each residual error pair. Four other
settings are currently available:
1 |
| fits stuctured errors with a common correlation paramater and a common variance parameter; |
2 |
| fits AR1 errors with a common variance parameter; |
3 |
| fits structured errors with a common correlation parameter and independent variance parameters; |
4 |
| fits AR1 errors with independent variance parameters. |
A list of objects specified for cross-classified and/or multiple membership
models, as used in the argument xclass:
class: An integer
(vector) of the specified class(es).
N1: This defines a multiple
membership across N1 units at level class. N1>1 if
there is multiple membership.
weight: If there is multiple
membership then the column number weight, which is the length of the
dataset, will contain the first set of weights for the multiple membership.
Note that there should be N1 weight columns and they should be
sequential in the worksheet starting from weight.
id: If the
response is multivariate then the column number id must be input and
this contains the first set of identifiers for the classification. Note that
for a p-variate model each lowest level unit contains p records and the
identifiers (sequence numbers) for each response variate need to be
extracted into id and following columns. There should be N1 of
these identifier columns and they should be sequential starting from
id in the multivariate case.
car: car = TRUE indicates
the spatial CAR model; FALSE otherwise. car = FALSE if ignored.
A list of objects specified for factor analysis, as used in the argument
fact:
nfact: Specifies the number of factors
lev.fact: Specifies the level/classification for the random part of
the factor for each factor.
nfactcor: Specifies the number of
correlated factors
factcor: a vector specifying the correlated
factors: the first element corresponds to the first factor number, the
second to the second factor number, the third element corresponds to the
starting value for the covariance and the fourth element to whether this
covariance is constrained
(1) or not (0). If more than one pair of factors is correlated,
then repeat this sequence for each pair.
loading: A matrix specifying the
starting values for the factor loadings and the starting value of the factor
variance. Each row corresponds to a factor.
constr: A matrix
specifying indicators of whether the factor loadings and the factor variance
are constrained (1) or not (0).
Rasbash, J., Steele, F., Browne, W.J. and Goldstein, H. (2012) A User's Guide to MLwiN Version 2.26. Centre for Multilevel Modelling, University of Bristol.
write.IGLS