Learn R Programming

R2MLwiN (version 0.1-7)

Formula.translate: An internal function to translate an R formula from a character string into an R list object.

Description

A model formula, as a formula object (or a character string) written in R-type syntax, is translated into an R list object.

Usage

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

Arguments

Formula
A formula object (or a character string) specifying a multilevel model. See Value for details.
levID
A character (vector) specifying the level ID(s).
D
A character string/vector specifying the distribution to be modelled.
indata
A data.frame object containing the data to be modelled.

Value

  • If Formula is a character string, we have the following syntax
  • ~is used to separate response variable(s) and explanatory variable(s);
  • ()are used to specify each random variable in the model together with its fixed/random part information;
  • |separates explanatory variable(s) (placed to the right of |) from the fixed/random part information (placed to the left of |) when placed within ();
  • []when placed immediately after an explanatory variable, indicates that the variable is categorical. The string in the [] represents the reference category; if empty, no reference category is used; See note.
  • :indicates an interaction term: i.e. the variables adjacent to :, and separated by it, are interacted with each other;
  • 0when placed to the left of | within () indicates that the variables to the right of | within the same () are to be added to the fixed part of the model;
  • 1when placed to the left of | within () indicates that the coefficients of the variables placed to the right of | within the same () are to be allowed to randomly vary at level 1;
  • 2when placed to the left of | within () indicates that the coefficients of the variables to the right of | within the same () are to be allowed to randomly vary at level 2 (and so on for 3 for level 3, etc.);
  • 0s/0cwhen placed to the left of | within () indicates that separate (hence s) / common (hence c) coefficients for the variables to the right of | within the same () are to be added to the fixed part (hence 0) of multivariate normal, multinomial and mixed responses models;
  • 2s/2cwhen placed to the left of | within () indicates that separate (hence s) / common (hence c) coefficients for the variables to the right of | within the same () are to be added to the random part of the model, and allowed to vary at level 2; applies to multivariate normal, multinomial and mixed responses models only;
  • ...
  • {}gives a vector of binary indicators specifying a common coefficient. 1 is to include the component at the corresponding positions; zero otherwise. These digits are separated by commas; applies to multivariate normal, multinomial and mixed responses models only;
  • .is used for adding a separate coefficient for a particular component at a specific level; applies to multivariate normal, multinomial and mixed responses models only;
  • If Formula is a formula object, 0s/0c, 2s/2c, .... and {} have to be replaced by `0s`/`0c`, `2s`/`2c`, .... and () respectively. Other syntax remains the same. see examples in runMLwiN for details. Outputs an R list object, which is then used as the input for MacroScript1 and/or MacroScript2.

See Also

runMLwiN,MacroScript1,MacroScript2