0

I have been trying to model this beta distributed data for a bit now with no success. It doesn't seem to be zero-one inflated visually, but I do have some ones in my data.

Here is the description of my data (based on this answer by Alexander):

>summary(y)

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   0.0300  0.4625  0.6700  0.6229  0.8000  1.0000 

>plot(density(y))

plot

>mu <- mean(y)
>var <- var(y)
>estBetaParams <- function(mu, var) {
+  alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
+  beta <- alpha * (1 / mu - 1)
+  return(params = list(alpha = alpha, beta = beta))
+}
>estBetaParams(mu, var)

$alpha
[1] 2.446421

$beta
[1] 1.4812

So when I try to run a model as recommended here by Kori Khan and here by Ben Bolker, I get this error message:

 >library(glmmTMB)
 >mod1.beta<-glmmTMB(y~ a + b + a:b +
 +                     (1|g),
 +                   data=df, family=list(family="beta",link="logit")) 


  Error in nlminb(start = par, objective = fn, gradient = gr, control =             
  control$optCtrl) : 
    gradient function must return a numeric vector of length 6
  In addition: Warning message:
  In nlminb(start = par, objective = fn, gradient = gr, control =       
  control$optCtrl) :
    NA/NaN function evaluation
  Timing stopped at: 0.023 0.004 0.028

Does someone understand why this model fails? On the Troubleshooting page for glmmTMB of the CRAN website it says that this occurs because the beta distribution is not appropriate with negative values but I have no negative values in my response variable.

I have been looking into adding zero-one inflation into the model because I have 1.00s in y, but I'm not sure if I have enough 1.00s to qualify for a one-inflated beta distribution. If I do I'm not sure how to go about specifying it in the code and haven't been able to find an example of how to integrate that into the model anywhere.

Thank you.

KatherineD
  • 15
  • 7
  • It's because you have 1's in your response variable. For beta regression, the response variable needs to satisfy $y\in(0,1)$. [Cribari-Neto & Zeileis](https://cran.r-project.org/web/packages/betareg/vignettes/betareg.pdf) recommend using the transformation $(y(n - 1) + 0.5)/n$ where $n$ is the sample size in cases where 0's or 1's are present in the response variable $y$. – COOLSerdash Mar 13 '18 at 19:28
  • I just found this question (https://stats.stackexchange.com/questions/31300/dealing-with-0-1-values-in-a-beta-regression) thats very similar to mine now that I understand what the problem is! Thank you! – KatherineD Mar 14 '18 at 14:58

0 Answers0