[R-sig-ME] mixed model

Ben Bolker bbolker at gmail.com
Thu Aug 11 04:34:52 CEST 2011


> Ahmad Rabiee <ahmadr at ...> writes:

# I have a binomial dataset (0, 1),

  this is a key piece of information not stated previously
(or I missed it ...)

> and would like to run a "mixed model"
# logistic regression and also a "nested mixed model" logistic regression
# using glmer:
# 
# ket.glm1 <- glmer(z_ket_1.4 ~  bcs_pre + bhb_date + lact  + (1 | herdno) ,
# family = binomial, data = ket)

  If your data are binomial with values 0/1 (i.e., "binary" or "Bernoulli"),
it makes sense to incorporate neither overdispersion nor zero-inflation.

# To account for the overdispersion in the dataset, I used the following codes
# (according to lme4 package), but the output is identical to the first model
# (above= ket.hlm1). Comments  please?
# 
# # Mixed model accounting for overdispersion
# 
# ket$obs <- 1:nrow(ket)
# 
# ket.glm2 <- glmer(z_ket_1.4 ~  bcs_pre + bhb_date + lact  + (1 | herdno)  +
# (1|obs), family = binomial, data = ket) 

  As stated above, overdispersion is unidentifiable with binary data. 

# #Nest random effect 
# When I want to run a nested random effects using "glmer" I get an error
# message (below);
# 
# # herds nested within studies
# 
# ket.glm43<- glmer(z_ket_1.4 ~  bcs_pre + bhb_date + lact +
# (1|studyid:herdno) + (1|id), family = binomial, data = ket)
# 
# #Error message (What does this mean?)
# 
# Error: length(f1) == length(f2) is not TRUE
# 
# In addition: Warning messages:
# 
# 1: In study:herdno :
# 
#   numerical expression has 2695 elements: only the first used

[snip]

  It means that you need studyid and herdno to be factors, not
numeric variables, in order for this to work.

# I believe my dataset (binomial) is zero-inflated- and Ben suggested that I
# should use the "glmmadmb" package to count for the zero-inflation (Please
# correct me if I am wrong). I can run this model (below), when I don't have a
# random effects term in the model. But I don't understand the outputs:

  When I suggested that, it was before I knew your data were binary.
Zero-inflation doesn't make sense for binary data.

# # first model (without random effects term)
# 
# ket.glmm1 <- glmmadmb(z_ket_1.4 ~  bcs_pre + bhb_date + lact , family =
# "binomial", data = ket)
# 
# summary(ket.glmm2)
# 
# Initial statistics: 10 variables; iteration 0; function evaluation 0; phase
# 1
[snip]

# Estimated covariance matrix may not be positive definite
# 
# 4.44173 4.92261 5.06046 5.06419 5.35787 5.45402 5.62318 6.84209 8.1491
# 11.1008 
# 
# When I run "glmmadmb" with a random effects term in the model, I get an
# error message. I don't know what I am doing wrong here. Any help would be
# greatly appreciated.
# 
# # Mixed model (herdno is the random effects term)
# 
# ket.glmm2 <- glmmadmb(z_ket_1.4 ~  bcs_pre + bhb_date + lact +  (1 |
# herdno), family = "binomial", data = ket)
# 
# summary(ket.glmm2)
# 
# #Error message
# 
# Error in process_randformula(formula, random, data = data) : 
# 
#   all grouping variables must be factors

  What it says.  herdno must be a factor.

  Ben Bolker




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