[R-sig-ME] counseling for multilevel models

Ben Bolker bbolker at gmail.com
Sun Jul 5 07:41:54 CEST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15-07-02 04:55 AM, Catarina Silva Castro wrote:
> Hello! My name is Catarina and study in the Faculty of Sciences of
> the University of Oporto, Portugal. Within the framework of my
> master's thesis, I am using a set of data on work accidents in a
> chain of stores. The chain store is divided into different
> directions of operations and each is associated monthly records of
> the number of registered work accidents. After several reviews, I
> think the multilevel models are the most suitable but when
> implementing in R the models, I don't know how to assign variables
> to different levels. When i use the function lme of the nlme
> library or lmer of the lme4 library, all covariables that include
> in the model are assigned to level 1 and do not know how to assign
> them to higher levels. I needed help to advise me on which the most
> appropriate functions and libraries, if them are not, and I would
> to know how to assign variables to different levels and get the
> best results for my study. Waiting for reply. Thanks, Catarina
> 

   You might need to be a little bit more specific/concrete.

   lme4 and nlme do not need to be told at what levels the fixed effects
(which I will take to be the same as your "covariables") vary.  It is
important to take this into account when deciding which terms to allow
to vary across which random-effects grouping levels, but this is not
an explicit model-specification issue.

  For example, suppose we have a response y, a grouping variable g,
and two covariates/fixed effects: x1 varies across individuals and x2
varies only across groups (that is, all individuals within any level
of g have identical values of x2).  Then the maximal model that makes
sense to fit (as an LMM) is

   y ~ x1 + x2 + (x1|g)   ;

if you try to fit

   y ~ x1 + x2 + (x1+x2|g)

(or some other model that incorporates variation of the effect of x2
across groups), you will get (hopefully) a warning or (possibly) a
wonky answer, as the observation/experimental design doesn't contain
any information about variation in this effect.

   I'm a little bit confused by your statement "all covariables that
include in the model are assigned to level 1"; how do you know?  The
only place I can think of that these packages make any kind of
assertion about levels is in anova(), where (n)lme (not lme4/lmer)
takes a guess about the appropriate denominator-df for an F test.  It
is true that lme's algorithm gets it wrong sometimes for random-slopes
models; if that is the case, please confirm / give more details ... in
any case, a bit of clarification about what's wrong and how you know
would be useful.

  cheers
    Ben Bolker


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJVmMOhAAoJEOCV5YRblxUHEiIH/0kk/PkzTotmKDi8eT0jGMyQ
9LGWFDXcZ9wHqN8L16VSm8yTDHz7geHkSRrrvVori0UQv8QojPvXn2CTxou/PiEV
oKG9ly5bPGK2ujEH0BK/W4Wp9x/i2iwGZdwSgJ45NwM2pKcOT6GDh0ZtARJTIHmz
B9s3LTK6OLP55a/hB/u5EO/HiydfnWhFnh7qxwrEIwOEOdzaN61R8jLah53b04gb
zXukK4YthvOYhFGsjW6dFkUqIEZ3Z/w4GOygayoiezLJo+b7MOIWLiZuNUI+aCBp
D3nZLUXtCaOfCQ/wkM2yscbBzdWldg1W1AYZlCnurUQrx9o7z2NwqAi+xnZKchQ=
=N9Vp
-----END PGP SIGNATURE-----



More information about the R-sig-mixed-models mailing list