A calculating problem concerning the C.I. of a random variable with known pdf.

33 Views Asked by At

Define $f(x)={N \choose{N \alpha}}x^{N \alpha}(1-x)^{N-N\alpha}$, where $f$ is defined on $(0,1)$. We further define $p(x)=\frac{f(x)}{\int_{0}^{1}f(u)du}$. Not hard to see $p(x)$ is actually a pdf on $(0,1)$. A two-tailed 95% C.I. for $X \sim p(x)$ is $(l,u)$, where $\int_{0}^{l}p(u)du=0.025$ and $\int_{u}^{1}p(u)du=0.025$. I want to find the two corresponding $\alpha\in (0,1)$ values such that $0.05=l$ and $0.05=u$ respectively.

It seems a bit hard to get a numerical result from my side. But I am also poor in programming... If one can obtain a numerical solution of $\alpha$ when $N=6000$ and $N=18000$ will do much good to me.

1

There are 1 best solutions below

1
On BEST ANSWER

This is a beta distribution with parameters $N\alpha+1$ and $N(1-\alpha)+1$. For a specific choice of $N$ ($6000$ and $18000$) and several $p$-values ($.025$ and $.975$), you're looking for the $\alpha$ which will make the $p^{th}$ quantile equal to the $.05$. This Python code should do it.

from scipy.stats import beta
from scipy.optimize import fsolve

def full_function(alpha,N,pvalue,qvalue):
    return(beta.ppf(pvalue,alpha*N+1,(1-alpha)*N+1)-qvalue)

for N in [6000,18000]:
    for pvalue in [.025,.975]:
        print(fsolve(full_function,.5,args=(N,pvalue,.05))[0])

We have a fuction, full_function, which takes values for $\alpha$, $N$, $p$, and $q$. We're then feeding in values for $N$, $p$, and $q$ ($N=6000,18000$ $p=.025,.975$, and $q=.05$) and asking the fsolve function to find the $\alpha$ values. We specify the beta distribution parameters $\alpha N+1$ and $(1-\alpha)N+1$. We also use the beta.ppf function (the inverse of the cdf). This function is equal to zero when the $p^{th}$ quantile (the output of the beta.ppf function when $p$ is provided) is equal to $.05$. You can repeat this with different values of $N$, different values of $p$ (other than $.025$ and $.975$), and other values of $q$ ($.05$).

These are the results I got.

N:6000|p:0.025|alpha:0.05550970939945436

N:6000|p:0.975|alpha:0.044482436934298104

N:18000|p:0.025|alpha:0.053182379001362114

N:18000|p:0.975|alpha:0.04681498679996298