I'm having trouble with my gam()
analysis with betar
family and the weird thing is that it worked perfectly before. After I restarted R, all kinds of error and warning messages showed up.
I'm analysing the effect of a proportion on another proportion (0,1) and a random effect (factor) with the betaregression family. The data is shown below.
> str(data_original)
'data.frame': 35 obs. of 17 variables:
$ X : int 1 2 3 4 5 6 7 8 9 10 ...
$ IndividualCarcassCode : Factor w/ 35 levels "1e Hogerwaarddwarsweg _1",..: 1 2 3 4 5 6 7 8 9 10 ...
$ Birds : int 2 94 7 0 0 1 11 70 56 15 ...
$ Mammals : int 1 139 3 89 4 21 33 29 33 2 ...
$ ProportionBirdsScavenging: num 0.6619 0.4062 0.6943 0.0143 0.0143 ...
$ pointWeight : int 3 233 10 89 4 22 44 99 89 17 ...
$ Area : Factor w/ 6 levels "Hamert","KempenBroek",..: 3 1 1 1 1 1 1 1 1 2 ...
$ OverheadCover : num 0.7 0.671 0.679 0.79 0.62 ...
$ Carcass_sp : Factor w/ 5 levels "Capreolus capreolus",..: 5 1 1 1 3 1 1 1 1 1 ...
$ Carcass_sp_diet : Factor w/ 3 levels "herbivore","omnivore",..: 3 1 1 1 2 1 1 1 1 1 ...
$ Carcass_open : logi TRUE FALSE FALSE TRUE FALSE FALSE ...
$ firstCarcassOnLocation : logi TRUE TRUE FALSE FALSE FALSE FALSE ...
$ StartMonitor : Factor w/ 33 levels "01/07/2015","01/11/2018",..: 33 16 27 1 11 12 31 14 29 26 ...
$ EndMonitor : Factor w/ 34 levels "01/05/2018","01/10/2019",..: 33 3 11 32 14 30 9 5 21 1 ...
$ DurationUntilDepletion : int 30 78 77 90 35 44 43 84 54 63 ...
$ MonitorPeriod : Factor w/ 14 levels "100% constant",..: 3 10 6 1 2 2 11 2 7 2 ...
$ GPS : Factor w/ 19 levels "51.16201, 6.13967",..: 8 11 11 11 11 11 11 12 13 6 ...
This is my call
mygam = gam(ProportionBirdsScavenging ~ OverheadCover + s(Area, bs="re"), family=betar(link="logit"), data = data_original, weights = pointWeight)
When I run this, it shows me Error in is.factor(...) : unused argument (bs = "re")
.
I have read the information on ?gam::s
, ?is.factor
, ?mgcv::gam
, searched the internet, but could not find anything which works for me. I have experimented with changing the structure of Area
, tried different parameters, updating all the packages, copied exact code from working scripts online and filled in my variables. That last method showed me that it has probably something to do with my data, and not my call. As far as I understand, the data structure should be suitable for such an analysis. Besides, it worked perfectly with exactly the same data (and script) before.
If I try the call without the random factor
mygam = gam(ProportionBirdsScavenging ~ OverheadCover, family=betar(link="logit"), data = data_original, weights = pointWeight)
It shows me Warning message: In model.matrix.default(mt, mf, contrasts) : non-list contrasts argument ignored
, but works fine. After some research online I found that this has probably to do with something an update (what could explain why it worked differently after I restarted R). Apparently, this message used to be silent but with a new update not anymore. Can anyone confirm this? Should I be worried about this warning?
If I do the gam.check
it gives me Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
which is weird, because the lengths are equal (both 35).
However, the gam
without + s(Area, bs="re")
works fine, but if I then try to do
coeftest(mygam, vcov = sandwich)
It tells me Error in bread. %*% meat. : non-conformable arguments
. A coeftest
without the sandwich
works fine, so it has to do with vcov = sandwich
. An internet search does not give much and did unfortunately not yield an answer.
Does anyone have an idea what is happening here? I'd love to hear thoughts and ideas. At the end, I'm trying to run a gam
with Area
as a random effect, but I think the other warnings and error messages might lead us to the problem.