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

Assignment 1 - MAT 5317

Gilles Lamothe

September 22, 2021

Instructions

1)  Please submit your solutions to this assignment in one PDF file in Brightspace.  Only one file will be accepted.

2) You can submit a PDF file more than once.  However, only the last submission will be saved.  If you want to modify your submitted assignment, that is fine as long as it is before the deadline.

3)  Late submissions of the assignment are not going to be marked.

4) In the second part of the assignment, you must use R for all of your computations.   Please use R markdown to write the solutions for this part.

5) You can submit hand written solutions for part one of the assignment, but please combine images of your hand-written solutions with the PDF produced with R markdown as one PDF. (See https: //imagetopdf.com/ as a possible solution to combine images as one PDF).

6)  Deadline: Before 11:59 pm on Friday, September 30

7) You can work in groups of up to four.   Please only one member of the group should submit the assignment in Brightspace.

Part one

You can provide hand-written solutions for this part, but it is not necessary. You are welcome to try to write your solutions with latex using R markdown. You can only use R to compute quantiles and probabilities for the binomial, normal, and beta distributions. It is not necessary to provide the R output for Part one.

1. We computed a 95% CI for π with the R function prop .test.  According to these computations, we are 95% confident that 0.421 < π < 0.579. What is the name of this interval?

prop.test(75,150,correct=FALSE)$conf.int

##  [1]  0 .4209901  0 .5790099

##  attr(,"conf .level")

##  [1]  0 .95

Wilson confidence interval

(b)  We computed a 95% CI for interval with the R function binom .test. According to these computations,

we are 95% confident that 0.417 < π < 0.583. What is the name of this interval?

binom.test(75,150)$conf.int

##  [1]  0 .4173574  0 .5826426

##  attr(,"conf .level")

##  [1]  0 .95

Clopper-Pearson confidence interval

2.  Consider a clinical trial where we would like perform inference concerning π, the probability that the

treatment is successful. We observed y = 8 successes among n = 12 trials.

Here is the display of the pmf for the B (n = 12, π = 0.5) distribution.

round(dbinom(0:12 ,12 ,0.5),3)

##    [1]  0 .000  0 .003  0 .016  0 .054  0 .121  0 .193  0 .226  0 .193  0 .121  0 .054  0 .016  0 .003 ##  [13]  0 .000

(a)  Using the values of for the above pmf, compute the p-value to test H0  : π = 0.5 against Ha  : π  0.5

with the Binomial test using the min likelihood method.

P (W ≤ 3|π = 0.5) + P(W ≥ 9|π = 0.5) = 0.1459961

Use the min likelihood method to count P-Value. P-value=0.1459961

sum (dbinom(c (0:3 ,9:12),size=12 ,prob=0.5))

##  [1]  0 .1459961

(b)  Using the values of for the above pmf, compute the p-value to test H0  : π = 0.5 against Ha  : π  0.5

with the Binomial test using the central method.

2P(Y ≤ 4|π = 0.5) = 0.07299805

Use the central method to count P-Value. P-value=0.1459961

pbinom(3 ,size=12 ,prob=0.5)

##  [1]  0 .07299805

sum (dbinom(3:12 ,size=12 ,prob=0.5))

##  [1]  0 .9807129

(c)  Give the Clopper-Pearson 95% confidence interval for π by using quantiles of an appropriate beta distribution.  (Hint: use qbeta.) 

lower limte = 

upper limte =

lower limit=qbeta(0.025;3,10)=0.05486064

upper limit=qbeta(0.025;4,9)=0.09924609

qbeta(0.025 ,3 ,10)

##  [1]  0 .05486064

qbeta(0.025 ,4 ,9)

##  [1]  0 .09924609

(d)  Use the Score Test to test H0  : π = 0.5 against Ha  : π  0.5.  Give the observed value of the test statistic, the p-value and the conclusion.

0  =

 − 0.5

 (0.5)(0.5)/n

= 1.1547

The obersved value = 1.1547 where  = w/n = 8/12 = 0.66666.  The p-value is 2 P(Z > |1.1547|) = 0.2482133, where Z ∼ N(0, 1). At α = 5%, we have significant evidence against H0 . We can conclude

that π  0.5.

2*(1-pnorm (1.1547))

##  [1]  0 .2482133

3.  Of 10000 randomly selected cases of lung cancer, 8756 resulted in death.

(a)  Give a point estimate for the population proportion π that such cases would result in death.  Also provide the estimated standard error of the estimate.

An estimate of π is  = y/n = 8756/10000 = 0.8756. The standard error is

se(  ) = 4  = 0.003300373.

p<-8756/10000

p

##  [1]  0 .8756

se<-sqrt(p* (1-p)/10000)

se

##  [1]  0 .003300373

(b)  Before computing the 95% Wald, Wilson, and Agresti-Coull confidence intervals for π, do you think

that they will be similar for this study? Why?

(c)  Give the 95% Wald, Wilson, and Agresti-Coull confidence intervals for π .

library(binom)

binom .confint(x=8756 ,n=10000 ,conf .level=0.95 ,methods="all")

##

method

x

n

mean

lower

upper

##  1

agresti-coull

8756

10000

0 .8756000

0 .8689852

0 .8819264

##  2

asymptotic

8756

10000

0 .8756000

0 .8691314

0 .8820686

##  3

bayes

8756

10000

0 .8755624

0 .8690737

0 .8820090

##  4

cloglog

8756

10000

0 .8756000

0 .8689733

0 .8819147

##  5

exact

8756

10000

0 .8756000

0 .8689718

0 .8820086

##  6

logit

8756

10000

0 .8756000

0 .8689858

0 .8819257

##  7

probit

8756

10000

0 .8756000

0 .8690134

0 .8819514

##  8

profile

8756

10000

0 .8756000

0 .8690355

0 .8819721

##  9

lrt

8756

10000

0 .8756000

0 .8690245

0 .8819721

##  10

prop .test

8756

10000

0 .8756000

0 .8689357

0 .8819736

##  11

wilson

8756

10000

0 .8756000

0 .8689868

0 .8819247

 ±  4  +  ,

where  = y/n, and

 = y + zα(2)/2/2

Hint: The quadratic formula might be helpful and also note that |a| < b is equivalent to −b < a < b.

Part Two

Please R for all computations, and for building graphs in this part of the assignment.  Note that we also want answers to some of this questions, that do not involve R. R will only be used for the computation, and to produce graphs.  For some of these questions, the R output will not be sufficient.  You will need to interpret, to describe, and give conclusions.

5. In addition to the coverage probability of a confidence interval, the expected length of an interval is important too. The expected length of the confidence interval is

n

E [L(W)] = E [U (W) L(W)] = (u(w) l(w)) P (W = w),

w=0

where l(w) is the lower limit of the interval and u(w) is the upper limit of the interval, where W has a B (n, π) distribution.

(a) We would like a confidence interval to be as short as possible with respect to its expected length. Why?

(b)  For n = 40, π = 0.16, and 1 − α = 0.95, find the expected length for the Wald confidence interval and

verify it is 0.2215.

(c)  For n = 40 and 1 α = 0.95, construct a plot for the expected length as a function of π .

(d)  Using the plots for coverage probability that we have seen during the lectures concerning coverage probability and the plots in (c), which interval is best? Explain.

Comments for part (c):

Iterate over values of π from π = 0.001 to π = 0.999 by increments of 0.001.

 We want the expected length of the confidence interval, which is

n

E [L(W)] = E [U (W) L(W)] = (u(w) l(w)) P (W = w),

w=0

where l(w) is the lower limit of the interval and u(w) is the upper limit of the interval.

 We will compare the following methods: Wald, Agresti-Coull, Wilson, and Clopper-Pearson.

•  Put the expected length of the five methods on the same plot instead of building four different plots. Here is an example of commands that you can use

par(mfrow  =  c(1,1))    #  1  by  1  graphics  window

plot(x  = mean .length[,1],  y  = mean .length[,2],

main  =  "Comparing  Length  of  CIs",  xlab  =  expression(pi),

ylab  =  "Length  of  CI",  type  =  "l",

ylim  =  c(0,0 .35),lty=1,col="grey0",lwd=1)

lines(x  = mean .length[,1],  y  = mean .length[,3],

lty=2,col="grey10",,lwd=2)

lines(x  = mean .length[,1],  y  = mean .length[,4],

lty=3,col="grey25",lwd=3)

lines(x  = mean .length[,1],  y  = mean .length[,5],

lty=4,col="grey50",lwd=4)

##  add  a  legend

legend(x  =  0 .2,  y  =  0 . 15,

legend  =  c("Wald",  "Agresti-Coull","Wilson","Clopper-Pearson"),

lty  =  c(1,2,3,4),  bty  =  "n",lwd=c(1,2,3,4),

col  =  c("grey0","grey10","grey25","grey50"))

Comments:

 I am assuming that we are collecting data in a matrix called mean .length.  In the first column, we have the values of π . In the corresponding columns we have the expected length of the interval based on Wald, Agresti-Coull, and so on. So it is a matrix with 5 columns.

 We start by building one plot with the function plot, of type "l". This means that line segments are drawn between the points. Then, we can add other curves to the plot with the function lines. The function lines adds these points to the previous plot by joining line segments to the new points. We repeat this process for all of the methods.

  To identify the different curves on the plot, we use different line widths with lwd, and different colours with col. We also used different line types with lty.

 We placed the legend at the point (0.2,0.15). You might have to play with the location to make it visible.