The number of higher level observations are not correct

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/
Post Reply
adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

The number of higher level observations are not correct

Post by adeldaoud »

Hi,

The number of higher level observations are not correct when comparing Mlwin and R2mlwin output.

Mlwin (in debug mode): 26 cases

R2mlwin in subsequent output:66 cases


Is there a quick fix for this?

Thanks
Adel

PS: tried to attach images but uploads fail for some reason...
ChrisCharlton
Posts: 1205
Joined: Mon Oct 19, 2009 10:34 am

Re: The number of higher level observations are not correct

Post by ChrisCharlton »

I haven't seen this before, can you provide more information about the model structure? If you can replicate the problem with one of the sample data files then this would help me track down the problem.
adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: The number of higher level observations are not correct

Post by adeldaoud »

Sure:


# load tutorial
demo(MCMCGuide03)

# Read tutorial data
data(tutorial, package = "R2MLwiN")

# The highest level comes first, then the second highest and so on
(mymodel1 <- runMLwiN(normexam ~ 1 + standlrt + (1 | school) + (1 | student), estoptions = list(EstM = 0), data = tutorial))
summary(mymodel1)

# check data
summary(tutorial) # standlrt has no missing; create some missing

# set a complete school to standlrt = NA
tutorial1 <- tutorial
tutorial1$standlrt1 <- ifelse(tutorial1$school == 65, NA, tutorial1$standlrt)

# should give 64 schools
(mymodel2 <- runMLwiN(normexam ~ 1 + standlrt1 + (1 | school) + (1 | student),
estoptions = list(EstM = 0), data = tutorial1))
summary(tutorial2)
# ==> shows 65

# check hierarchy viewer in debugg mode
(mymodel2 <- runMLwiN(normexam ~ 1 + standlrt1 + (1 | school) + (1 | student),
estoptions = list(EstM = 0, debugmode=T), data = tutorial1))
# ==> hierarchy viewer shows 64 schools!
# Hence, the R2mlwin output about valid higher level cases is wrong
ChrisCharlton
Posts: 1205
Joined: Mon Oct 19, 2009 10:34 am

Re: The number of higher level observations are not correct

Post by ChrisCharlton »

Thanks for this example, there were a couple of bugs here:
  • The cross-classification flag was not being checked correctly, so it was assuming that the IDs were unique across all groups.
  • Unused factors were not being dropped after reducing the data to complete cases. This meant that although you made school 65 completely missing there was still a factor label associated with it after the records had been dropped.
Both of these should now have been fixed in the development version (see http://www.bristol.ac.uk/cmm/software/r ... stallation on how to use this), however you may have to wait a while before the changes are mirrored onto github (see https://github.com/rforge/r2mlwin/commits/master).
adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: The number of higher level observations are not correct

Post by adeldaoud »

Thanks very much for the prompt fix, Chris.

I will install the development version asap.
Post Reply