# equations for the expected value and the variance for binomial

If my dataset was generated from a binomial random variable, can I provide estimates to the two parameters n (integer) and p? Using the equations for the expected value and the variance for binomial.

• Could you clarify how you propose using these equations? Which equations, precisely?
– whuber
Dec 3, 2020 at 12:22
• equations for the expected value and the variance for binomial. Is a dataset with 3000 random draws from a discrete random variable. Dec 3, 2020 at 14:22
• That's only half of what you need, because it doesn't use the data. Are you perhaps asking whether you can apply the method of moments to this problem? Or maximum likelihood? Or something else?
– whuber
Dec 3, 2020 at 14:25
• I think that is just " if I can apply the method" or provide estimates to the two parameters n and p? (n is an integer). Dec 3, 2020 at 14:33
• Is your question intended to be "how can I estimate $n$ and $p$?" or is it "how can I use the formulas for Binomial expectation and variance to estimate $n$ and $p$?" The latter is more restrictive and its answers might not be what you expect if you are really trying to ask the first question.
– whuber
Dec 3, 2020 at 16:02

Your question is not clear. Based on what you say here and our discussion in comments after a previous question of yours, I'm guessing that you may have something like the following in mind. If I have guessed wrongly, please try to explain more clearly exactly what information you have and exactly what you want to estimate.

Suppose, you have results from a "large number" of binomial experiments with unknown $$n$$ and $$p.$$ You are told only that $$\bar X = 70.192$$ and $$S^2 = 20.243.$$ You are wondering whether you can estimate the parameters $$n$$ and $$p.$$

Then you know that $$Var(X) = npq = np(1-p) \approx S^2 = 20.243$$ and $$E(X) = np \approx \bar X = 70.192.$$

So you estimate $$q$$ as $$\hat q = S^2/\bar X = 0.2883947.$$

q.est = 20.243/70.192;   q.est
[1] 0.2883947

Then you estimate $$p$$ as $$\hat p = 1 - \hat q = 0.711605.$$

p.est = 1-q.est;  p.est
[1] 0.7116053

Finally, you estimate $$n$$ as $$\hat n = 70.192/\hat p = 98.64,$$ which you would round to an integer.

n.est = 70.192/p.hat; n.est
[1] 98.63895

In summary, it seems reasonable to estimate $$n = 99$$ and $$p = 0.7116.$$

This procedure works reasonably well if the original $$\bar X$$ and $$S^2$$ are from a sufficiently large sample. For small samples, the estimate of $$n$$ can be astonishingly bad. (Try it a few times for $$\bar X$$ and $$S^2$$ based on fifty binomial observations.)

Note: As a reality check, I mention that I generated $$m = 3000$$ observations from $$\mathsf{Binom}(n=100, p = 0.7),$$ in R as follows:

set.seed(2020)
x = rbinom(3000, 100, .7)
mean(x);  var(x)
[1] 70.19233
[1] 20.24276
• I appreciate your time, I am taking an R course that is supposed to be basic or introductory. They are deleting my posts and they are reasonable things ... Dec 3, 2020 at 18:09
• also, this is ok to calculate the mean and variance ? randomdraws <- sample(3000, replace = TRUE) mean(randomdraws) # mean of 3000 random numbers var(randomdraws) Dec 3, 2020 at 18:11
• We use a lot of R on this site, but it may not be the best forum for learning R. // There are a lot of online sites showing various applications of R. (Some very good, some seemingly written by delusional people.) // I'm unclear what you're trying to do with the R code in your previous comment. Seems it samples 3000 items from among $1, 2, \dots, 3000.$ Are you missing an argument. // Again, it helps if you say what you're trying to do. Dec 3, 2020 at 18:21
• Mean and variance of what random variable or distribution? Dec 3, 2020 at 18:26
• "Anthony", please don't accuse users of this site of doing things they have not done. The records show that you have deleted two of your previous questions, not us. This is problematic because it destroys the helpful comments left by others, forcing everyone to start all over each time you post something new. That's not constructive. Please see our help center for more information on how this site works.
– whuber
Dec 3, 2020 at 18:35