getwd()
## [1] "/Users/jangsieun"
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.3 ✔ 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
dat <- ToothGrowth
head(dat)
## 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
str(dat)
## 'data.frame': 60 obs. of 3 variables:
## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
## $ dose: num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
summary(dat)
## 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
dat %>%
ggplot(aes( supp ,len)) + geom_boxplot()
dat %>%
ggplot(aes( dose, len)) + geom_boxplot()
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?
boxplot(ToothGrowth$len)
hist(ToothGrowth$len)
mean(ToothGrowth$len)
## [1] 18.81333
sd(ToothGrowth$len)
## [1] 7.649315
length(ToothGrowth$len)
## [1] 60
ToothGrowth.len.mean <- mean(ToothGrowth$len)
ToothGrowth.len.sd <- sd(ToothGrowth$len)
ToothGrowth.mean <- 17
ToothGrowth.n <- 60
t_value <- (ToothGrowth.len.mean - ToothGrowth.mean) / (ToothGrowth.len.sd / sqrt(ToothGrowth.n))
p_value <- 1 - pt(t_value, df=ToothGrowth.n - 1, lower.tail = FALSE)
p_value
## [1] 0.9643194
mean(ToothGrowth$len)
## [1] 18.81333
sd(ToothGrowth$len)
## [1] 7.649315
length(ToothGrowth$len)
## [1] 60
표본 평; 표본 표준편차; 모집단 평균( 가정된 값); 표본 크기
ToothGrowth.len.mean <- mean(ToothGrowth$len)
ToothGrowth.len.sd <- sd(ToothGrowth$len)
ToothGrowth.mean <- 18
ToothGrowth.n <- 60
t_value <- (ToothGrowth.len.mean - ToothGrowth.mean) / (ToothGrowth.len.sd / sqrt(ToothGrowth.n))
p_value <- 2 * pt(t_value, df=ToothGrowth.n - 1, lower.tail = FALSE)
p_value
## [1] 0.4134781
```