Problems when adding a variance structure into a GLMM I did a GLMM model with proportional data using the lme4 package.
This model has three categorical independent variables:


*

*Age (2 levels)

*Sex (2 levels)

*Status (2 levels)
"Year" is the random factor.
There are no NA's.
The model would be:
FL_F <- glmer(cbind(Fledglings, Hatchlings-Fledglings) ~ Sex * Age + Sex * Status + (1 | Year), data = DataF5, family = binomial)
I show the residuals vs fitted of the model. It is possible to observe a clear heterogeneity pattern:
plot(FL_F)

Once I checked the residuals vs fitted I decided to add a structure to the variance, so I changed into glmmPQL (MASS) to be able to add varIdent trying to get a better pattern of the residuals.
In this case the model is as following:
VS1 <- varIdent (form = ~ 1 | Year) ## the structure of the variance
FL_F2 <- glmmPQL (cbind(Fledglings, Hatchlings-Fledglings) ~ FDisSta*MAge + FDisSta*MDisSta, random = ~ 1 | Year, family = binomial, weights= VS1, data = DataF5)
But the problem comes with an error message:
Error in model.frame.default(data = DataF5, weights = varIdent(form = ~1 |  : 
  variable lengths differ (found for '(weights)')
I can't fix this error because I don't know exactly where it is, if when creating VS1 or later in FL_F2. I am not sure if it is related with the problem but when creating VS1 in Rstudio (right-upper panel) the description says Classes 'varIdent', 'varFunc' atomic (0);  and I doubt if that 0 should be a 0.
I've been reading Zuur et al (2009) Mixed effect models and extensions in ecology with R and all the examples therein with varIdent, but I can't see any differences with my script.
Does anyone know why I am having this problem?
I'd very much appreciate your help.
Thanks in advance.
 A: I suggest that you first write down the mathematical equation of the model that you are trying to fit. You will then see that it doesn't make sense. We used varIdent for a Gaussian model....you use it for a binomial.
And I have never been a fan of using Year as random effect.
Alain Zuur
A: EDIT I completely overlooked that the functions used were not in nlme.
So the reason is a much simpler one: the varFunctions are into the nlme package: they are neither compatible with MASS::glmmPQL nor lme4::glmer.
glmmPQL, as well as glm(), instead, can manage a vector of prior weights. END EDIT
Late, aware that taken literally the ask is about the code and not Statistics, so completely  ignoring the issue whether it makes sense or not to do it, but to only answer the question :

I can't fix this error because I don't know exactly where it is, if when creating VS1 or later in FL_F2

my answer is that the error message reporting:
variable lengths differ (found for '(weights)')

seems due to lacking initialization of the VS1 object, by means of
VS1<-Initialize(VS1, DataF5)

Note that the function has been renamed from initialize () - as it appears in Pinheiro and Bates (2000) - to Initialize (), with a capital letter - as reported by Zuur et al. (2009). Unfortunately, when using the previous name the printed error message is not
'function initialize() not found' 

as might be expected, but something like
'Error in getClass(Class) : 
  c("“varIdent” is not a defined class", "“varFunc” is not a defined class")' 

that may result quite misleading.
