\(~\)
This lab will use data from a major US university that was assembled in response to an evaluation of salary disparities between male and female faculty at the university. The publicly released version of the data excludes any potentially identifying variables, and masks the department of each faculty member under the discipline categories “A” (departments deemed to be theoretical or part of the liberal arts) and “B” (departments deemed to be applied or business oriented).
fac_sal = read.csv("https://remiller1450.github.io/data/Salaries.csv")
The outcome variable in our analysis is Salary, the
9-month salary of the faculty member. There are several categorical
predictors we will consider:
sex - whether the sex of the professor is male or
female.rank - either “AsstProf”, the lowest rank, “AssocProf”,
an intermediate rank, or “Prof”, the highest rank.discipline - whether the professor belongs to group “A”
or “B” (see the description in the paragraph above)Question #1: For this question you are to consider
using one-hot encoding to represent the variable
rank using a set of dummy variables.
R will use the
first alphabetical category as the reference category when creating
dummy variables. For these data, that is the “AssocProf” category. With
this in mind, write out the form of the population-level linear
regression model involving the dummy variables described in Part A.lm() function and the model formula
salary ~ rank. Then use the summary() function
to print a summary of the fitted model.rankAsstProf. What does this value you tell you
about the mean faculty salaries at different ranks?dplyr package. Use grouped summarization to find the mean
salary for each rank. How do these means relate to the fitted model
coefficients from Parts C-E?\(~\)
Question #2: This question will focus on changing
the reference category, which is useful to facilitate comparisons
between different groups. Below we use the factor()
function to overwrite an existing categorical variable with a new order
of levels:
fac_sal$rank = factor(fac_sal$rank, levels = c("AsstProf", "AssocProf", "Prof"))
new_rank_model = lm(salary ~ rank, data = fac_sal)
summary(new_rank_model)
##
## Call:
## lm(formula = salary ~ rank, data = fac_sal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -68972 -16376 -1580 11755 104773
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 80776 2887 27.976 < 2e-16 ***
## rankAssocProf 13100 4131 3.171 0.00164 **
## rankProf 45996 3230 14.238 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 23630 on 394 degrees of freedom
## Multiple R-squared: 0.3943, Adjusted R-squared: 0.3912
## F-statistic: 128.2 on 2 and 394 DF, p-value: < 2.2e-16
Notice how the model’s intercept and coefficients have changed to reflect the new reference category, but the model’s predictions for each category are still the same (the group means you found in Question 1 Part F).
sex to
predict salary and print a summary of the fitted model.
Which category of sex was used as the reference group?factor() function to change the reference category
to “Female” and refit the model from Part A using the modified data. How
did the slope and intercept of this model change from Part A?sexMale and
sexFemale coefficients in the models from Part A and Part
C. In your own words, explain why they are identical.