Created
April 10, 2020 19:20
-
-
Save aaroncharlton/1e689e087ed1d516d5dced6936f06e5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first, look at the data | |
iris | |
head(iris) | |
summary(iris) | |
?iris | |
# next, visualize the data | |
library(ggplot2) # if not installed, run this code: install.packages("ggplot2") | |
ggplot(iris, aes(y = Sepal.Length, x = Petal.Length)) + | |
geom_point() + | |
geom_smooth(method = "lm") | |
# next, run a regression | |
model1 <- lm(Sepal.Length ~ Petal.Length, data = iris) | |
summary(model1) | |
#*********** Let's try logistic regression *************** | |
ggplot(iris, aes(y = Species, x = Petal.Length)) + | |
geom_point(alpha = .1) + | |
geom_smooth(method = "lm") # oops that didn't work | |
library(tidyverse) # if you don't have it, install it (install.packages("tidyverse")) | |
iris2 <- iris %>% | |
mutate(versicolor = ifelse(.$Species == "versicolor",1,0)) %>% | |
filter(Species != "setosa") | |
ggplot(iris2, aes(y = versicolor, x = Petal.Length)) + | |
geom_point() + | |
stat_smooth(method = "glm", method.args=list(family="binomial"), se=FALSE) + | |
labs(y = "p(versicolor)", title = "Probability of versicolor species\ngiven petal length") | |
# run our logistic regression | |
model1 <- glm(versicolor ~ Petal.Length, data = iris2, family = "binomial") | |
summary(model1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment