Learn R Programming

R2MLwiN (version 0.8-1)

Formula.translate: An internal function to translate an R formula into an R list object.

Description

A model formula, as a formula object written in R-type syntax, is translated into an R list object.

Usage

Formula.translate(Formula, D = "Normal", indata)

Arguments

Formula
A formula object specifying a multilevel model. See formula for notes on general usage, and runMLwiN
D
A character string/vector specifying the type of distribution to be modelled, which can include 'Normal' (the default), 'Binomial', 'Poisson', 'Negbinom', 'Unordered Multinomial', 'O
indata
A data.frame object containing the data to be modelled. Optional (can attach as an alternative) but recommended.

Value

See Also

runMLwiN, write.IGLS, write.MCMC; for function allowing back-compatibility with Formula syntax used in older versions of R2MLwiN (<0.8.0) see="" Formula.translate.compat.

Examples

Run this code
# NB: See demo(packge = 'R2MLwiN') for a wider range of examples.
library(R2MLwiN)
# NOTE: if MLwiN not saved in location R2MLwiN defaults to, specify path via:
# options(MLwiN_path = 'path/to/MLwiN vX.XX/')
# If using R2MLwiN via WINE, the path may look like this:
# options(MLwiN_path = '/home/USERNAME/.wine/drive_c/Program Files (x86)/MLwiN vX.XX/')

# Two-level random intercept model with student (level 1) nested within
# school (level 2) and standlrt added to the fixed part.
# Importantly, the ordering of school and student reflects their hierarchy,
# with the highest level (school) specified first.
# E.g. see demo(UserGuide04)
data(tutorial, package = 'R2MLwiN')
(mymodel1 <- runMLwiN(normexam ~ 1 + standlrt + (1 | school) + (1 | student),
                     data = tutorial))

# Adding a random slope
(mymodel2 <- runMLwiN(normexam ~ 1 + standlrt + (1 + standlrt | school)
                     + (1 | student), data = tutorial))

# Exploring complex level 1 variation
# E.g. see demo(UserGuide07)
(mymodel3 <- runMLwiN(normexam ~ 1 + standlrt + (1 + standlrt | school)
                      + (1 + standlrt | student), data = tutorial))

# Logit link with cons specified as denominator
# Note level 1 ID not explicitly specified
# E.g. see demo(UserGuide09)
data(bang, package = 'R2MLwiN')
(mymodel4 <- runMLwiN(logit(use, cons) ~ 1 + lc + age + (1 | district),
                      D = 'Binomial', data = bang))

# Mixed response model
# Note using MCMC estimation (EstM = 1)
# Normal (english) and Bernoulli (behaviour) distributed responses
# probit link modelling behaviour with cons as denominator
# E.g. see demo(MCMCGuide19)
data(jspmix1, package = 'R2MLwiN')
(mymodel <- runMLwiN(c(english, probit(behaviour, cons)) ~
                     1 + sex + ravens + fluent[1] + (1 | school) + (1[1] | id),
                     D = c('Mixed', 'Normal', 'Binomial'),
                     estoptions = list(EstM = 1,
                     mcmcMeth = list(fixM = 1, residM = 1, Lev1VarM = 1)),
                     data = jspmix1))

Run the code above in your browser using DataLab