MH3511 Data Analysis With Computer: Lab 5 (Solution) AY2019/20 Semester 2
MH3511 Data Analysis With Computer: Lab 5 (Solution) AY2019/20 Semester 2
Exercise 5.1
A person has been trained to set the bean grinder so that a 25-second expresso shot results in 2
ounces of espresso. He pours thirteen shots and measures the amounts to be
1.95, 1.78, 2.10, 1.82, 1.73, 2.01, 1.83, 1.90, 2.05, 1.85, 1.96, 1.98, 1.79
a) Examine whether the data are roughly normally distributed using QQ-plot and Shapiro-
Wilk’s test.
b) Use an R code similar to the following to compare three results of the two-sided 90%
confidence interval using the normal approximation, t-distribution approximation, and using
the t.test() function.
t.test(coffee, conf.level=0.9)
c) Find the one-sided 90 % CI of the form ¿, using normal approximation, t-distribution
approximation, and using the t.test() function. Compare the three results.
>
>
> coffee<- c(1.95, 1.78, 2.10, 1.82, 1.73, 2.01, 1.83, 1.90, 2.05,
1.85, 1.96, 1.98, 1.79)
>
> qqnorm(coffee)
> qqline(coffee)
> shapiro.test(coffee)
data: coffee
W = 0.96491, p-value = 0.8271
data: coffee
t = 60.184, df = 12, p-value = 2.928e-16
alternative hypothesis: true mean is not equal to 0
90 percent confidence interval:
1.847466 1.960226
sample estimates:
mean of x
1.903846
Exercise 5.2
The existing dataframe “airquality” in R contains daily air quality measurements in New York, May to
September 1973, with 154 observations on 6 variables, where variable “Wind” is the average wind
speed in m/s (meters per second).
I. Subset the dataframe and use a QQplot to check if the wind speed data in August and
September are approximately normally distributed.
II. One wants to test hypothesis that the mean wind speed is 10 m/s during August and
September.
a. What are the null and alternative hypotheses?
b. Find the p-value of this test using three methods: normal approximation, t
approximation and t.test() function.
c. Are p-values obtained from the three methods the same or very similar? Why?
Exercise 5.4
Let { X 1 , X 2 , X 3 , … , X n } be a random sample from a normal population of size n . We are interested
in testing H 0 : X N (0 , 1) against H 1 : X N (μ 1 , 1), where μ1 >0.
Suppose we apply the decision rule so that we reject H 0 if x́ ≥ 0.5 , otherwise do not reject H 0.
a) For various values of n (10, 11, 20 and 30) use a R code to determine the probability of Type
I error. at what value of n would the probability of type I error be approximately 0.05?
b) For n=11, determine the powers of this test when μ1=1.0 , 1.1 ,1.2∧1.3.
X́−μ
Note that when X N (μ , 1) , N ( 0,1 ) ,
1/ √ n
Under H 0 : X N (0 , 1), the p-value is