식물의 성장 데이터를 포함하고 있는 R 내장 데이터 PlantGrowth를 불러옵니다.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(rstatix)
## 
## 다음의 패키지를 부착합니다: 'rstatix'
## 
## The following object is masked from 'package:stats':
## 
##     filter
library(stringr)

data("PlantGrowth")

PlantGrowth <- PlantGrowth %>%
  mutate(group = factor(group))
summary_stats <- PlantGrowth %>%
  group_by(group) %>%
  summarise(mean_weight = mean(weight),
            sd_weight = sd(weight),
            n = n())
print(summary_stats)
## # A tibble: 3 × 4
##   group mean_weight sd_weight     n
##   <fct>       <dbl>     <dbl> <int>
## 1 ctrl         5.03     0.583    10
## 2 trt1         4.66     0.794    10
## 3 trt2         5.53     0.443    10

비교 1: 그룹 ctrl과 trt1 간의 식물 성장률 (weight)의 평균차이가 존재하는지를 유의수준 5%로 검정하시오.

ctrl_trt1 <- PlantGrowth %>%
  filter(group %in% c("ctrl", "trt1"))

comparison_ctrl_trt1 <- t.test(weight ~ group, data = ctrl_trt1)
print(comparison_ctrl_trt1)
## 
##  Welch Two Sample t-test
## 
## data:  weight by group
## t = 1.1913, df = 16.524, p-value = 0.2504
## alternative hypothesis: true difference in means between group ctrl and group trt1 is not equal to 0
## 95 percent confidence interval:
##  -0.2875162  1.0295162
## sample estimates:
## mean in group ctrl mean in group trt1 
##              5.032              4.661

비교 2: 그룹 ctrl과 trt2 간의 식물 성장률 (weight)의 평균차이가 존재하는지를 유의수준 5%로 검정하시오

ctrl_trt2 <- PlantGrowth %>%
  filter(group %in% c("ctrl", "trt2"))

comparison_ctrl_trt2 <- t.test(weight ~ group, data = ctrl_trt2)
print(comparison_ctrl_trt2)
## 
##  Welch Two Sample t-test
## 
## data:  weight by group
## t = -2.134, df = 16.786, p-value = 0.0479
## alternative hypothesis: true difference in means between group ctrl and group trt2 is not equal to 0
## 95 percent confidence interval:
##  -0.98287213 -0.00512787
## sample estimates:
## mean in group ctrl mean in group trt2 
##              5.032              5.526

결과: 비교 1의 p-value > 0.05이므로 평균 차이가 존재하지 않고, 비교 2의 p-value < 0.05이므로 평균 차이가 존재한다.