# Estimators for Bernoulli trials

I have failure data for an experience over $T$ years: at the beginning of each year I have $n_t$ subjects and $d_t$ of these subjects experience a "failure" at the end of the year.

Now if I assume that the trials are iid Binomial and the probability of failure $p$ is homogenous (i.e. constant over time), the ML estimator is given by

$$\hat{p}=\frac{\sum\limits_{i=1}^T d_t}{\sum\limits_{i=1}^T n_t}$$

However, there is an alternate estimator:

$$\bar{p}=\frac{1}{T}\sum\limits_{i=1}^T \frac{d_t}{n_t}.$$

What would be the assumptions and the model so that the estimate is $\bar{p}$?

===========================

EDIT:

The question is not about the relative merits of the two estimators. For example, it is not necessary to assume homogeneity for the second estimator. I am wondering about the assumptions that would "naturally" lead to the second estimator.

===========================

EDIT2:

I am in a situation where $\bar{p}$ is imposed as an estimator. I need to come up with confidence intervals or credible intervals for the estimate. My idea was to determine the assumptions (possibly a hierarchical model) and do a MCMC using JAGS...

-

Your model for estimator $\hat{p}$ is actually of a single system that was operated $n_i$ times in year $i$, $1 \leq i \leq T$, and failed $d_i$ times that year. Presumably the system was successfully repaired and restored to perfect working condition before the next time it was operated.

Your model for estimator $\bar{p}$ is that of $n_i$ independent copies of Model $i$ of the system being put in operation in year $i$ and $d_i$ of those copies failing independently. You wish to estimate the average failure rate per year over $T$ years.

-

I believe both can be considered as estimators of $p$ for the same model under different 'estimating equations'. It $appears$ to me that both estimators have the same mean (see the discussion below). Therefore, I don't think biasedness is a useful criteria to pick one. Let me define $N:=\sum_{t=1}^T n_t$, then

$$\hat p = \sum_{t=1}^T \frac{d_t}{N} =\sum_{t=1}^T \frac{n_t}{N}\frac{d_t}{n_t} .$$

Therefore, if $n_t$ does not change much over time, $\frac{n_t}{N} \approx \frac{1}{T}$, the estimators will be very similar. But if this values are different, they will differ of course. Check the following R code for an illustration.

ss = c(10,50)
e1 = function(x) return(sum(x)/sum(ss))
e2 = function(x) return(mean(x/ss))
e1v = e2v = rep(0,100)
for(j in 1:100){
x = rbinom(length(ss), size = ss, 0.5)
e1v[j] = e1(x)
e2v[j] = e2(x)
}
plot(e1v-e2v,type='l',col='red')
plot(e1v,type='l',col='red',ylim=c(0.2,0.8))
points(e2v,type='l',col='blue')


Second code

ss = seq(10,20,1)
e1 = function(x) return(sum(x)/sum(ss))
e2 = function(x) return(mean(x/ss))
e1v = e2v = rep(0,10000)
for(j in 1:10000){
x = rbinom(length(ss), size = ss, 0.5)
e1v[j] = e1(x)
e2v[j] = e2(x)
}

c(quantile(e1v,0.025),quantile(e1v,0.975))
hist(e1v)

c(quantile(e2v,0.025),quantile(e2v,0.975))
hist(e2v)

-
@Dilip He is assuming that $p$, the failure rate, is homogeneous. Then, wishing to estimate the average failure rate is equivalent to estimate $p$. Your second statement is a tautology. –  Papo Feb 9 '12 at 13:46
I like the approach--arguing from fundamental ideas--but it would be nice to see the calculations supporting the assumptions in the first paragraph. It appears to me that the estimators have different variances except when all the $n_i$ are equal and otherwise the first estimator has smaller variance: this comes down to the famous (and elementary) inequality between the harmonic and arithmetic means. –  whuber Feb 9 '12 at 14:11
But if the numbers $n_i$ differ significantly e.g. the number of subjects grow year by year, then $\hat{p}$ is dominated by the failures experienced in the most prolific years while $\bar{p}$ is less so. My gut feeling is that $\bar{p}$ is a better statistic for estimating $p$ than $\hat{p}$ is. –  Dilip Sarwate Feb 9 '12 at 14:15
@whuber $d_t\sim Bin(n_t,p)$, then $E[d_t]=n_tp$. Taking linearity into account it follows that $E[\hat p] = E[\bar p] = p$ from which unbiasedness follows. You are completely right about the variances. I will modify my answer and I would like to see your calculation about the variances (given that you noticed this, I don't want to steal the credit and maybe this will tell us which estimator is better). –  Papo Feb 9 '12 at 14:17
@Dilip If $n_i$ differ but you assume homogeneity of the parameter $p$, then the likelihood function is the product of the likelihoods corresponding to each experiment from which you obtain the same estimator $\hat p$. I have the same feeling about which estimator is better. –  Papo Feb 9 '12 at 14:24