# Can I construct a GAM in R for beta binomial data where the response is aggregated?

I have beta-binomial data pi = ri/ni and wish to construct a GAM using R.

My data has columns {Case, X1...Xn, R, N}

Initial thought

Stack Successes(1) & Fail(0) use mgcv:gam with weights ri & (ni-ri) respectively and family = beta. As far as i can see family = beta does not exist. The family betar is for proportions on the open interval (0, 1) rather than count (success, fail) pairs.

The main issue is being able to construct confidence intervals with a good enough overdispersion adjustment.

Other thoughts:

• As above with family quasibinomial
• As above swapping gam with gamm and specifying random effects

My question is

Can I construct a GAM in R for beta binomial data where the response is aggregated?

Edit

I have discovered I can use cbind() in the left hand side of the formula to represent binomial data

result <- gam(data=data,
formula = cbind(r, (n-r)) ~ s(x1, bs = "cs"),


Assuming the solution holds with gamm() I have an effective method for coping with aggregated binomial data having over-dispersion. The solution does not work with family=betar.

• Why not use family=betar? – Łukasz Deryło Dec 18 '19 at 13:16
• The description for family = betar specifies proportions on the open interval (0,1). It is unclear whether the denominator should be included as an offset in the model or as a weight. The application I have in mind sometimes has small denominators leading {0, 1} data which the package help tells me causes additional problems. – Dave Dec 18 '19 at 13:45
• OK, I understand and think you should include this info in your question. – Łukasz Deryło Dec 18 '19 at 13:56