Learn R Programming

R2MLwiN (version 0.1-7)

MacroScript2: Writes MLwiN macros to fit models using Markov chain Monte Carlo (MCMC) methods

Description

MacroScript2 is an internal function which creates an MLwiN macro file to fit models using MCMC.

Usage

MacroScript2(indata, dtafile, resp,
levID, expl, rp,
D, nonlinear, categ,
notation, nonfp, clre,
smat, Meth, merr, seed,
iterations, burnin, scale,
thinning, priorParam, refresh,
fixM, residM, Lev1VarM,
OtherVarM, adaption, priorcode,
rate, tol, lclo,
mcmcOptions, fact,
xclass = NULL, BUGO = NULL,
mem.init, nopause,
modelfile = modelfile,
initfile = initfile,
datafile = datafile,
macrofile = macrofile,
IGLSfile = IGLSfile,
MCMCfile = MCMCfile,
chainfile = chainfile,
MIfile = MIfile,
resifile = resifile,
resi.store = resi.store,
resioptions=resioptions,
resichains = resichains,
FACTchainfile = FACTchainfile,
resi.store.levs = resi.store.levs,
debugmode = debugmode,
startval = startval,
dami = dami)

Arguments

indata
A data.frame object containing the data to be modelled.
dtafile
The file name of the dataset to be imported into MLwiN, which is in Stata format (i.e. with extension .dta).
resp
A character string (vector) of response variable(s).
levID
A character string (vector) of the specified level ID(s). The ID(s) should be sorted in the descending order of levels (e.g. levID=c('level2','level1') where 'level2' is the higher level).
expl
A character string (vector) of explanatory (predictor) variable(s).
rp
A character string (vector) of random part of random variable(s).
D
A vector specifying the type of distribution to be modelled, which can include "Normal", "Binomial" "Poisson", "Unordered Multinomial", "Ordered Multinomial", "Multivariate Normal"
nonlinear
LINEarise mode N order M. 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
categ
Specifies categorical variable(s) as a matrix. Each column corresponds to a categorical variable; the first row specifies the name(s) of variable(s); the second row specifies the name(s) of reference group(s), NA(s) if no reference group; th
notation
Specifies the model subscript notation to be used in the MLwiN equations window. "class" means no multiple subscripts, whereas "level" has multiple subscripts.
nonfp
Removes the fixed part of random variable(s). NA if no variable is removed.
clre
A matrix used to estimate some, but not all, of the variances and covariances for a set of coefficients at a particular level. Remove from the random part at level the covariance matrix element(s) defined by the pair(s) of rows
smat
An integer vector of length 2 specifying whether the covariance matrix at a particular level is diagonal. The first digit is the level indicator, whilst the second digit is a binary indicator where 1 indicates a diagonal covariance matrix and
Meth
Specifies which maximum likelihood estimation method to be used. If 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 IGL
merr
A vector which sets-up measurement errors on predictor variables. The first element N defines the number of variables that have measurement errors. Then, for each variable with measurement error, a pair of inputs is required: value Ma is the
seed
An integer specifying the random seed in MLwiN. By default, seed=1.
iterations
An integer specifying the number of iterations after burn-in.
burnin
An integer specifying length of the burn-in.
scale
An integer specifying the scale factor.
thinning
An integer specifying the frequency with which successive values in the Markov chain are stored. By default thinning=1.
priorParam
A vector specifying the informative priors used. Also see prior2macro.
refresh
An integer specifying how frequently the parameter estimates are refreshed on the screen during iterations. By default refresh=50.
fixM
Specifies the fixed effect method: 1 for Gibbs Sampling, 2 for univariate MH Sampling and 3 for multivariate MH Sampling.
residM
Specifies the residual method: 1 for Gibbs Sampling, 2 for univariate MH Sampling and 3 for multivariate MH Sampling.
Lev1VarM
Specifies the level 1 variance method: 1 for Gibbs Sampling, 2 for univariate MH Sampling and 3 for multivariate MH Sampling.
OtherVarM
Specifies the variance method for other levels: 1 for Gibbs Sampling, 2 for univariate MH Sampling and 3 for multivariate MH Sampling.
adaption
adaption=1 indicates adaptation is to be used; 0 otherwise.
priorcode
An integer indicating which default priors are to be used for the variance parameters. This parameter takes the value 1 for Gamma priors or 0 for Uniform on the variance scale priors. See the section on "Priors" in the MLwiN help
rate
An integer specifying the acceptance rate (as a percentage); this command is ignored if adaptation=0.
tol
An integer specifying tolerance.
lclo
This command toggles on/off the possible forms of complex level 1 variation when using MCMC. By default (lclo=0) we express the level 1 variation as a function of the predictors. If this is toggled (lclo=1) we express the log of
mcmcOptions
A list of other MCMC options used. See Value below.
fact
A list of objects specified for factor analysis. See Value below.
xclass
A list of objects specified for cross-classified and/or multiple membership models. See Value below.
BUGO
If the first entry of the vector is TRUE, the current model is outputted in BUGS code. version=4 specifies WinBUGS 1.4 format, whilst version=3 corresponds to WinBUGS 1.3 format. n.chains specifies the n
mem.init
A vector which sets and displays worksheet capacities for the current MLwiN session according to the value(s) specified. By default, the number of levels is nlev+1; worksheet size in thousands of cells is 6000; the number of columns is 2500;
nopause
A logical value specifying whether the estimates are to be updated on screen or not, in MLwiN. Default nopause=FALSE, i.e. the screen is updated.
modelfile
A file name where the WinBUGS model will be saved in .txt format.
initfile
A file name where the WinBUGS initial values will be saved in .txt format.
datafile
A file name where the WinBUGS data will be saved in .txt format.
macrofile
A file name where the MLwiN macro file will be saved. The default location is in the temporary folder.
IGLSfile
A file name where the IGLS estimates will be saved. The default location is in the temporary folder.
MCMCfile
A file name where the MCMC estimates will be saved. The default location is in the temporary folder.
chainfile
A file name where the MCMC chains will be saved. The default location is in the temporary folder.
MIfile
A file name where the missing values will be saved. The default location is in the temporary folder.
resifile
A file name where the residual estimates will be saved. The default location is in the temporary folder.
resi.store
A logical value to indicate if residuals are to be stored (TRUE) or not (FALSE).
resioptions
A string vector to specify the various residual options. The "variances" option calculates the posterior variances instead of the posterior standard errors; the "standardised", "leverage", "influence" an
resichains
A file name where the residual chains will be saved. The default location is in the temporary folder.
FACTchainfile
A file name where the factor chains will be saved. The default location is in the temporary folder.
resi.store.levs
An integer vector indicating the levels at which the residual chains are to be stored.
debugmode
A logical value determining whether MLwiN is run in the background or not. The default value is FALSE: i.e. MLwiN is run in the background. If TRUE MLwiN remains open after the model has run, allowing the user to interact with ML
startval
A list of numeric vectors specifying the starting values when using MCMC. 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
dami
This command outputs a complete (i.e. including non-missing responses) response variable y. If dami=c(0,,,...) then the response variables returned will be the value of y at the iterations quoted (as integers ,

Value

  • A list of other MCMC options as used in the argument mcmcOptions:
  • orthIf orth=1, orthogonal fixed effect vectors are used; zero otherwise.
  • hcenAn integer specifying the level where we use hierarchical centering.
  • smcmIf smcm=1, structured MCMC is used; zero otherwise.
  • smvnIf smvn=1, the structured MVN framework is used; zero otherwise.
  • paexThis gives a vector of length two. If the second digit is 1, parameter expansion is used at level ; zero otherwise.
  • mccoThis command allows the user to have constrained settings for the lowest level variance matrix in a multivariate Normal model. The default value for mcco, 0, is used for a full covariance matrix. Four other settings are currently available: ll{ (1) all correlations equal and all variances equal; (2) an AR1 structure with all variances equal; (3) all correlations equal but independent variances; (4) an AR1 structure with independent variances. }
  • A list of objects specified for cross-classified and/or multiple membership models, as used in the argument xclass:
  • classAn integer (vector) of the specified class(es).
  • N1This defines a multiple membership across N1 units at level class. N1>1 if there is multiple membership.
  • weightIf 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.
  • idIf 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.
  • carcar=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:
  • nfactSpecifies the number of factors
  • lev.factSpecifies the level/classification for the random part of the factor for each factor.
  • nfactcorSpecifies the number of correlated factors
  • factcorA vector specifying the correlated factors
  • ll{ (1) the first factor number; (2) the second factor number; (3) the starting value for the covariance and (4) an indicator of whether this covariance is constrained (1) or not (0). }
  • loadingA matrix specifying the starting values for the factor loadings and the starting value of the factor variance. Each row corresponds to a factor.
  • constrA matrix specifying indicators of whether the factor loadings and the factor variance are constrained (1) or not (0).
  • The MLwiN macro file is created in the temporary directory (tempdir()) and will be displayed on screen if show.file=TRUE.

See Also

MacroScript1, tempdir