library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.26/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")
## Example: Normal
formula="normexam~(0|cons+standlrt+girl)+(2|cons+standlrt)+(1|cons+standlrt+girl)"
levID=c('school','student')
clre=matrix(,nrow=3,ncol=2)
clre[1,1]=1; clre[2,1]='standlrt'; clre[3,1]='standlrt'
clre[1,2]=1; clre[2,2]='girl'; clre[3,2]='girl'
estoptions= list(EstM=1,mcmcMeth=list(nopause=TRUE),resi.store=TRUE,clre=clre)
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions,MLwiNPath=mlwin)
## Caterpillar plot
caterpillarR(mymodel["residual"], lev=2)Run the code above in your browser using DataLab