1. To manually expand the data you would need to increase the number of rows so that within each level-1 unit there is a row for each of the response categories (except the base). Within each level-1 group you would then put a 1 in the appropriate row to indicate which category was in the original row. You would then for each explanatory variable create columns for each category and put the original value into the matching row/column. The column names would need to match the fixed-part parameter names in your model (minus the FP_) prefix).
2. If you just need the data for prediction in R then you can leave the terms as they are, however if you want to use the customised predictions faculties in MLwiN then you would probably want to specify the terms as actual interactions.
As predLines was not written to work with multinomial models it would require some effort to adapt it. The following example gets to the point where the data matches the model parameters, however it still does not provide the expected graph:
Code: Select all
# Load the R2MLwiN library
library(R2MLwiN)
# Load the "bang" example dataset
data(bang, package = "R2MLwiN")
# Set the base category
bang$use4 <- relevel(bang$use4, 4)
# Run the model in debug mode in order to extract the data
# To do this check which columns correspond to the expanded data (in this case bcons.1 up to age.Traditional_method).
# Then choose File->Export from the menu, select these columns and save as a dta file (in this example expanded.dta).
# Having done this click the "resume" button each time it appears until you are back in R.
(mymodel <- runMLwiN(log(use4) ~ 1 + age + (1 | district), D = "Unordered Multinomial", estoptions = list(EstM = 1, debugmode=TRUE, resi.store=TRUE, resi.store.levs = 2), data = bang))
# Load the foreign package to read the expanded data
library(foreign)
# Read the data into R
expanded <- read.dta("expanded.dta")
# Replace "." with "_" in the column names to match the parameter names
colnames(expanded) <- sub("\\.", "_", colnames(expand))
# Attach the expanded data to the saved model object
mymodel@data <- expanded
# Attempt to call predLines (but note the graph is blank)
predLines(mymodel, xname="age_Modern_reversible_method", lev=2, legend=FALSE, probs=c(0.025, 0.975))
predLines() (see
https://github.com/rforge/r2mlwin/blob/ ... redLines.r) would therefore need to be adapted to allow it to work for this case. I will put this on the TODO list, but I suspect that it is unlikely to be implemented any time soon. If you get anything working however I would be interested in incorporating it into the package.
I suspect that the easiest method would be instead to use the prediction functionality within MLwiN once it has received the model and data from R.