I have sampled animals at a number of sites and time points. Each site is sampled up to 4 times a year and is sampled over multiple years. At each site*time combination a maximum of 20 animals were sampled, with the number varying at each site*time combination. Each animal was tested for 3 different viruses. I have also collected some site*time level co-variates, such as animal abundance at a at each site*time combination.

I am modelling the prevalence of virus_1 at the site*time level, i.e I have a single prevalence value for each combination of site*time. To account for differences in the number of animals sampled at each site*time combination I have built what I understand to be a weighted logistic regression model - where the response variable is the prevalence of virus_1, weighted by the number of animals sampled at each site*time combination. I have included a nested random effect to account for repeated measures through time within sites.

Model <- glmmTMB(cbind(count_virus_1_positive, count_virus_1_negative) ~  prevalence_virus_2 + prevalence_virus_3 + site_abundance + (1 | site / time), data = data, family = binomial)

Question: How do I account for differences in the number of animals sampled at each site*time combination in my predictor variables?

i.e I have include the prevalence of virus_2 and virus_3 as predictors in my model; these predictors are also influenced by the number of animals sampled at site*time combination. An offset() for the number of animals sampled at each site*time combination maybe? If I included an offset() for the number of animals sampled at each site*time combination would this mean that for my response variable I am accounting for the number of animals sampled at each site*time combination twice, once using cbind(success, failure) as the response variable and once using the offset()?

  • 1
    $\begingroup$ Please try not to ask multiple questions in a single post. You can make as many posts if you want and reference the others. Partial answer to your question: The replication is not of time, but of animals. You can account for measuring three different viruses by including a random effect for the animal and a fixed effect for virus. Perhaps a random slope for virus if you have theoretical reasons to expect animal-specific responses to the viruses, but this will more likely overfit than just a random intercept. $\endgroup$ – Frans Rodenburg Nov 28 '19 at 6:41

For simplicity, and to focus on your main question, I will initially set aside the fact that you are looking at three different viruses, and just focus on one. Evidently you have count variables that count the number of positive and negative outcomes on your viral test. The normal thing to do with this type of count data is to model the positive counts (or equivalently, the negative counts) and include an offset term for the exposure variable, which is the total number of animals exposed (i.e., the sum of the positive and negative counts. Since you have not stated which is your exposure variable, I will just refer to this variable as exposure (i.e., this is the variable that counts the number of animals exposed at each site).

On this basis (and looking at only one of the viruses), a simple formulation of a logistic regression would be something like this:

#Create exposure variable
data$virus    <- data$count_virus_1_positive;
data$exposure <- data$count_virus_1_positive + data$count_virus_1_negative;

#Fit logistic regression model
MODEL   <- glm(virus ~ offset(log(exposure)) + site*time,  
               data = data, family = binomial);

This kind of formula would give you a base model, and then you can alter it to add additional explanatory variables, or mixed effects, if you prefer. In any case, by including the exposure variable as a logarithmic offset term in your (logarithmic) link function, there is then no need to look at both the positive and negative counts; your model will estimate the rate of positive tests for that virus conditional on the explanatory variables in the model. The exposure size enters into the model as a fixed offset term, and there is no double-counting of this offset.

Now, since you have three different viruses, you will have to decide if they are all of interest as response variables, or if the latter two are merely useful explanatory variables for the first virus. If they are all of interest then you will need to shift to a multivariate logistic regression (or some other multivariate model) with three binary response variables. Since this part was not the main focus of your question, I will leave it at that.

  • $\begingroup$ Thank you very much for your response. I understand that including offset(log(exposure)) as a predictor in glmmTMB() will account for different levels of exposure in my response; can you confirm that this will also account for different levels of exposure in my virus prevalence that is being used as an explanatory variable? If this is the case, then I assume it does not matter that some explanatory variables are not derivatives of this exposure variable (i.e site abundance is not derived from sampling individual animals at each site*time combination)? $\endgroup$ – Pat Taggart Nov 29 '19 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.