library(tidyverse)
library(rio)
library(Hmisc)
library(jtools)
library(table1)
library(plotly)
setwd("C:/Users/yoonh/OneDrive - The University of Chicago/Courses/Winter 2025/SOCI 30617 - Intro to Applied Stats and Data Science/Assignments/Assignment 2/Data")
gss <- import("GSS2018cleaned.rdata")
gss$Female <- ifelse(gss$Sex=="Female", 1, 0)
gss$Black <- ifelse(gss$Race=="Black", 1, 0)
model5viz2 <- lm(OccPres ~ DadSES + Black + Female + Age + FamIncome10k, data=gss)
model5viz2
##
## Call:
## lm(formula = OccPres ~ DadSES + Black + Female + Age + FamIncome10k,
## data = gss)
##
## Coefficients:
## (Intercept) DadSES Black Female Age
## 31.63198 0.12324 -0.91260 0.23434 0.08694
## FamIncome10k
## 1.15957
new_data_3d <- expand.grid(
DadSES = seq(min(gss$DadSES, na.rm = TRUE), max(gss$DadSES, na.rm = TRUE), length.out = 100),
Age = seq(min(gss$Age, na.rm = TRUE), max(gss$Age, na.rm = TRUE), length.out = 100),
Black = mean(gss$Black, na.rm = TRUE),
Female = mean(gss$Female, na.rm = TRUE),
FamIncome10k = mean(gss$FamIncome10k, na.rm = TRUE)
)
new_data_3d$Predicted_OccPres <- predict(model5viz2, newdata = new_data_3d)
plot_ly(new_data_3d, x = ~DadSES, y = ~Age, z = ~Predicted_OccPres, type = "scatter3d", mode = "markers")