I have read through the emmeans "Basics of EMMs" vignette, "Working with messy data" vignette, and this Stack Overflow post but am still having a hard time knowing which 'weights' argument to use when factor levels have uneven numbers of observations.
I am using binomial GAMs with mgcv in R to model binary species presence on a hydrophone against environmental (chlorophyll-a concentration, sea-surface temperature, sea-level, vessel presence) and categorical temporal covariates (season and photoperiod):
M <- gam(Species ~ s(Chla,bs="ts") + s(SST,bs="ts") + s(SLEV,bs="ts") + Season + Photoperiod + Vessel, data=Hydrophone, family='binomial', method = "ML")
The categorical groups do not have an even number of observations (i.e. dawn/dusk photoperiods are shorter than night/day, fewer observations were gathered in summer than other season, clips with vessel presence/absence are uneven) and I am hoping to account for this when running pairwise comparisons in
contrast from the
emmeans library on my model factors. Specifically, I don't want small groups to have less weight than large groups; they should be proportional to the total number of observations per group.
I am primarily torn between using
weights="cells". The description for
weights="proportional" in the
emmeans help file makes it sound ideal since it uses "Weight in proportion to the frequencies (in the original data) of the factor combinations that are averaged over." However, when I run
contrasts I get the same results as when I run
weights="equal", which doesn't seem right.
weights="cells" uses "Weight according to the frequencies of the cells being averaged" but this is in regards to the reference grid constructed by
emmeans and I am unsure if those frequencies are the same as in the original dataset? Using
contrast gives different results than
To summarize, my question is which weighting argument accounts for unbalanced factors (i.e. different number of observations per factor level) when conducting pairwise comparisons using
contrast from the
emmeans R library?
Sorry for the long post but I wanted to provide adequate context.