I am interested in modeling total fish catch using gam in mgcv to model simple random effects for individual vessels (that make repeated trips over time in the fishery). I have 98 subjects, so I thought I would use gam instead of gamm to model the random effects. My model is:
modelGOM <- gam(TotalFish ~ factor(SetYear) + factor(SetMonth) + factor(TimePeriod) + s(SST) + s(VesselID, bs = "re", by = dum) + s(Distance, by = TimePeriod) + offset(log(HooksSet)), data = GOM, family = tw(), method = "REML")
I have coded the random effect with bs = "re" and by = dum (I read that this would allow me to predict with the vessel effects at their predicted values or zero). "dum" is a vector of 1.
The model runs, but I am having problems predicting. I picked one of the vessels for the predictions (Vessel21) and average values for everything else except the predictor of interest for predictions (Distance).
data.frame("Distance"=seq(min(GOM$Distance),max(GOM$Distance),length = 100), "SetYear" = '2006', "SetMonth" = '6', "TimePeriod" = 'A', "SST" = mean(GOM$SST), "VesselID" = 'Vessel21', "dum" = '0', #to predict without vessel effect "HooksSet" = mean(GOM$HooksSet)) pred_GOM_A_Swordfish <- predict(modelGOM, grid.bin.GOM_A_Swordfish, type = "response", se = T)
The error that I'm getting is:
Error in Predict.matrix.tprs.smooth(object, dk$data) : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: In Ops.factor(xx, object$shift[i]) : - not meaningful for factors
I think this is being called because VesselID is a factor, but I'm using it a smooth for the random effects.
I have been able to successfully predict using gam without the simple random effects (bs = "re").
Can you provide any advice on how to predict this model without the VesselID term (but still include it in fitting)?