# Load the ToothGrowth data
data("ToothGrowth")
# Display the first few rows of the data
head(ToothGrowth)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
# Basic summary of the data
summary(ToothGrowth)
## len supp dose
## Min. : 4.20 OJ:30 Min. :0.500
## 1st Qu.:13.07 VC:30 1st Qu.:0.500
## Median :19.25 Median :1.000
## Mean :18.81 Mean :1.167
## 3rd Qu.:25.27 3rd Qu.:2.000
## Max. :33.90 Max. :2.000
# Load necessary library
library(ggplot2)
# Create a boxplot to compare tooth growth by supp and dose
ggplot(ToothGrowth, aes(x = interaction(supp, dose), y = len, fill = supp)) +
geom_boxplot() +
labs(title = "Tooth Growth by supp and dose",
x = "Supplement and Dose",
y = "Tooth Length") +
theme_minimal()
# Load necessary library
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Perform hypothesis testing
test_result <- ToothGrowth %>%
group_by(supp, dose) %>%
summarise(mean_length = mean(len), sd_length = sd(len), n = n()) %>%
mutate(se = sd_length / sqrt(n),
t_stat = (mean_length - mean(ToothGrowth$len)) / se,
p_value = 2 * pt(-abs(t_stat), df = n - 1))
## `summarise()` has grouped output by 'supp'. You can override using the
## `.groups` argument.
# Display the test results
test_result
## # A tibble: 6 × 8
## # Groups: supp [2]
## supp dose mean_length sd_length n se t_stat p_value
## <fct> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1 OJ 0.5 13.2 4.46 10 1.41 -3.96 0.00331
## 2 OJ 1 22.7 3.91 10 1.24 3.14 0.0119
## 3 OJ 2 26.1 2.66 10 0.840 8.63 0.0000120
## 4 VC 0.5 7.98 2.75 10 0.869 -12.5 0.000000554
## 5 VC 1 16.8 2.52 10 0.795 -2.57 0.0302
## 6 VC 2 26.1 4.80 10 1.52 4.83 0.000935
Based on the analysis, it appears that there are differences in tooth growth depending on the supplement (supp) and dose. The boxplot suggests variations in tooth length, and the hypothesis tests provide evidence for the significance of these differences.
The conclusions rely on the assumptions that the data is normally distributed and that the variances are homogenous across groups. The t-tests assume that the samples are independent and that the populations follow a normal distribution.