# Model for food preference experiment

I am trying to analyze an experiment comparing consumption of 2 food types in a choice-type design. Subjects (bees) were offered a choice of 2 food types, and their daily consumption of each food type was recorded. Each subject also was assigned to one of 2 Infection treatments. We want to know-- " How does infection affect preference for one food type over another?

I am wondering if it is acceptable to model this like a repeated measures design, with 2 observations per subject and timepoint-- one for each food type. Or is that not acceptable because the 2 food types were given at the same time? The repeated measures type design seems to be what was suggested here by Ben Bolker: https://stackoverflow.com/questions/7831243/multivariate-linear-mixed-model-in-lme4

Below I paste a code to generate a random data set, to show the general data structure.

####choice analysis for list###
Df<-expand.grid(Time=seq(0,10,1),
Subject=c("Honeybunch","Buttercup","Rosy",
"Sting", "Buzz", "Bumble"))
Df$Infection<-NULL Df$Infection[1:33]<-"Infected"
Df$Infection[34:66]<-"Uninfected" Df$Infection

Df$Consumption.Food.A<-rnorm(n=length(Df$Time),mean=30, sd=6)
Df$Consumption.Food.B<-rnorm(n=length(Df$Time),mean=25, sd=8)

library(lme4)
##Analysis with consumption of other food type as covariate
ModelA<-lmer(Consumption.Food.A~ Time + Infection + Consumption.Food.B +
(1|Subject),data=Df)
ModelB<-lmer(Consumption.Food.B~ Time + Infection + Consumption.Food.A +
(1|Subject), data=Df)

#option to convert data to long format
library(tidyr)
Df_long<-gather(data=Df, key=Foodtype, value=Amt.eaten,
Consumption.Food.A,Consumption.Food.B)
View(Df_long)
#Is this model legal, because both foods offered simultaneously?
Fullmodel<-lmer(Amt.eaten ~ Foodtype * Infection + Time +
(1|Subject) + (1|Time), data=Df_long)


(Originally I was planning to model proportions of the 2 food types eaten, but the actual data has many values close to zero that could make the proportion estimates highly variable. And the proportional analysis would not account for the strong trends of decreasing with (a) time and (b) infection treatment)

1. You do not have many Subjects (6) so you cannot have anything more than rather simple random-effects structures.
2. You appear to use Time as a factor to define a random intercept (1|Time), this is somewhat counter-intuitive. I suspect you want to use it within a random slope per subject (Time|Subject).
3. Because of point 1 you will probably be unable to properly account for correlation between random factors in the context of (Time|Subject). I would suggest using uncorrelated random slopes and intercepts (Time + 0 | Subject).
4. You might need to consider using MCMCglmm to have a somewhat more informed model . This will allow you to define some weak priors for your random effects variance structure. MCMCglmm fits multivariate mixed models natively.
• I am glad I could help and that you actually have a larger number of subjects than originally presented (more data $\approx$ good thing :) ); if this is post is useful for you or answers your original question please consider upvoting it or accepting it as an answer. If you get -1/+1 correlation estimates you might want to consider the third point mentioned (I say this so you do not overlook it). – usεr11852 says Reinstate Monic Mar 25 '16 at 18:10