程序代写代做代考 html graph C The University of Sydney School of Mathematics and Statistics

The University of Sydney School of Mathematics and Statistics
Computer Exercise Week 8
STAT3023: Statistical Inference
Web Page: https://sydney.edu.au/science/maths/STAT3023 Lecturers: Rachel Wang and Michael Stewart
Two-sided tests for a normal variance
Semester 2, 2020
Prepare your computer report and submit to the appropriate Canvas portal by 11:59pm Sunday 25th October. Please include in your report all the code, plots and any comments required by the questions. The upload format will be restricted to PDF, HTML or Word, created any way that is convenient as long as it includes all the required content.
Suppose X1,…,Xn are iid N(μ,σ2). In the week 7 Tutorial it was noted that the statistic Y = (n−1)S2 = 􏰂n (Xi −X ̄)2 (where X ̄ = 1 􏰂n Xi and S2 are the sample mean and variance) is
i=1
sufficient for σ2 and has a σ2χ2
n i=1
distribution (note we are not multiplying by 1 as we did in the week
2
7 Tutorial!). Consider testing
n−1
H0:σ2 =1againstH1:σ2 ̸=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 b}= α. 2
(a) Taking α = 0.05 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 7 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.
Ifthetestistohavelevelα,werejectforY ≤corY ≥dwhere
P0(Y ≤c)+P0(Y ≥d)=α (2)
and
(n − 1) log(c) − c = (n − 1) log(d) − d . (3)
(a) Write a function of the form
which
Copyright ⃝c 2020 The University of Sydney 1
(1)
fn=function(c,alpha,n) { …
}

• computes the appropriate d so that c and d satisfy (2);
• then computes and outputs the difference between the left-hand side and right-hand
side in (3).
(b) Use the R function uniroot() to find the root (in c) of the equation fn(c,0.05,5)=0. In your code you will need a command along the lines of
uniroot(fn,lower=0,upper=…,alpha=0.05,n=5)
Consult the week 7 exercise 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
which returns a list containing elements $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.
3. The GLRT test of (1) above uses the statistic
̄ ̄ n􏰀Y􏰁nY Ln=l(X,Y/n;X)−l(X,1;X)=−2log n −2+2
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 exact GLRT, recreate your earlier plot and add a power curve to it so it shows all 3 power curves on the 1 graph. Add an informative heading, legend, etc.. Comment on the main differences between the 3 tests.
4. As a final step, recreate your last plot but use an extended range for the parameter: sig.sq=(1:400)/100.
norm.var.umpu=function(alpha,n) { …
}
2