Page 1 of 1

The number of higher level observations are not correct

Posted: Sun Jul 17, 2016 4:31 pm
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...

Re: The number of higher level observations are not correct

Posted: Mon Jul 18, 2016 10:14 am
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.

Re: The number of higher level observations are not correct

Posted: Mon Jul 18, 2016 11:43 am
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

Re: The number of higher level observations are not correct

Posted: Mon Jul 18, 2016 1:21 pm
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).

Re: The number of higher level observations are not correct

Posted: Mon Jul 18, 2016 1:37 pm
by adeldaoud
Thanks very much for the prompt fix, Chris.

I will install the development version asap.