Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Computer Exercise Week 9

STAT3023: Statistical Inference

Semester 2, 2022

Two-sided tests for a normal variance

Suppose X1 , . . . , Xn   are iid  N (µ, σ2 ).   In the week  8  Tutorial it was noted that the statistic  Y  = (n - 1)S2  =     (Xi  - )2   (where  =       Xi  and S2  are the sample mean and variance) has a σ 2 χn(2) 1  distribution (note we are not multiplying by  as we did in the week 8 Tutorial!).  Consider testing

H0 : σ 2  = 1 against H1 : σ 2    1.                                                       (1)

1.   One possible level-α test is the equal-tailed” test based on Y , where we reject for Y < a or Y > b where

α

P0 {Y < a} = P0 {Y > b} =

(a)  Taking α = 0.04 and n = 5, find appropriate values a and b.

(b)  Defining sig .sq=(50:150)/100, plot the power of the test against sig .sq. Add a horizontal

dotted line to indicate the level.

2.  In Tutorial week 8 we also saw that the UMPU test rejects for large values of S2 - log(S2 ),

which is equivalent to rejecting for small values of the statistic

T = (n - 1) log Y - Y ;

to see this, write log(S2 ) = log Y - log(n - 1), multiply through by n - 1 and ignore the (n - 1) log(n - 1) term.

If the test is to have level α, we reject for Y < c or Y 2 d where

P0 (Y < c) + P0 (Y 2 d) = α

and

(n - 1) log(c) - c = (n - 1) log(d) - d .

(a)  Write a function of the form

fn=function(c ,alpha ,n)  {

}      ...

which

●  computes the appropriate d so that c and d satisfy (2);

(2)

(3)

●  then computes and outputs the difference between the left-hand side and right-hand side in (3).

(b)  Use the R function uniroot() to nd the root (in c) of the equation fn(c,0 .04,5)=0. In

your code you will need a command along the lines of

uniroot(fn,lower=0 ,upper= . . . ,alpha=0.04 ,n=5)

Consult the week 8 computer lab for some hints as to how to choose the upper= . . .. When you have worked out the right commands, wrap it all in a function of the form

norm .var .umpu=function(alpha ,n)  {

}      ...

which returns a list containing elements $c and $d. Run this function and output the values of c and d.

(c)  Recreate your plot from part (b) of the previous question and add to it the power function of the UMPU test. Use two different colours to draw the two curves and include a legend.

3.  The GLRT test of (1) above uses the statistic

Ln  = a(, Y/n; X) - a( , 1; X) = -  log _ -  +

which is an increasing function of Y - n log Y (as opposed to the UMPU which rejects for large Y - (n - 1) log Y). Adapt your code for the previous question to compute the power of the e北act GLRT, recreate your earlier plot from Q2 and add a power curve to it so it shows all 3 power curves on the 1 graph. Add an informative title and legend, etc.. Comment on the main differences between the 3 tests.

4.  As a nal step, recreate your last plot but use an extended range for the parameter: sig .sq=(1:400)/100.