[R] Help with logistic model with random effects in R
Ben Bolker
bbolker at gmail.com
Wed Jan 19 23:05:02 CET 2011
LAURA WEIR <0611792W <at> student.gla.ac.uk> writes:
>
> Hello everyone,
>
> I'm quite new to R and am trying to run a logistic model
> to look at how various measures of boldness in
> individual animals influences probability of capture,
> however I also want to include random effects and
> I'm not sure how to construct a model that incorporates both
> of these things.
>
> Data was collected from 6 different groups of 6 individuals
> with 10 replicates for each group. Whether an
> individual was caught in a trial or not was called "Catchability"
> and the outcome is binomial (caught = 1,
> not caught = 0). "Catchability" is my response variable that
> I want to see if I can explain by the other
> variables. "Individual" and "Group" would be my random effects.
> I have already installed lme4 but not
> sure how to code for the model I need, can anyone offer any help please?
>
> The column headings in my data table are as follows.
>
> [1] "Trial" "Group" "Individual" "Mark"
> [5] "Catchability" "Mboldness1" "Mboldness2" "Nboldness1"
> [9] "Nboldness2" "Standardlength"
>
> This is the string of my data:
>
> str(data)
> 'data.frame': 36 obs. of 10 variables:
> $ Trial : int 1 2 3 4 5 6 7 8 9 10 ...
> $ Group : int 1 1 1 1 1 1 2 2 2 2 ...
> $ Individual : int 1 2 3 4 5 6 7 8 9 10 ...
> $ Mark : Factor w/ 8 levels " - O"," - P",..:
> 8 2 4 6 3 1 6 3 1 5 ...
> $ Catchability : int 1 1 1 1 0 1 1 1 1 1 ...
> $ Mboldness1 : int 7 10 0 11 15 5 15 4 15 1 ...
> $ Mboldness2 : int 1 270 600 1 10 203 10 230 1 580 ...
> $ Nboldness1 : int 0 0 0 0 0 0 1 0 2 0 ...
> $ Nboldness2 : int 270 110 50 50 90 70 130 90 260 220 ...
> $ Standardlength: num 40.5 37.4 38.6 41.1 39.1 40.5 50.2 60.3 53.9 55 ...
>
I'm a little confused about your experimental design. You say you
have 10 replicates per group, but I only see 36 observations in your
data set -- from your description I would have expected 360?
If you had 10 replicates per group I would say should do something like
glmer(Catchability~[fixed effect predictors]+(1|Group/Individual),
family=binomial,data=data)
A couple of other points:
* it's considered bad practice to name your data set 'data' (which is
also the name of a built-in R function). Usually it's OK, but occasionally
it could cause problems.
* A rule of thumb is that you should not try to fit a model with
more than k=N/10 parameters, where for binary data 'N' is the minimum
of (number of successes, number of failures).
* 6 groups is at the lower edge of feasibility for fitting a random
effect -- you may find that glmer estimates the group-level variance
as zero. (Don't panic.)
I would suggest that you send follow-ups to r-sig-mixed-models at r-project.org
and possibly take a look at <http://glmm.wikidot.com/faq>
cheers
Ben Bolker
More information about the R-help
mailing list