Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Random effect with gam() with betar family in R

$
0
0

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:
 $ 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 ...

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?

Moreover, 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). And if I plot(mygam) I see the following graph. This doesn't look right... plot.gam

However, the gam without + s(Area, bs="re") at least does not yield an error (only a warning), but an error arises when I try

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.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>