Define reference category for non-numeric covariates

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Define reference category for non-numeric covariates

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.

ChrisCharlton
Posts: 1165
Joined: Mon Oct 19, 2009 10:34 am

Re: Define reference category for non-numeric covariates

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.