Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created November 30, 2022 16:32
Show Gist options
  • Save ryanburge/f0dd4c92f506872fdd1f50201a2700b1 to your computer and use it in GitHub Desktop.
Save ryanburge/f0dd4c92f506872fdd1f50201a2700b1 to your computer and use it in GitHub Desktop.
Regression Class - Graduate Methods - 11/30/2022
# install.packages("jtools")
# install.packages("interactions")
# install.packages("ggstance")
# install.packages("broom.mixed")
library(jtools)
library(interactions)
library(ggstance)
library(broom.mixed)
library(socsci)
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