Working in R. I'm having trouble with calculating my predicted values to the response scale when I have to exclude a random effect from the prediction. By excluding the random effect from the prediction, I need to specify type = "terms"
, hereby making it impossible to include the type = "response"
argument. Is there a way of recalculating the predicted values to the response scale (beta regression)? Or is it possible to both specify the exclusion of Area
and type = "response"
in the predict
function? Please see my code below.
str(data_re)
# 'data.frame': 35 obs. of 17 variables:
# $ ProportionBirdsScavenging: num 0.6619 0.4062 0.6943 0.0143 0.0143 ...
# $ OverheadCover : num 0.7 0.671 0.679 0.79 0.62 ...
# $ Area : Factor w/ 6 levels "Hamert","KempenBroek",..: 3 1 1 1 1 1 1 1 1 2 ...
# $ pointWeight : int 3 233 10 89 4 22 44 99 89 17 ...
mygam <- mgcv::gam(ProportionBirdsScavenging ~ OverheadCover + s(Area, bs="re"), family=betar(link="logit"), data = data_re, weights = pointWeight)
new.xgam <- expand.grid(OverheadCover = seq(0, 1, length.out = 1000))
new.xgam$Area <- "a" # pad new.xgam with an arbitrary value for variable Area -> https://stackoverflow.com/questions/54411851/mgcv-how-to-use-exclude-argument-in-predict-gam
new.ygam <- predict.gam(mygam, newdata = new.xgam, type = "terms", exclude = "s(Area)") # Because I have to specify type = "terms", I can't specify type = "response".
new.ygam <- data.frame(new.ygam)
head(new.ygam) # not on the response scale (0,1)
# OverheadCover
# 1 0.000000000
# 2 -0.004390776
# 3 -0.008781551
# 4 -0.013172327
# 5 -0.017563103
# 6 -0.021953878