library(tidyverse)
library(tidymodels)
library(openintro)
Activity: Grading the professor
Simple and multiple linear regression
Many college courses conclude by giving students the opportunity to evaluate the course and the instructor anonymously. However, the use of these student evaluations as an indicator of course quality and teaching effectiveness is often criticized because these measures may reflect the influence of non-teaching related characteristics, such as the physical appearance of the instructor. The article titled, “Beauty in the classroom: instructors’ pulchritude and putative pedagogical productivity” (Hamermesh and Parker, 2005) found that instructors who are viewed to be better looking receive higher instructional ratings. (Daniel S. Hamermesh, Amy Parker, Beauty in the classroom: instructors pulchritude and putative pedagogical productivity, Economics of Education Review, Volume 24, Issue 4, August 2005, Pages 369-376, ISSN 0272-7757, 10.1016/j.econedurev.2004.07.013. http://www.sciencedirect.com/science/article/pii/S0272775704001165.)
In this activity you will analyze the data from this study in order to learn what goes into a positive professor evaluation.
The data were gathered from end of semester student evaluations for a large sample of professors from the University of Texas at Austin. In addition, six students rated the professors’ physical appearance. (This is a slightly modified version of the original data set that was released as part of the replication data for Data Analysis Using Regression and Multilevel/Hierarchical Models (Gelman and Hill, 2007).) The result is a data frame where each row contains a different course and columns represent variables about the courses and professors.
Learning goals
- Fitting a linear regression with a single numerical and categorical predictor
- Interpreting regression output in context of the data
- Comparing models
Getting started
Download the activity Quarto file here and place it in your class activities folder.
Open the R Quarto document.
Render the document to make sure it compiles without errors.
Update the YAML (header) of your Quarto file with your information and render.
What to do if you face an error when installing and loading the tidymodels
package.
The newest version of
tidymodels
requires you to either:Update the
rlang
package. Useinstall.packages("rlang")
to update.Update your version of RStudio. To do so, you will need to download the newest release of RStudio (that came out just after we started the semester):
Note: you do not need to uninstall anything in order to update. Simply download the newest version and install.
Packages
We’ll use the tidyverse
package for much of the data wrangling and visualization, the tidymodels
package for modeling and inference, and the data lives in the dsbox
package. These packages are already installed for you. You can load them by running the following in your Console:
Data
The data can be found in the openintro
package, and it’s called evals
.
Since the dataset is distributed with the package, we don’t need to load it separately; it becomes available to us when we load the package. You can find out more about the dataset by inspecting its documentation, which you can access by running ?evals
in the Console or using the Help menu in RStudio to search for evals
. You can also find this information here.
Part 1 Simple linear regression
Exploratory Data Analysis
- Visualize the distribution of
score
. Is the distribution skewed? What does that tell you about how students rate courses? Is this what you expected to see? Why, or why not? Include any summary statistics and visualizations you use in your response.
# Your code here
- Visualize and describe the relationship between
score
andbty_avg
.
# Your code here
- Recreate the scatterplot from Step 2, but this time use
geom_jitter()
. What does “jitter” mean? What was misleading about the initial scatterplot?
# Your code here
Linear regression with a numerical predictor
Linear model is in the form \(\hat{y} = b_0 + b_1 x\).
- Let’s see if the apparent trend in the plot is something more than natural variation. Fit a linear model called
score_bty_fit
to predict average professor evaluationscore
by average beauty rating (bty_avg
). Based on the regression output, write the linear model (as a comment inside the code chunk).
# Your code here
- Recreate the scatterplot from Step 2, and add the regression line to this plot in orange color, with shading for the uncertainty of the line turned off.
# Your code here
- Interpret the slope of the linear model in context of the data. Write your response below.
# Your code here
- Interpret the intercept of the linear model in context of the data. Comment on whether or not the intercept makes sense in this context. Write your response below.
- Determine the \(R^2\) of the model and interpret it in context of the data. Write your response below.
- Working with residuals. Calculate the required variables and make a scatter plot which shows the residuals \(e_i = y_i - \widehat{y_i}\) on the y-axis and the predicted values \(\widehat{y_i}\) on the x-axis.
# Your code here
What aspects of the residual plot show that the linear model is appropriate or not? Are there any aspects of the residual plot that cause you to be concerned about the fitting of the linear model? Write your response.
Linear regression with a categorical predictor
- Fit a new linear model called
score_gender_fit
to predict average professor evaluationscore
based ongender
of the professor. Based on the regression output, write the linear model and interpret the slope and intercept in context of the data.
# Your code here
What is the equation of the line corresponding to male professors? What is it for female professors? Write your response below.
Fit a new linear model called
score_rank_fit
to predict average professor evaluationscore
based onrank
of the professor. Based on the regression output, write the linear model and interpret the slopes and intercept in context of the data.
# Your code here
- Create a new variable called
rank_relevel
where"tenure track"
is the baseline level. Use thefct_relevel
function to specify the baseline (first) level. See our notes on factors.
# Your code here
- Fit a new linear model called
score_rank_relevel_fit
to predict average professor evaluationscore
based onrank_relevel
of the professor. This is the new (releveled) variable you created in Step 12. Based on the regression output, write the linear model and interpret the slopes and intercept in context of the data. Also determine and interpret the \(R^2\) of the model.
# Your code here
- Create another new variable called
tenure_eligible
that labels"teaching"
faculty as"no"
and labels"tenure track"
and"tenured"
faculty as"yes"
.
# Your code here
- Fit a new linear model called
score_tenure_eligible_fit
to predict average professor evaluationscore
based ontenure_eligible
ness of the professor. This is the new (regrouped) variable you created in the previous Step. Based on the regression output, write the linear model and interpret the slopes and intercept in context of the data. Also determine and interpret the \(R^2\) of the model.
# Your code here
Part 2 Multiple linear regression
Simple linear regression
- (Refresher from above) Fit a linear model (one you have fit before):
score_bty_fit
, predicting average professor evaluationscore
based on average beauty rating (bty_avg
) only. Write the linear model, and note the \(R^2\) and the adjusted \(R^2\).
# Your code here
Multiple linear regression
- Fit a linear model:
score_bty_gen_fit
, predicting average professor evaluationscore
based on average beauty rating (bty_avg
) andgender
. Write the linear model, and note the \(R^2\) and the adjusted \(R^2\).
# Your code here
- Interpret the slopes and intercept of
score_bty_gen_fit
in context of the data. - What percent of the variability in
score
is explained by the modelscore_bty_gen_fit
? - What is the equation of the line corresponding to just male professors?
- For two professors who received the same beauty rating, which gender tends to have the higher course evaluation score?
- How does the relationship between beauty and evaluation score vary between male and female professors?
# Your code here
- How do the adjusted \(R^2\) values of
score_bty_gen_fit
andscore_bty_fit
compare? What does this tell us about how usefulgender
is in explaining the variability in evaluation scores when we already have information on the beauty score of the professor. - Compare the slopes of
bty_avg
under the two models (score_bty_fit
andscore_bty_gen_fit
). Has the addition ofgender
to the model changed the parameter estimate (slope) forbty_avg
? - Create a new model called
score_bty_rank_fit
withgender
removed andrank
added in. Write the equation of the linear model and interpret the slopes and intercept in context of the data.
# Your code here