# Likelihood for BetaBinomialDistribution with variable number of trials [closed]

BetaBinomialDistribution is parametrized by three parameters [α, β, n], so it appears that all manipulations are limited to having a single value of n. Is it possible to re-define the distribution so it would take multiple different trial size as part of the data along with observation counts, and allow to use FindDistributionParameters on it ? Also - how can I compute the likelihood for a sample with variable number of trials, so the data is, for example:

1 success out of 2 trials
17 successes out of 30 trials

d = {1, 17};
n = {2, 30};


## closed as off-topic by ciao, corey979, Feyre, MarcoB, SaschaJan 12 '17 at 7:23

• The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Is this a question about data, or a question about the Beta Binomial distribution? Is not the point of the BetaBinomial that the success probability $p$, instead of being fixed, is itself a random variable with a Beta(a,b) distribution. – wolfies Jan 11 '17 at 18:08
• I don't think this should migrated. I think it's about BetaBinomialDistribution – m_goldberg Jan 11 '17 at 22:41
• This is about using BetaBinomialDistribution functionality within Mathematica. – Leon Jan 12 '17 at 2:20
• I've voted to close because the question is not specific enough. My guess is that the OP has two different samples from beta binomial random variables with common parameters $\alpha$ and $\beta$ and known sample sizes, 1 and 17. The objective is to use the two different samples to obtain maximum likelihood estimates of $\alpha$ and $\beta$. But it is likely that the maximum likelihood estimators won't be very good given that one of the sample sizes is 1. Alternatively, the OP might want the distribution of the sum of the two random variables. In short, more specifics are needed. – JimB Jan 12 '17 at 3:52
• I understand that you're new to Mathematica and to this forum. What's needed (usually) is to show your effort to write Mathematica code and that you have looked at the online manual. The functions Likelihood and LogLikelihood are very explicit. But when questions sound like "Supply the code to do the following...", you at best won't get the depth of response or level of interest that would be helpful. – JimB Jan 15 '17 at 0:55

## 1 Answer

If you want maximum likelihood estimates based on multiple samples from beta binomial distributions with the same parameters $\alpha$ and $\beta$ but the fixed and known sample sizes vary, then here is an approach to do so:

(* Sample sizes *)
n = {2, 30, 20, 21, 56, 27};

(* Random samples with α=3 and β=2 *)
SeedRandom[13];
d = Flatten[
Table[RandomVariate[BetaBinomialDistribution[3, 2, n[[i]]], 1], {i, Length[n]}]];

(* Log of likelihood *)
logL = Sum[LogLikelihood[BetaBinomialDistribution[α, β, n[[i]]], {d[[i]]}], {i, Length[n]}];

(* Find maximum likelihood estimates *)
sol = FindMaximum[{logL, α > 0 && β > 0}, {{α, 3}, {β, 2}}]
(* {-16.74694495424507,{α -> 3.5777414111204497,β -> 2.871340409996666}} *)


Update

It turns out that if one creates a multivariate random variable using TransformedDistribution, one can then use FindDistributionParameters directly (at least for this combination of distributions):

(*Sample sizes*)
n = {2, 30, 20, 21, 56, 27};

dist = TransformedDistribution[
Table[ToExpression["x" <> ToString[i]], {i, Length[n]}],
Table[ToExpression["x" <> ToString[i]] \[Distributed]
BetaBinomialDistribution[a, b, n[[i]]], {i, Length[n]}]]

(*Random samples with α=3 and β=2*)
SeedRandom[13];
x = Flatten[Table[RandomVariate[BetaBinomialDistribution[3, 2, n[[i]]], 1], {i, Length[n]}]];

FindDistributionParameters[{x}, dist]
(* {a -> 3.5777390778400413,b -> 2.8713390386213904} *)

• Thank you, you must have seen my second question (moved to StackExchange for some reason) and in addition to answering this one also almost answered the second one. The first one was about Mathematica syntax to use in order to work with variable sample sizes. I see how to do that now. The second was about getting confidence intervals on parameter estimates (instead of a point estimate). Also would be most helpful to parametrize not with "shape" parameters alpha and beta but with the proportion and deviance. – Leon Jan 12 '17 at 21:32
• For both questions I highly recommend re-writing your questions in terms of Mathematica code and explicit objectives. As you've hopefully noticed, the above question is on hold until you make such changes. You can't just say "Is there a way to work with a variable number of trials?" With a more explicit question you'll get more and better help. If you do so, I'll supply an explicit answer to your other question on confidence intervals. – JimB Jan 12 '17 at 22:09
• And by "re-writing" I mean "editing the existing question". – JimB Jan 12 '17 at 23:26
• I am happy to try, except being new to this format I am not sure what is expected of me. In fact my question here (not the other one) was about the existence of appropriate syntax. Thank you very much for your help. Also - I do not understand how do I re-gain access to the other question and ability to edit it since it is moved to another forum. – Leon Jan 15 '17 at 0:34
• Your other question is at stats.stackexchange.com/questions/255754/…. Hit the 'edit' button just at the bottom left of your question and add in the necessary details (such as what $\theta$ is exactly and that you intend to run the analyses in Mathematica). – JimB Jan 15 '17 at 3:12