# Load the library foreign library(foreign) # Read in the tutorial Stata data set tutorial = read.dta("http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta") # Generate a boy dummy variable tutorial$boy <- 1 - tutorial$girl # Generate the passexam binary response variable tutorial$passexam <- tutorial$normexam>0 # Load the library R2MLwiN library(R2MLwiN) # Specify the MLwiN directory mlwin ="C:/Program Files (x86)/MLwiN v2.26/" # Declare the levels in the model hierarchy levID = c('school','student') # Specify the continuous response model formula = "normexam ~ (0 | cons + standlrt + girl) + (2 | cons + standlrt) + (1 | girl + boy)" # Set the level-1 covariance between the boy and girl residual errors to zero smat = c(2,1) # Specify estimation by IGLS estoptions = list(EstM=0) # Fit the model mymodel = runMLwiN(formula, levID, D="Normal", tutorial, estoptions, MLwiNPath=mlwin, workdir = tempdir()) # Specify the binary response model formula = "logit(passexam, cons) ~ (0 | cons + standlrt + girl) + (2 | cons + standlrt)" # Specify estiamtion by MCMC estoptions = list(EstM=1) # Fit the model mymodel = runMLwiN(formula, levID, D="Binomial", tutorial, estoptions, MLwiNPath=mlwin, workdir = tempdir())