-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_penguins.R
121 lines (94 loc) · 2.92 KB
/
p_penguins.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
getwd()
setwd("~/GitHub/PALMER_PENGUINS")
getwd()
ls()
install.packages("learningr")
install.packages("gapminder")
install.packages("rmarkdown")
install.packages("tinytex")
install.packages("ISLR2")
install.package("palmerpenguins")
library(readxl)
library(tidyverse)
library(janitor)
library(palmerpenguins)
library(learningr)
library(gapminder)
library(ggplot2)
library(rmarkdown)
library(tinytex)
library(dplyr)
library(ISLR2)
data()
data(penguins)
View(penguins)
View(penguins_raw)
glimpse(penguins)
penguins_sm <- filter(penguins, species != "Adelie")
glimpse(penguins_sm)
View(penguins_sm)
model <- lm(body_mass_g ~ flipper_length_mm * species, data = penguins_sm)
summary(model)
penguins %>%
group_by(species) %>%
summarise(var(flipper_length_mm, na.rm = TRUE))
pp_model <- aov(flipper_length_mm ~ species, data = penguins)
summary(pp_model)
TukeyHSD(pp_model)
adelie <- filter(penguins, species == "Adelie",
!is.na(bill_length_mm))
View (adelie)
ggplot(adelie, aes(x = bill_depth_mm,
y = bill_length_mm)) + geom_point()
ggsave("p_penguins_scatter.png")
pp_bill_model <- lm(bill_length_mm ~ bill_depth_mm,
data = adelie)
plot(pp_bill_model)
ggplot(adelie, aes(x = bill_depth_mm,
y = bill_length_mm)) + geom_point()+
geom_smooth(method = "lm",
level = .99)
ggsave("p_penguins_bill_model.png")
predict(pp_bill_model)
predict(pp_bill_model, interval = "prediction")
adelie_new <- cbind(adelie,
predict(pp_bill_model, interval = "prediction"))
View(adelie_new)
ggplot(adelie_new, aes(x = bill_depth_mm)) +
geom_point(aes(y = bill_length_mm))+
geom_line(aes(y = fit),
col = "purple") +
geom_line(aes(y = upr),
col = "brown",
linetype = "dashed")+
geom_line(aes(y = lwr),
col = "navy",
linetype = "dashed")
ggsave("p_penguins_CI.png")
ggplot(penguins, aes(x = species, y = flipper_length_mm)) +
geom_boxplot()
ggsave("p_penguins_boxplot.png")
ggplot(penguins, aes(x = flipper_length_mm)) +
geom_histogram() +
facet_wrap(~species, ncol = 1)
ggsave("p_penguins_species_dist.png")
ggplot(penguins, aes(x = species, y = bill_length_mm, fill = species))+
geom_violin()+
geom_boxplot(width =.5)
ggsave("p_penguins_violinplot.pdf")
ggsave("p_penguins_violinplot.png")
ggplot(penguins_sm, aes(x = flipper_length_mm, y = body_mass_g, color = species))+
geom_point()+
geom_smooth(method = "lm", se = FALSE)
ggsave("p_penguins_LM.pdf")
ggsave("p_penguins_LM.png")
ggplot(penguins_sm, aes(x = flipper_length_mm, y = body_mass_g, color = species))+
geom_point()+
geom_abline(aes(intercept = -3037.196,
slope = 34.573,
col = "Chinstrap"))+
geom_abline(aes(intercept = -3037.196-3750.085,
slope = 34.573 + 20.049,
col = "Gentoo"))
ggsave("p_penguins_regression.pdf")
ggsave("p_penguins_regression.png")