Page 1 of 1

Define reference category for non-numeric covariates

Posted: Tue Apr 17, 2018 9:37 pm
by adeldaoud
Hi

(A)
How can I define the reference category for non-numeric covariates (binary, ordinal, or multinomial)? According to the manual "[] 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.". I have used this in the past, but it does not work anymore.

Code: Select all

data(tutorial, package = "R2MLwiN")

# works
(mymodel2 <- runMLwiN(normexam ~ 1 + standlrt + sex + schgend + (1 + standlrt | school) + (1 | student), data = tutorial))

# does not work - string
(mymodel3 <- runMLwiN(normexam ~ 1 + standlrt + sex["boy"] + schgend + (1 + standlrt | school) + (1 | student), data = tutorial))

# does not work - no string
(mymodel4 <- runMLwiN(normexam ~ 1 + standlrt + sex[boy] + schgend + (1 + standlrt | school) + (1 | student), data = tutorial))

Any ideas?

(B)
I want to specifically use an explicit reference category with an interaction, for example:

Code: Select all

(mymodel5 <- runMLwiN(normexam ~ 1 + standlrt + sex["boy"] + schgend["mixedsch"] + sex["boy"]:schgend["mixedsch"]  (1 + standlrt | school) + (1 | student), data = tutorial))

Not sure what why this is not working.

Re: Define reference category for non-numeric covariates

Posted: Wed Apr 18, 2018 9:06 am
by ChrisCharlton
The syntax that you refer to is the documentation of Formula.translate.compat, which is used in cases where the old formula syntax is specified. Using the current syntax the way to specify reference categories is via the relevel function (http://stat.ethz.ch/R-manual/R-devel/li ... level.html), as in the third example model in http://www.bristol.ac.uk/cmm/media/r2ml ... ide02.Rout.

Re: Define reference category for non-numeric covariates

Posted: Wed Apr 18, 2018 12:16 pm
by adeldaoud
ok, thanks Chris. It was not immediately clear from the R2mlwin documentation (https://cran.r-project.org/web/packages ... 2MLwiN.pdf), pp. 22-23. An additional note is may be required.