I am running an analysis on the effect of canopy cover (OverheadCover
) and the number of carcasses placed on the same location (CarcassNumber
) on the proportion of carrion eaten by birds (ProportionBirdsScavenging
). These data points were collected at different national parks, so I aim to include Area
as a random factor. Long story short, I want to test for an interaction effect of OverheadCover
and CarcassNumber
. Test data and analysis below.
library(mgcv)
data_both <- data.frame(ProportionBirdsScavenging = c(0.406192519926425, 0.871428571428571, 0.452995391705069, 0.484821428571429, 0.795866569978245, 0.985714285714286, 0.208571428571429, 0.573982970671712, 0.694285714285714, 0.930204081632653, 0.0483709273182957, 0.0142857142857143, 0.661904761904762, 0.985714285714286, 0.0142857142857143, 0.0142857142857143),
pointWeight = c(233, 17, 341, 128, 394, 46, 5, 302, 10, 35, 57, 39, 12, 229, 28, 116),
OverheadCover = c(0.671, 0.04, 0.46, 0.65, 0.02, 0, 0.8975, 0.585, 0.6795, 0.0418, 0.5995, 0.6545, 0.02, 0, 0.92, 0.585),
CarcassNumber = as.factor(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2)),
Area = c("Hamert", "KempenBroek", "KempenBroek", "KempenBroek", "Markiezaat", "Markiezaat", "Meinweg", "Valkenhorst", "Hamert", "KempenBroek", "KempenBroek", "KempenBroek", "Markiezaat", "Markiezaat", "Meinweg", "Valkenhorst"))
gam_interaction <- mgcv::gam(ProportionBirdsScavenging ~ OverheadCover * CarcassNumber + s(Area, bs="re"), family=betar(link="logit"), data = data_both, weights = pointWeight)
summary(gam_interaction)
# Family: Beta regression(26.515)
# Link function: logit
#
# Formula:
# ProportionBirdsScavenging ~ OverheadCover * CarcassNumber + s(Area,
# bs = "re")
#
# Parametric coefficients:
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) 1.20570 0.15236 7.913 2.51e-15 ***
# OverheadCover -1.91892 0.12480 -15.376 < 2e-16 ***
# CarcassNumber2 1.76033 0.05319 33.093 < 2e-16 ***
# OverheadCover:CarcassNumber2 -8.30140 0.12432 -66.774 < 2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Approximate significance of smooth terms:
# edf Ref.df Chi.sq p-value
# s(Area) 3.792 4 452.9 <2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# R-sq.(adj) = 0.889 Deviance explained = 94.9%
# -REML = -2630.1 Scale est. = 1 n = 16
I've read that gam
's (because they work additively) do not test very well for interaction effects. However, I also found that you can add some interaction like terms to your model with the by
argument, but this only affects the model and doesn't test for interaction. By using the tensor product te()
it should work, but CarcassNumber
has insufficient unique values. Can somebody advise me on how I should properly test for an interaction effect while using gam
? Is the way I did it above (with the *
sign) scientifically correct?