In: Computer Science
sleep data analysis:
a) What is the dataset “sleep” in R? and its description?
b) Draw boxplots for two drug groups in ONE plot.
c) Set up a hypothesis (null and alternative) for testing whether there exists an effect difference between two drugs. Using both words and symbols for hypothesis settings. (Hint: this is a paired sample test, rather than a general two sample t test.)
d) Use an appropriate formula to calculate the test statistic and find its p-value for part c) and draw a conclusion at the significance level α=0.05.
e) Check the function “t.test”in R, i.e, read the description of this function and its usage, values, and even play the examples provided at the end of the help page. What is the function description?
f) Use the function “t.test” in R to answer c) with the significance level α=0.05. (Hint: you need to change the “paired” status from FALSE to TRUE) g) Compare the conclusions in d) and f) Attach all the R code you used for this problem.
1.
datasets
Usage
sleep
Details
The group
variable name may be misleading about the
data: They represent measurements on 10 persons, not in groups.
Format
A data frame with 20 observations on 3 variables.
1 | Extea | numeric | increase in hours of sleep |
2 | Group | factor | drug given |
# NOT RUN {
require(stats)
## Student's paired t-test
with(sleep,
t.test(extra[group == 1],
extra[group == 2], paired = TRUE))
## The sleep *prolongations*
sleep1 <- with(sleep, extra[group == 2] - extra[group ==
1])
summary(sleep1)
stripchart(sleep1, method = "stack", xlab = "hours",
main = "Sleep prolongation (n = 10)")
boxplot(sleep1, horizontal = TRUE, add = TRUE,
at = .6, pars = list(boxwex = 0.5, staplewex = 0.25))
# }
2.
Description
Data which show the effect of two soporific drugs (increase in hours of sleep compared to control) on 10 patients.
Usage
sleep
Format
A data frame with 20 observations on 3 variable
1 | extra | Numeric | increase in hours of sleep |
2 | group | Factor | Drugs given |
3 | Id | Factor | Patient ID |
Details
The group
variable name may be misleading about the
data: They represent measurements on 10 persons, not in groups
require(stats) ## Student's paired t-test with(sleep, t.test(extra[group == 1], extra[group == 2], paired = TRUE)) ## The sleep *prolongations* sleep1 <- with(sleep, extra[group == 2] - extra[group == 1]) summary(sleep1) stripchart(sleep1, method = "stack", xlab = "hours", main = "Sleep prolongation (n = 10)") boxplot(sleep1, horizontal = TRUE, add = TRUE, at = .6, pars = list(boxwex = 0.5, staplewex = 0.25))
3