[R] glmer with multiple random slopes
Ben Bolker
bbolker at gmail.com
Wed Oct 22 17:08:25 CEST 2014
David Kikuchi <dwkikuchi <at> gmail.com> writes:
>
> Hi all,
>
> I'm modeling the probability that a subject attacks or rejects a prey
> item based on its proportion of yellow coloration and size. There are
> two populations of prey, one defended and the other undefended, so
> subjects should reject one type and accept others. Each subject has a
> unique rejection threshold that is a line on a contour plot with
> coloration and size on the x and y axes. I want to estimate the error
> around that line's slope, and believe that I need to estimate two random
> slopes per subject to do so, one in the color dimension and the other in
> the size dimension. The code that I think I should use to do this is:
> glmer(attack ~ prop.color + size + (prop.color + size|subject, family =
> binomial), but I cannot find a reference or example for fitting random
> slopes in different continuous dimensions. I would appreciate any
> pointers in the right direction.
>
> Thanks,
> David
This seems perfectly reasonable. It might be more on-topic
on r-sig-mixed-models at r-project.org (send follow-ups there please).
My only concern with this model is the size of your data set -- you
probably need a reasonably large number of trials per subject (20-30, or more?),
and a reasonably large number of subjects (at least 10, preferably >20?)
in order to estimate the among-subject variation in the response reasonably
well.
You should be able to use lme4's simulate method to simulate data and
try a power analysis -- the hardest part is figuring out what the 'theta'
(random-effects) parameters mean (the among-subject variance-covariance
matrix is a 3*3 matrix (intercept, color, size), the parameters fill in
a lower-triangular matrix
t1 0 0
t2 t4 0
t3 t5 t6
which is multiplied by its transpose
t1 t2 t3
0 t4 t5
0 0 t6
to get the variance-covariance matrix.
More information about the R-help
mailing list