### Install SortedEffects Package Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Installs the SortedEffects R package from GitHub. Requires the devtools package to be installed first. ```r install.packages("devtools") devtools::install_github("yuqimemeda/SortedEffects") ``` -------------------------------- ### Load Mortgage Data Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Loads the mortgage dataset for analysis. This is the initial step before performing any estimations. ```r data("mortgage") ``` -------------------------------- ### Estimate Sorted Partial Effects (SPE) Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Estimates SPE and APE using the 'spe' command. It specifies the model formula, data, the variable of interest ('black'), the estimation method ('logit'), the range of SPE quantiles, and the number of bootstrap replications. ```r test <- spe(fm = fm, data = mortgage, var = "black", method = "logit", us = c(2:98)/100, b = 500, bc = TRUE) ``` -------------------------------- ### Plot SPE and APE Results Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Visualizes the estimated Average Partial Effects (APE) and Sorted Partial Effects (SPE) with confidence bands. This helps in understanding the heterogeneity of effects. ```r plot(x = test, ylim = c(0, 0.25), ylab = "Change in Probability", main = "APE and SPE of Being Black on the Prob of Mortgage Denial", sub = "Logit Model") ``` -------------------------------- ### Specify Regression Model Formula Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Defines the formula for the binary response model, specifying the outcome variable (deny) and its covariates. ```r fm <- deny ~ black + p_irat + hse_inc + ccred + mcred + pubrec + ltv_med + ltv_high + denpmi + selfemp + single + hischl ``` -------------------------------- ### Summarize Classification Analysis Results Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Displays a summary of the classification analysis results, including estimates, standard errors, and p-values for the tabulated means of characteristics for different groups. ```r summary(CA) ``` -------------------------------- ### Perform Classification Analysis Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Conducts classification analysis using the 'ca' command to group observational units based on their affectedness by the variable of interest. It specifies the model, data, variable, method, classification type, variables for analysis, and bootstrap settings. ```r CA <- ca(fm = fm, data = mortgage, var = "black", method = "logit", cl = "both", t = t, b = 500, bc = TRUE) ``` -------------------------------- ### Define Variables for Classification Analysis Source: https://github.com/yuqimemeda/sortedeffects/blob/master/README.md Specifies a vector of variable names to be used in the classification analysis, including outcome, treatment, and control variables. ```r t <- c("deny", "p_irat", "black", "hse_inc", "ccred", "mcred", "pubrec", "denpmi", "selfemp", "single", "hischl", "ltv_med", "ltv_high") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.