Likelihood ratio test for a normal distribution with unknown mean

562 Views Asked by At

Suppose $X_1,X_2,…,X_n$ is a random sample from a normal population with mean $μ$ and variance 16. Let sample size=16. Find the likelihood ratio test for $H_0:μ=10 $ against the simple alternative hypothesis $H_a:μ=15$ with size=0.05 and compute power of the test.

This is what I did

The MLE of $\mu$ is, $\hat\mu=\bar x$ .

$\Lambda={sup_{\theta\in \Theta}\over sup_{\theta\in \omega}}$= $ \begin{cases} e^{-1/32[ \sum_{i=1}^{16}(X_i-\bar x)^2-\sum_{i=1}^{16}(X_i-10)^2]} & \text{if $\bar x<10$ } \\ 1, & \text{if $\bar x>10$ } \end{cases}$

Decision rule, Reject $H_0 $if $Λ>k$ where k>1 such that

$sup_ {\theta\in \omega} Pr(\Lambda>k$ when $\mu=10$)<=0.05 So I wrote R code for this:

normal<-function(nsim,mu,sigma){
Lambda<-c()
for(i in 1:nsim){
    x<-rnorm(16,mu,sigma)
    m<-mean(x)
    y<- sum((x-m)^2)-sum((x-10)^2)
    if(m<10){
        lambda<-exp(-1/32*y)
    }
    else{
        lambda<- 1  
    }
    Lambda<-c(Lambda,lambda)
}
Lambda
}
p<-normal(10000,10,4)
quantile(p,0.95)

Then I get k=3.78297.

Is this correct?

For power I wrote the following code as
power=Pr(Reject $H_0$ when $H_0 $is false)=Pr(Λ>3.78297 when $\mu=15$).

normalPower<-function(nsim,mu,sigma,critvalue){
    Lambda<-c()
    for(i in 1:nsim){
        x<-rnorm(16,mu,sigma)
        m<-mean(x)
        y<- sum((x-m)^2)-sum((x-mu)^2)
        if(m<15){
            lambda<-exp(-1/32*y)
        }
        else{
            lambda<- 1  
        }
        Lambda<-c(Lambda,lambda)
    }
    y<-sum((Lambda>critvalue)*1)/nsim
    y

}
p1<-normalPower(10000,15,4,3.78297)
p1

The power I get is > p1 [1] 0.0471
Why do I get such low power value?Is this correct?
In the power function is my line if(m<15)correct?