Hi Maxim,

Thanks for raising this issue. You're right: due to the manner in which MLwiN handles dummy variables, there can be issues when fitting a model (via R2MLwiN) with a categorical predictor in the fixed and random part of a model, and so I'm afraid a workaround is needed.

To this end, R2MLwiN has an Untoggle function to create dummy variables on the user's behalf. However, we've just spotted a bug in how it assigns variable names for factors, so in the meantime it's necessary to first convert your variable (assuming it's a factor) to a continuous variable, as in the example below. We'll update this post when a new version of R2MLwiN is released with this bug fixed.

Code: Select all

```
library("R2MLwiN")
data("tutorial")
IDa <- c("school", "student")
## change path as appropriate:
MLwiN <- "C:/Program Files (x86)/MLwiN v2.27/"
## By default, schgend is a factor with 3 levels (mixedsch, boysch, girlsch):
summary(tutorial)
## R2MLwiN's Untoggle function is designed to create separate vectors for each level of a categorical variable
## ...however we've just discovered a bug in how it assigns variable names for factors,
## ...so in the meantime (whilst we resolve bug) please first convert to a continuous variable:
tutorial$schgend <- as.numeric(tutorial$schgend)
tutorial <- cbind(tutorial, Untoggle(tutorial[["schgend"]], "schgend"))
## new vectors schgend_1 (mixedsch), schgend_3 (girlsch), schgend_2 (boysch) all added to dataset:
summary(tutorial)
F1 <- "normexam ~ (0|cons + standlrt + schgend_2 + schgend_3) + (2|cons + schgend_2 + schgend_3) + (1|cons)"
(mymodel2 <- runMLwiN(Formula = F1, levID = IDa, indata = tutorial, MLwiNPath = MLwiN))
## Will post again when new version R2MLwiN released with bug fix.
```

Hope that answers your question?

Best wishes,

Richard