I want to fit beta-binomial regression. I don't have counts but proportions that I want to fit. Here's example:
library(dplyr)
library(gamlss)
df <- tibble(
cluster = LETTERS[1:20]
) |>
mutate(
p = rbeta(n(), 1, 1),
n = as.integer(3 * runif(n()))
)
fit <- gamlss(
p ~ log(n),
weights = n,
data = df,
family = BB(mu.link='identity')
)
I get error:
Error in while (abs(olddv - dv) > cc && itn < cyc) { :
missing value where TRUE/FALSE needed
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Warnings look like:
In dbinom(x, size = bd, prob = mu, log = log) : non-integer x = 0.834502
Note that I DON'T want to rounded number of successes such as mutate(y = round(p * n))
.
The help file for the
BB()
family suggests that the dependent variable is expected to be a two-column matrix of the numbers of successes and failures. If you've gotp
(the probability of success) and you've gotn
(the number of trials), then you can make both the number of successesk=floor(p*n)
and the number of failuresnotk = n-k
. Then, you can do as I did below.Created on 2023-01-20 by the reprex package (v2.0.1)