# Likelihood ratio test using random number generation

Let $X_1,X_2,...,X_{10}$ be a random sample from the density $\theta_1 x^{(\theta_1-1)}I_{(0,1)}(x)$ and let $Y_1,Y_2,...,Y_{20}$ be a random sample from the density $\theta_ 2y^{(\theta_2-1)}I_{(0,1)}(y)$ . Assume that the samples are independent. Find the likelihood ratio test for
$H_0:\theta_1=\theta_2$ vs $H_a:\theta_1\neq \theta_2$ at size= 0.05

This is what I did:
I found $\hat \theta_1=$$-10\over \sum_{i=1}^{10}ln(x_i) \hat \theta_2=$$-20\over \sum_{i=1}^{20}ln(y_i)$
Under $H_0$ when $\theta_1=\theta_2=\theta$
$\hat \theta=$$-30\over \sum_{i=1}^{10}ln(x_i)+\sum_{i=1}^{20}ln(y_i) Therefore likelihood ratio \Delta=$$(\hat \theta_1)^{10} \prod_{i=1}^{10}x_i^{(\hat\theta_1-1)} (\hat \theta_2)^{20} \prod_{i=1}^{20}y_i^{(\hat\theta_2-1)}\over{(\hat \theta)^{30} \prod_{i=1}^{10}x_i^{(\hat\theta-1)}\prod_{i=1}^{20}y_i^{(\hat\theta-1)}}$

Decision rule : Reject $H_0$ when $\Delta>k$

So I want Pr(reject Ho when $H_0$ is true)=0.05
Pr($\Delta>k$ when $\theta_1=\theta_2=\theta$ )=0.05

My question is under $H_0$ does $\Delta=1$?

From inversion method I found $\hat\theta_1$ and $\hat\theta_2$ as following.
Here $\theta=1.5$

inv<-function(n,theta){
m<-c()
for(i in 1:n){
u<-runif(1)
x<-u^(1/theta)
m<-c(m,x)
}
t<-log(m,base=exp(1))
-n/sum(t)

}
theta1=inv(10,1.5)
theta2=inv(20,1.5)
> theta1
 0.9755558
> theta2
 0.8359643


Now how can I proceed to find k?
I wrote the following R code for it but it runs forever.

likelihood<-function(nsim,m,n,theta){
k<-c()
w<-c()
v<-c()
f<-c()
g<-c()
delta<-c()
for (i in 1:nsim){
for(i in 1:m){
u<-runif(1)
a<-u^(1/theta)
w<-c(w,a^(theta1-1))
f<-c(f,a^(theta-1))

}
for(i in 1:n){
u<-runif(1)
b<-u^(1/theta)
v<-c(v,b^(theta2-1))
g<-c(g,b^(theta-1))

}
d<-(theta1^m*prod(w)*theta2*prod(v))/(theta^(m+n)*prod(f)*prod(g))
delta<-c(delta,d)

}
delta

}

s<-likelihood(10,10,20,1.5)
quantile(s,0.95)


Can someone plaese tell me how I can come up with a likelihood ratio test.

• try stats SE?.. – BCLC Nov 18 '15 at 3:05