title: “方差分析 analysis of variance”
author:
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library (patchwork)
library(gapminder) #life expect in difference area
library(forcats)
#data()
head(gapminder)
# Create a data set to work with
gapdata <- gapminder %>%
filter(year ==2007&
continent %in% c("Americas","Europe","Asia")) %>%
select(continent,lifeExp)
#Take a look at the distribution of means
gapdata %>%
group_by(continent) %>%
summarise(Mean_life=mean(lifeExp)) %>%
arrange(Mean_life)
#Research question:
# Is the life expectancy in these three continents
# Research question: Is the life expectancy in these three continents different
# Hypothesis testing: HO:Mean life expectancy is the same
# HI:Mean life expectancy is not the same
# observation:
# Difference in mean is observed in the sample data,but is this statistically
# significant (alpha 0.05)
# Create ANOVA mode 1
gapdata %>%
aov(lifeExp ~ continent,data =.) %>%
summary()
aov_model <- gapdata %>%
aov(lifeExp ~ continent,data =.)
# Is this significance being driven by a particular continent?
gapdata %>%
aov(lifeExp ~ continent,data = .) %>%
TukeyHSD() %>%
plot()
TukeyHSD(aov_model)
#The difference between Asia and the Americas
#has an adjusted p value of 0.14 (not significant)
#and a 95%cI that overlaps 0
多组间两两比较图形 TukeyHSD方法:
