-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapterfive.R
74 lines (51 loc) · 1.63 KB
/
chapterfive.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library(moderndive)
library(gapminder)
library(tidyverse)
library(skimr)
options(warn=-1)
evals_ch5 <- evals %>%
select(ID,score, bty_avg,age)
glimpse(evals_ch5)
#Choose a random sample and view
evals_ch5 %>%
sample_n(size=5)
evals_ch5 %>%
select(score, bty_avg)%>%
skim()
evals_ch5 %>%
get_correlation(formula = score ~bty_avg)
evals_ch5 %>%
summarise(correlation=cor(score, bty_avg))
ggplot(evals_ch5, aes(x=bty_avg,y=score))+
geom_point()+
labs(x="Beauty Score",
y="Rating score",
tittle="Teaching score vs Beauty Score ")+
geom_smooth(method = "lm", se=FALSE)
score_model <- lm(score~bty_avg, data=evals_ch5)
get_regression_table(score_model)
#life expectancy
gapminder2007 <- gapminder %>%
filter(year==2007)%>%
select(country, lifeExp,continent,gdpPercap)
glimpse(gapminder2007)
gapminder2007 %>% sample_n(size = 5)
gapminder2007 %>% select(lifeExp, continent)%>% skim()
ggplot(gapminder2007, aes(x=lifeExp))+
geom_histogram(binwidth = 5, color="white")+
labs(x="Life expectancy",
y="number of countries")+
facet_wrap(~continent, nrow = 2)
ggplot(gapminder2007, aes(x=continent, y=lifeExp))+
geom_boxplot()+
labs(x="Life expectancy",
y="number of countries")
life_Exp_by_Continent<-gapminder2007 %>%
group_by(continent) %>%
summarise(median=median(lifeExp),
mean=mean(lifeExp))
life_Exp_by_Continent
life_Exp_model <-lm(lifeExp~continent, data=gapminder2007)
get_regression_table(life_Exp_model)
regression_points <- get_regression_points(life_Exp_model, ID="country")
regression_points