img-responsive

Please Wait

Advanced Quantitative Methods – Analysis of Correlates of School Performance

# 1. Explore the use of logarithms of the dependent variable.

calschool$log_dependent variable <- log(calschool$dependent variable)

regression_log <- lm(log_dependent variable ~ independent variable(s), data =

calschool)

summary(regression_log)

# 2. Convert a continuous variable into a nominal / ordinal variables

quantile(calschool$ell, 0.75, na.rm = TRUE) # find the value of ell at 75%, we set

this value as the cutoff.

calschool$ell_cat[calschool$ell < 50.25] <- 0

calschool$ell_cat[calschool$ell >= 50.25] <- 1

calschool$ell_cat <- factor(calschool$ell_cat) # make ell_cat as a dummy

variable that only has value 1 and 0.

# Create a dummy variable for mealcat

calschool$high_mealcat <- ifelse(calschool$mealcat == 3, 1, 0)

calschool$med_mealcat <- ifelse(calschool$mealcat == 2, 1, 0)

calschool$low_mealcat <- ifelse(calschool$mealcat == 1, 1, 0)

# 3. Create an interaction variable of dummy variables, just multiply these two

dummy variable ell_cat*high_mealcat.

regression_interaction_high <- lm(dependent variable ~ ell_cat*high_mealcat,

data = calschool)

summary(regression_interaction_high)

#4 Visualization extension: For students who would like to experiment with

improved visualizations

#First, we will need to install some new packages:

install.packages("stargazer")

install.packages("lmtest")

install.packages("corrplot")

12

install.packages("sjPlot")

library(stargazer)

library(lmtest)

library(corrplot)

library(sjPlot)

#Then, run this code:

# Correlation Matrix Visualization

corrmatrix <- cor(calschool, use = "complete.obs")

View(corrmatrix)

corrplot(corrmatrix, method="circle") # correlation_table_calschool is the name of

the correlation matrix we created above

corrplot.mixed(corrmatrix, number.cex = 0.8, tl.cex = 0.6)

#number.cex changes the size of the number fonts. tl.cex changes the size of the

labels

corrplot(corrmatrix, type="lower")

#Here is some code to improve the formatting of your regression results

#Here is the unadjusted regression model (first model that only has independent

variable) output using the `sjPlot` package.

sjt.lm(regression_1,

show.header = TRUE,

p.numeric = FALSE,

show.se = TRUE,

show.fstat = TRUE,

string.est = "Estimate",

string.ci = "Conf. Int.",

string.dv = "Unadjusted Regression Model",

depvar.labels = c(" % Free Meals"),

pred.labels = c("School wide Academic Performance"))

#Here is the adjusted regression model output using the `sjPlot` package.

sjt.lm(regression_final,

show.header = TRUE,

p.numeric = FALSE,

show.se = TRUE,

digits.se = 3,

show.fstat = TRUE,

string.est = "Estimate",

13

string.ci = "Conf. Int.",

string.dv = "Adjusted Regression Model",

depvar.labels = c("% Free Meals"),

pred.labels = c("School Wide Academic Performance", "% English learners",

"% teachers with full credentials"))

#Showing the unadjusted (first model) and adjusted regression (final model)

results side by side

#stargazer package

stargazer(regression_1, regression_final, title="Regression Results",

dep.var.labels=c("% Free Meals"), type="text")

#sjPlot package:

sjt.lm(regression_1, regression_final,

show.header = TRUE,

p.numeric = FALSE,

show.se = TRUE,

digits.se = 3,

show.fstat = TRUE,

group.pred = FALSE,

string.est = "Estimate",

string.ci = "Conf. Int.",

string.dv = "Regression Results",

depvar.labels = c("Unadjusted Regression Model", "Adjusted Regression

Model"),

pred.labels = c("School Wide Academic Performance", "% English

Learners",

"% teachers with full credentials"))

Solution image

Enjoy 40% Discount on All Assignments.

Or

img-responsive

Please Wait