Last active
December 1, 2021 21:39
-
-
Save ryanburge/f2cb0c026e2d87e59cfb1317d1588e17 to your computer and use it in GitHub Desktop.
Regression Walkthrough 12/1/2021
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
install.packages("jtools") | |
install.packages("interactions") | |
install.packages("ggstance") | |
install.packages("broom.mixed") | |
library(jtools) | |
library(interactions) | |
library(ggstance) | |
library(broom.mixed) | |
library(socsci) | |
## Scatterplots and Simple Relationships | |
bball <- read_csv("https://raw.githubusercontent.com/ryanburge/pls2003_sp17/master/bball.csv") | |
bball <- bball %>% | |
rename(games = g, wins =w, losses = l, runs =r, atbats = ab, hits =h, homeruns =hr, walks = bb, strikeout = so, stolenbase = sb, earnedruns = era) | |
## Regression ### | |
df <- read_csv("https://raw.githubusercontent.com/ryanburge/pls2003_sp17/master/living.csv") | |
reg <- lm(weight ~ height, data = df) | |
summ(reg) | |
reg <- lm(weight ~ height + white, data = df) | |
summ(reg) | |
60*4.56 | |
273.6 (-9.6 * 0) | |
264 - 133.50 = 130.5 | |
plot_coefs(reg) | |
reg <- lm(weight ~ height + white + black, data = df) | |
summ(reg) | |
plot_coefs(reg) | |
reg <- lm(weight ~ height + white + black + male + physical + educ, data = df) | |
summ(reg) | |
plot_coefs(reg) | |
int <- lm(weight ~ height*white*stamps, data = df) | |
interact_plot(int, pred = height, modx = white, mod2 = stamps, interval = TRUE) | |
df <- df %>% | |
mutate(white_new = frcode(white == 1 ~ "White", | |
white == 0 ~ "Non-White")) %>% | |
mutate(stamps_new = frcode(stamps == 1 ~ "On Food Stamps", | |
stamps == 0 ~ "Not on Food Stamps")) %>% | |
mutate(coll = frcode(educ >= 16 ~ "College Grad", | |
educ <= 15 ~ "No College")) | |
int <- lm(weight ~ height*white_new*coll, data = df) | |
interact_plot(int, pred = height, modx = white_new, mod2 = coll, interval = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment