Actions

Work Header

Killings, Happiness, and Reasons He Stares at my Hips

Chapter 12: R code for regression

Chapter Text

Code needed for producing similar style regression results in R.

# ------------------------------------------------------------
# 1. Install packages
# ------------------------------------------------------------

install.packages(c("haven", "car", "janitor"))

# ------------------------------------------------------------
# 2. Load packages
# ------------------------------------------------------------

library(haven) # for importing SPSS .sav files
library(car) # for VIF
library(janitor) # for cleaning variable names


# ------------------------------------------------------------
# 3. Import SPSS data
# ------------------------------------------------------------

# data <- read_sav("C:/Users/YourName/your_file.sav")


# ------------------------------------------------------------
# 4. Check variable names
# ------------------------------------------------------------

# Optional: clean variable names to make them easier to use in R
data <- clean_names(data)

names(data)


# ------------------------------------------------------------
# 5. Run multiple linear regression
# ------------------------------------------------------------

model <- lm(
staring_times ~ prekill + party + wordmanipulation + tear +
confession + alcohol + happiness,
data = data
)

# View regression results
summary(model)


# ------------------------------------------------------------
# 6. Check multicollinearity using VIF
# ------------------------------------------------------------

vif(model)


# ------------------------------------------------------------
# 7. Optional: get confidence intervals
# ------------------------------------------------------------

confint(model)

Notes:

I don't know, I just love statistical analysis and think data is super fun to work with. Hopefully this piece actually helps! You can leave any comment regarding to data or academic writing etc. Thank you for your patience!

Series this work belongs to: