Stats scores. (2.33, p. 78) Below are the final exam scores of twenty introductory statistics students.
57, 66, 69, 71, 72, 73, 74, 77, 78, 78, 79, 79, 81, 81, 82, 83, 83, 88, 89, 94
Create a box plot of the distribution of these scores. The five number summary provided below may be useful.
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.6 v dplyr 1.0.3
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
summary(scores)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 57.00 72.75 78.50 77.70 82.25 94.00
boxplot(scores)
Mix-and-match. (2.10, p. 57) Describe the distribution in the histograms below and match them to the box plots.
Distributions and appropriate statistics, Part II. (2.16, p. 59) For each of the following, state whether you expect the distribution to be symmetric, right skewed, or left skewed. Also specify whether the mean or median would best represent a typical observation in the data, and whether the variability of observations would be best represented using the standard deviation or IQR. Explain your reasoning.
Ans: Right skew, median, and IQR. The Median and IQR are better observations of the data when there are extreme values.
Ans: Either mean/SD or median/IQR can be used because the data set is symetrical.
Ans: Right skewed and median/IQR can be used. There might be outliers but given the right skew dataset and the outliers, I believe the median/IQR is the better fit.
Ans: Right skewed, median and IQR can be used. Few very high salaries would right skew the data.
Heart transplants. (2.26, p. 76) The Stanford University Heart Transplant Study was conducted to determine whether an experimental heart transplant program increased lifespan. Each patient entering the program was designated an official heart transplant candidate, meaning that he was gravely ill and would most likely benefit from a new heart. Some patients got a transplant and some did not. The variable transplant indicates which group the patients were in; patients in the treatment group got a transplant and those in the control group did not. Of the 34 patients in the control group, 30 died. Of the 69 people in the treatment group, 45 died. Another variable called survived was used to indicate whether or not the patient was alive at the end of the study.
library(openintro)
data("heart_transplant")
heartTr <- data("heart_transplant")
heartTr <- heart_transplant
# mosaic plot -------------------------------------------------------
par(mar = c(0, 0, 0, 0), las = 1, mgp = c(2.7, 0.9, 0))
mosaicplot(transplant ~ survived, data = heartTr,
main = "", xlab = "", ylab = "", color = COL[1],
cex.axis = 1.5)
# box plot ----------------------------------------------------------
par(mar = c(2, 4.8, 0, 0), las = 1, mgp = c(3.5, 0.7, 0),
cex.lab = 1.5, cex.axis = 1.5)
boxPlot(heartTr$survtime, fact = heartTr$transplant,
ylab = "Survival Time (days)", col = COL[1,2])
dim(heartTr)
## [1] 103 8
summary(heartTr)
## id acceptyear age survived survtime
## Min. : 1.0 Min. :67.00 Min. : 8.00 alive:28 Min. : 1.0
## 1st Qu.: 26.5 1st Qu.:69.00 1st Qu.:41.00 dead :75 1st Qu.: 33.5
## Median : 49.0 Median :71.00 Median :47.00 Median : 90.0
## Mean : 51.4 Mean :70.62 Mean :44.64 Mean : 310.2
## 3rd Qu.: 77.5 3rd Qu.:72.00 3rd Qu.:52.00 3rd Qu.: 412.0
## Max. :103.0 Max. :74.00 Max. :64.00 Max. :1799.0
##
## prior transplant wait
## no :91 control :34 Min. : 1.00
## yes:12 treatment:69 1st Qu.: 10.00
## Median : 26.00
## Mean : 38.42
## 3rd Qu.: 46.00
## Max. :310.00
## NA's :34
unique(heartTr$transplant)
## [1] control treatment
## Levels: control treatment
Ans It appears that transplanted patients were more likely to be alive (survive).
Ans: The box plots indicated that the treatment group survived longer than the control group.
count(heartTr,transplant,survived)
## # A tibble: 4 x 3
## transplant survived n
## <fct> <fct> <int>
## 1 control alive 4
## 2 control dead 30
## 3 treatment alive 24
## 4 treatment dead 45
control.dead.ratio <-30/34
control.dead.ratio
## [1] 0.8823529
treatment.survive.ratio <- 24/69
treatment.survive.ratio
## [1] 0.3478261
treatment.dead.ratio <- 45/69
treatment.dead.ratio
## [1] 0.6521739
round(control.dead.ratio - treatment.dead.ratio, 4)
## [1] 0.2302
Ans: (The Null Hypothesis H0) The survival of patients does not depend on transplant. Transplat and survival are independent and have no relatioships.
(Hypothesis Alternative HA) The transplanted patients are more likely to survive and survival ratio shows that transplated patients have better survival time and rate.
The paragraph below describes the set up for such approach, if we were to do it without using statistical software. Fill in the blanks with a number or phrase, whichever is appropriate
We write alive on 28______ cards representing patients who were alive at the end of the study, and dead on 75 cards representing patients who were not. Then, we shuffle these cards and split them into two groups: one group of size 69__ representing treatment, and another group of size 34__ representing control. We calculate the difference between the proportion of dead cards in the treatment and control groups (treatment - control) and record this value. We repeat this 100 times to build a distribution centered at 0. Lastly, we calculate the fraction of simulations where the simulated differences in proportions are 0.2302__. If this fraction is low, we conclude that it is unlikely to have observed such an outcome by chance and that the null hypothesis should be rejected in favor of the alternative.
# plot randomization distribution -----------------------------------
par(mar = c(3.6, 2.2, 1, 1), las = 1, mgp = c(2.5, 0.7, 0),
cex.axis = 1.5, cex.lab = 1.5)
values <- table(diffs)
plot(diffs, type = "n", xlim = c(-0.25, 0.25),
xlab = "simulated differences in proportions",
ylab = "", axes = FALSE, ylim = c(0, max(values)))
axis(1, at = seq(-0.25, 0.25, 0.05),
labels = c(-0.25, NA,-0.15, NA,-0.05, NA, 0.05, NA, 0.15, NA, 0.25))
for(i in 1:length(diffs)){
x <- diffs[i]
rec <- sum(diffs == x)
points(rep(x, rec), 1:rec, pch = 20, cex = 0.8, col = COL[1])
}
Ans: The simulation is effective for 100 simulations as the data appears to be centered near to 0. We can safely reject the NULL hypothesis as transplanted patients are more likely to survive.