-
Notifications
You must be signed in to change notification settings - Fork 0
/
MATH0216_A6.R
47 lines (28 loc) · 1.58 KB
/
MATH0216_A6.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
## ----include=FALSE---------------------------------------------------------------------------------------------------
library(tidyverse)
## --------------------------------------------------------------------------------------------------------------------
taboo <-read.csv("https://raw.githubusercontent.com/ebmwhite/MATH0216/master/assignments/taboo.csv")
## --------------------------------------------------------------------------------------------------------------------
model <- lm(Happiness ~ Salary, data = taboo)
taboo %>%
ggplot(aes(x = Salary, y = Happiness)) +
geom_point() +
geom_abline(slope = coef(model)[2],
intercept = coef(model)[1],
color = "red")
summary(model)
## --------------------------------------------------------------------------------------------------------------------
model2 <- lm(Happiness ~ Salary + factor(Gender), data = taboo)
summary(model2)
summary(model)$r.squared
summary(model2)$r.squared
## --------------------------------------------------------------------------------------------------------------------
taboo %>%
ggplot(aes(x = Sex, y = Happiness, color = Gender)) +
geom_point()
## --------------------------------------------------------------------------------------------------------------------
model3 <- lm(data = taboo, Happiness ~ Sex + factor(Gender))
summary(model3)
## --------------------------------------------------------------------------------------------------------------------
full_model <- lm(data = taboo, Cigarette ~ Happiness + Sex + Gender + Alcohol + Salary)
step(full_model)