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

MATH253 Week 4 Tutorial

R tutorial

This tutorial sheet is related to material covered in chapters 3, 4, 5 and 6 (how to do tests/calculations/plots from these chapters in R).

Solutions will be available on Canvas on Friday.

Question A

In an experiment to determine the mean density of the Earth, British scientist Henry Cavendish obtained 29 observed values (g/cm3 ). The data is available on Canvas – file Tutorial4 earth density .xlsx.

❼ Download the le Tutorial4 earth density .xlsx to your computer into a folder dedicated to R.

Make sure that this folder is set up as your working directory in RStudio.

❼ In RStudio open a new R script.

❼ Load the le Tutorial4 earth density .xlsx using readxl package, creating the variable called

density.  (See Tutorial 2 for details how to load data using readxl package.)

❼ Make sure you save your R script in the folder dedicated to R and it is a good idea to keep saving it

after each task you complete.

1.  Produce a histogram of the data, name the histogram and horizontal axis appropriately. ❼ Hint: Use the command hist.

2.  Find a 95% confidence interval for the population mean.  Test the hypothesis H0  : µ = 5.1 versus the alternative H1  : µ  5.1.

❼ We perform a t-test in R, using the command t .test:

t .test(density$Density,  y  =  NULL,  alternative  =  c("t"),  mu  =  5 . 1, paired  =  FALSE,  var .equal  =  FALSE,  conf .level  =  0 . 95)

❼ The command t .test is used for the two-sample t-tests as well. If used for one sample, we have to

use y  =  NULL,  paired  =  FALSE,  var .equal  =  FALSE in the command.

❼ Use the parameter alternative to specify the alternative hypothesis:  for a two-sided alterna-

tive,  we write  alternative  =  c("t"),  for the one-sided alternative  H1   :  µ  >  µ0 ,  we write alternative  =  c("g") and for H1  : µ < µ0 , we write alternative  =  c("l").

❼ Parameters mu and conf .level are to specify the hypothesised value µ0  and the confidence level.

Write up your conclusions.  What is the underlying assumption of the test you have used here?  Do you think the assumption is justified for these data? Explain your answer.

3.  Use R to test the hypothesis H0  : µ = 5.5 versus the alternative H1  : µ < 5.5.  Report your conclusions clearly.

4.  Suppose now the true standard deviation is known to be σ = 0.22, so that a t-test is no longer appropriate. A Z-test should now be used to test the hypothesis H0  : µ = 5.1 versus the alternative H1  : µ  5.1.       Use R to carry out the appropriate test. Compute a 95% confidence interval. Write up your conclusions.

❼ A Z-test is not a part of basic R, however it is a part of BSDA package. Install BSDA package.  (See

Tutorial 2 for details how to install a package.)

❼ Call the package and now you can use the command z .test (using parameters in a similar way as

for t .test):

z .test(density$Density,  y  =  NULL,  alternative  =  "t",  mu  =  5 . 1, sigma .x  =  0 .22,  sigma .y  =  NULL,  conf .level  =  0 . 95)

How does this CI differ from the CI of part Q2 above? Give two reasons why it differs in this way.

Save your work.

Question B

Body Mass Index (BMI) is a measure used to assess if a person is under- or over-weight. The normal range of BMI in adults is 18.5 to 25.  The data set we are working with is the BMI of 35 adult female gymnasts; the data set is available on Canvas – file Tutorial4 BMI .xlsx.

1.  Decide if it is reasonable to assume that data are normally distributed.

2.  Find the 99% two-sided confidence interval for the mean BMI of gymnasts. Interpret this interval.

3. It is claimed that gymnasts tend to be underweight (BMI<18.5).  State the appropriate hypotheses and perform the test. Report your conclusions clearly.

4.  Assuming that the variance of the gymnasts is known and equal to 2.56, test if the BMI of gymnasts differs from the population average of 22.3; obtain a 99% CI for the mean BMI. State the hypotheses for your test and report your conclusions clearly.