Multiple Linear Regression: Grading the Professor

Getting started

# If needed: install.packages(c('tidyverse','openintro','GGally'))
library(tidyverse)
library(openintro)
library(GGally)
set.seed(607)
data(evals, package = 'openintro')
glimpse(evals)
Rows: 463
Columns: 23
$ course_id     <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1…
$ prof_id       <int> 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,…
$ score         <dbl> 4.7, 4.1, 3.9, 4.8, 4.6, 4.3, 2.8, 4.1, 3.4, 4.5, 3.8, 4…
$ rank          <fct> tenure track, tenure track, tenure track, tenure track, …
$ ethnicity     <fct> minority, minority, minority, minority, not minority, no…
$ gender        <fct> female, female, female, female, male, male, male, male, …
$ language      <fct> english, english, english, english, english, english, en…
$ age           <int> 36, 36, 36, 36, 59, 59, 59, 51, 51, 40, 40, 40, 40, 40, …
$ cls_perc_eval <dbl> 55.81395, 68.80000, 60.80000, 62.60163, 85.00000, 87.500…
$ cls_did_eval  <int> 24, 86, 76, 77, 17, 35, 39, 55, 111, 40, 24, 24, 17, 14,…
$ cls_students  <int> 43, 125, 125, 123, 20, 40, 44, 55, 195, 46, 27, 25, 20, …
$ cls_level     <fct> upper, upper, upper, upper, upper, upper, upper, upper, …
$ cls_profs     <fct> single, single, single, single, multiple, multiple, mult…
$ cls_credits   <fct> multi credit, multi credit, multi credit, multi credit, …
$ bty_f1lower   <int> 5, 5, 5, 5, 4, 4, 4, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 7, 7,…
$ bty_f1upper   <int> 7, 7, 7, 7, 4, 4, 4, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 9, 9,…
$ bty_f2upper   <int> 6, 6, 6, 6, 2, 2, 2, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 9, 9,…
$ bty_m1lower   <int> 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7,…
$ bty_m1upper   <int> 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 6,…
$ bty_m2upper   <int> 6, 6, 6, 6, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6,…
$ bty_avg       <dbl> 5.000, 5.000, 5.000, 5.000, 3.000, 3.000, 3.000, 3.333, …
$ pic_outfit    <fct> not formal, not formal, not formal, not formal, not form…
$ pic_color     <fct> color, color, color, color, color, color, color, color, …
stopifnot(all(complete.cases(evals)))
# Format fitted equations, including indicator terms.
eq <- function(m) {
  b <- coef(m)
  paste0(round(b[1], 4), paste(sprintf(' %s %.4f * %s',
    ifelse(b[-1] < 0, '-', '+'), abs(b[-1]), names(b)[-1]), collapse=''))
}
# Common regression diagnostics.
diag_plots <- function(m) {
  d <- tibble(fitted = fitted(m), residual = resid(m),
              standardized = rstandard(m), order = seq_along(resid(m)))
  print(ggplot(d, aes(fitted, residual)) + geom_point(alpha=.5) +
    geom_hline(yintercept=0, linetype=2) + geom_smooth(se=FALSE) + theme_minimal())
  print(ggplot(d, aes(sample=standardized)) + stat_qq() + stat_qq_line() + theme_minimal())
  print(ggplot(d, aes(fitted, sqrt(abs(standardized)))) + geom_point(alpha=.5) +
    geom_smooth(se=FALSE) + labs(y='Square root of absolute standardized residual') + theme_minimal())
  print(ggplot(d, aes(order, residual)) + geom_point(alpha=.5) +
    geom_hline(yintercept=0, linetype=2) + theme_minimal())
}

The unit of observation is a course. The supplied lab reports 463 rows and 23 columns (21 substantive variables plus two identifiers).

Exercise 1

Question: Is this an observational study or an experiment? The original research question posed in the paper is whether beauty leads directly to the differences in course evaluations. Given the study design, is it possible to answer this question as it is phrased? If not, rephrase the question.

Answer:

This is an observational study: neither beauty nor other instructor characteristics were randomly assigned. A causal effect cannot be established because confounding may explain the association. A suitable question is: Is average instructor beauty rating associated with course evaluation scores?

Exercise 2

Question: Describe 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?

Answer:

summary(evals$score)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  2.300   3.800   4.300   4.175   4.600   5.000 
ggplot(evals, aes(score)) + geom_histogram(binwidth=.2, boundary=0, color='white') + theme_minimal()

Scores are concentrated near the upper end of the 1–5 scale, with a longer lower tail (left skew). Students generally rate courses favorably. This is plausible because satisfactory courses may be common and the scale has an upper ceiling; response bias is also possible, but cannot be established from the histogram.

Exercise 3

Question: Excluding score, select two other variables and describe their relationship with each other using an appropriate visualization.

Answer:

ggplot(evals, aes(gender, bty_avg)) + geom_boxplot() + geom_jitter(width=.12, alpha=.2) + theme_minimal()

evals %>% group_by(gender) %>% summarise(n=n(), median=median(bty_avg), mean=mean(bty_avg), IQR=IQR(bty_avg))
# A tibble: 2 × 5
  gender     n median  mean   IQR
  <fct>  <int>  <dbl> <dbl> <dbl>
1 female   195   4.33  4.66  2.5 
2 male     268   4     4.24  2.33

The boxplots compare beauty ratings across gender categories. Female instructors tend to have higher beauty ratings in this course-level sample, although the distributions overlap. Repeated courses can give some professors more weight.

Exercise 4

Question: Before you draw conclusions about the trend, compare the number of observations in the data frame with the approximate number of points on the scatterplot. Is anything awry? Replot the scatterplot, but this time use geom_jitter as your layer. What was misleading about the initial scatterplot?

Answer:

ggplot(evals, aes(bty_avg, score)) + geom_point() + theme_minimal()

nrow(evals)
[1] 463
nrow(distinct(evals, bty_avg, score))
[1] 264
ggplot(evals, aes(bty_avg, score)) + geom_jitter(width=.06, height=.04, alpha=.5) + theme_minimal()

There are 463 observations, but fewer distinct coordinate pairs. Overplotting hides observations with identical or nearly identical ratings. Jitter reveals their density without changing the underlying data used for regression.

Exercise 5

Question: Let’s see if the apparent trend in the plot is something more than natural variation. Fit a linear model called m_bty to predict average professor score by average beauty rating. Write out the equation for the linear model and interpret the slope. Is average beauty score a statistically significant predictor? Does it appear to be a practically significant predictor?

Answer:

m_bty <- lm(score ~ bty_avg, data=evals)
summary(m_bty)

Call:
lm(formula = score ~ bty_avg, data = evals)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.9246 -0.3690  0.1420  0.3977  0.9309 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  3.88034    0.07614   50.96  < 2e-16 ***
bty_avg      0.06664    0.01629    4.09 5.08e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5348 on 461 degrees of freedom
Multiple R-squared:  0.03502,   Adjusted R-squared:  0.03293 
F-statistic: 16.73 on 1 and 461 DF,  p-value: 5.083e-05
eq(m_bty)
[1] "3.8803 + 0.0666 * bty_avg"
ggplot(evals, aes(bty_avg, score)) + geom_jitter(width=.06,height=.04,alpha=.5) + geom_smooth(method='lm', formula=y~x) + theme_minimal()

ggplot(evals, aes(bty_avg, score)) + geom_jitter(width=.06,height=.04,alpha=.5) + geom_smooth(method='lm', formula=y~x,se=FALSE) + theme_minimal()

The fitted equation is \(\widehat{score}=3.8803 + 0.0666 * bty_avg\). A one-point increase in beauty rating is associated with an estimated 0.0666 point increase in course score. The conventional p-value is 5.083^{-5}, statistically significant at 5%. However, the effect is small on the five-point scale and the model explains only 3.5% of variation. The shaded band is a confidence interval for the fitted mean, not a prediction interval for individual courses.

Exercise 6

Question: Use residual plots to evaluate whether the conditions of least squares regression are reasonable. Provide plots and comments for each one (see the Simple Regression Lab for a reminder of how to make these).

Answer:

diag_plots(m_bty)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Linearity: inspect the residual smooth for systematic curvature; the linear trend is a reasonable first approximation. Normality: the bounded score and long lower tail produce departures from normality, especially in the lower tail of the Q-Q plot. Constant variance: the upper score ceiling can restrict residual spread at high fitted values; inspect the scale-location plot for changing spread. Independence: the order plot is only a screening tool; multiple courses from the same professor may be correlated. Consequently conventional inference requires caution.

Allied task: correlation among beauty measures

ggplot(evals, aes(bty_f1lower,bty_avg)) + geom_point() + theme_minimal()

evals %>% summarise(correlation=cor(bty_avg,bty_f1lower))
# A tibble: 1 × 1
  correlation
        <dbl>
1       0.844
evals %>% select(contains('bty')) %>% ggpairs()

The reported correlation is 0.844. The average is constructed from the six individual ratings, so including all six and their average would create exact or near collinearity. Use the average as the representative predictor.

Exercise 7

Question: P-values and parameter estimates should only be trusted if the conditions for the regression are reasonable. Verify that the conditions for this model are reasonable using diagnostic plots.

Answer:

m_bty_gen <- lm(score ~ bty_avg + gender, data=evals)
summary(m_bty_gen)

Call:
lm(formula = score ~ bty_avg + gender, data = evals)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.8305 -0.3625  0.1055  0.4213  0.9314 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  3.74734    0.08466  44.266  < 2e-16 ***
bty_avg      0.07416    0.01625   4.563 6.48e-06 ***
gendermale   0.17239    0.05022   3.433 0.000652 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5287 on 460 degrees of freedom
Multiple R-squared:  0.05912,   Adjusted R-squared:  0.05503 
F-statistic: 14.45 on 2 and 460 DF,  p-value: 8.177e-07
diag_plots(m_bty_gen)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The additive linear model is a reasonable descriptive approximation, but the Q-Q plot should be checked for the pronounced lower tail and the scale-location plot for unequal spread. The score ceiling limits residuals. The residual order plot cannot establish independence because courses are clustered by professor. These limitations qualify ordinary least-squares p-values.

Exercise 8

Question: Is bty_avg still a significant predictor of score? Has the addition of gender to the model changed the parameter estimate for bty_avg?

Answer:

tibble(model=c('Beauty only','Beauty and gender'), slope=c(coef(m_bty)[2],coef(m_bty_gen)[2]), p=c(coef(summary(m_bty))[2,4],coef(summary(m_bty_gen))[2,4]))
# A tibble: 2 × 3
  model              slope          p
  <chr>              <dbl>      <dbl>
1 Beauty only       0.0666 0.0000508 
2 Beauty and gender 0.0742 0.00000648

Yes. The supplied output gives a beauty coefficient of 0.07416 and p = 0.00000648 after controlling for gender. The slope increases relative to the simple model. The fitted gender-specific equations are female: 3.74734 + 0.07416 × beauty; male: 3.91973 + 0.07416 × beauty. At equal beauty ratings, male instructors have a predicted score 0.17239 higher.

Exercise 9

Question: What is the equation of the line corresponding to those with color pictures? (Hint: For those with color pictures, the parameter estimate is multiplied by 1.) For two professors who received the same beauty rating, which color picture tends to have the higher course evaluation score?

Answer:

The question switches from gender to picture color without defining a corresponding model. Fit an additive beauty-and-picture-color model explicitly, using black and white as the reference. The original grouped smoothing plot fits separate slopes, unlike this additive model.

# Encode color directly, avoiding relevel() and category spelling issues.
evals$pic_color <- factor(ifelse(tolower(trimws(as.character(evals$pic_color))) == 'color',
                                 'color', 'non-color'),
                          levels = c('non-color', 'color'))
stopifnot(all(table(evals$pic_color) > 0))
m_bty_color <- lm(score ~ bty_avg + pic_color, data=evals)
summary(m_bty_color)

Call:
lm(formula = score ~ bty_avg + pic_color, data = evals)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.8892 -0.3690  0.1293  0.4023  0.9125 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)     4.06318    0.10908  37.249  < 2e-16 ***
bty_avg         0.05548    0.01691   3.282  0.00111 ** 
pic_colorcolor -0.16059    0.06892  -2.330  0.02022 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5323 on 460 degrees of freedom
Multiple R-squared:  0.04628,   Adjusted R-squared:  0.04213 
F-statistic: 11.16 on 2 and 460 DF,  p-value: 1.848e-05
b <- coef(m_bty_color)
ggplot(evals, aes(bty_avg,score,color=pic_color)) + geom_smooth(method='lm',formula=y~x,se=FALSE) + theme_minimal()

For color pictures: predicted score = 3.9026 + 0.0555 × beauty. For black-and-white pictures: predicted score = 4.0632 + 0.0555 × beauty. At equal beauty, black-and-white pictures have the higher predicted score, by 0.1606 points.

Exercise 10

Question: Create a new model called m_bty_rank with gender removed and rank added in. How does R appear to handle categorical variables that have more than two levels? Note that the rank variable has three levels: teaching, tenure track, tenured.

Answer:

m_bty_rank <- lm(score ~ bty_avg + rank, data=evals)
summary(m_bty_rank)

Call:
lm(formula = score ~ bty_avg + rank, data = evals)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.8713 -0.3642  0.1489  0.4103  0.9525 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
(Intercept)       3.98155    0.09078  43.860  < 2e-16 ***
bty_avg           0.06783    0.01655   4.098 4.92e-05 ***
ranktenure track -0.16070    0.07395  -2.173   0.0303 *  
ranktenured      -0.12623    0.06266  -2.014   0.0445 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5328 on 459 degrees of freedom
Multiple R-squared:  0.04652,   Adjusted R-squared:  0.04029 
F-statistic: 7.465 on 3 and 459 DF,  p-value: 6.88e-05
levels(evals$rank)
[1] "teaching"     "tenure track" "tenured"     
contrasts(evals$rank)
             tenure track tenured
teaching                0       0
tenure track            1       0
tenured                 0       1

R uses two indicator variables for the three rank categories, with teaching as reference. Each rank coefficient compares that rank with teaching at the same beauty rating. The beauty coefficient represents a one-point increase holding rank fixed.

Exercise 11

Question: Which variable would you expect to have the highest p-value in this model? Why? Hint: Think about which variable would you expect to not have any association with the professor score.

Answer:

Before fitting the full model, I would expect cls_profs (single versus multiple instructors) to have a high p-value because the number of instructors need not directly reflect teaching quality. This is a hypothesis rather than a result.

Exercise 12

Question: Check your suspicions from the previous exercise. Include the model output in your response.

Answer:

m_full <- lm(score ~ rank + gender + ethnicity + language + age + cls_perc_eval + cls_students + cls_level + cls_profs + cls_credits + bty_avg + pic_outfit + pic_color, data=evals)
summary(m_full)

Call:
lm(formula = score ~ rank + gender + ethnicity + language + age + 
    cls_perc_eval + cls_students + cls_level + cls_profs + cls_credits + 
    bty_avg + pic_outfit + pic_color, data = evals)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.77397 -0.32432  0.09067  0.35183  0.95036 

Coefficients:
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)            4.0952141  0.2905277  14.096  < 2e-16 ***
ranktenure track      -0.1475932  0.0820671  -1.798  0.07278 .  
ranktenured           -0.0973378  0.0663296  -1.467  0.14295    
gendermale             0.2109481  0.0518230   4.071 5.54e-05 ***
ethnicitynot minority  0.1234929  0.0786273   1.571  0.11698    
languagenon-english   -0.2298112  0.1113754  -2.063  0.03965 *  
age                   -0.0090072  0.0031359  -2.872  0.00427 ** 
cls_perc_eval          0.0053272  0.0015393   3.461  0.00059 ***
cls_students           0.0004546  0.0003774   1.205  0.22896    
cls_levelupper         0.0605140  0.0575617   1.051  0.29369    
cls_profssingle       -0.0146619  0.0519885  -0.282  0.77806    
cls_creditsone credit  0.5020432  0.1159388   4.330 1.84e-05 ***
bty_avg                0.0400333  0.0175064   2.287  0.02267 *  
pic_outfitnot formal  -0.1126817  0.0738800  -1.525  0.12792    
pic_colorcolor        -0.2172630  0.0715021  -3.039  0.00252 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.498 on 448 degrees of freedom
Multiple R-squared:  0.1871,    Adjusted R-squared:  0.1617 
F-statistic: 7.366 on 14 and 448 DF,  p-value: 6.552e-14
drop1(m_full,test='F')
Single term deletions

Model:
score ~ rank + gender + ethnicity + language + age + cls_perc_eval + 
    cls_students + cls_level + cls_profs + cls_credits + bty_avg + 
    pic_outfit + pic_color
              Df Sum of Sq    RSS     AIC F value    Pr(>F)    
<none>                     111.08 -630.90                      
rank           2    0.8930 111.98 -631.19  1.8007 0.1663804    
gender         1    4.1085 115.19 -616.09 16.5694 5.544e-05 ***
ethnicity      1    0.6117 111.70 -630.36  2.4668 0.1169791    
language       1    1.0557 112.14 -628.52  4.2576 0.0396509 *  
age            1    2.0456 113.13 -624.45  8.2499 0.0042688 ** 
cls_perc_eval  1    2.9698 114.06 -620.69 11.9769 0.0005903 ***
cls_students   1    0.3599 111.44 -631.40  1.4513 0.2289607    
cls_level      1    0.2740 111.36 -631.76  1.1052 0.2936925    
cls_profs      1    0.0197 111.11 -632.82  0.0795 0.7780566    
cls_credits    1    4.6495 115.73 -613.92 18.7510 1.839e-05 ***
bty_avg        1    1.2967 112.38 -627.53  5.2294 0.0226744 *  
pic_outfit     1    0.5768 111.66 -630.50  2.3262 0.1279153    
pic_color      1    2.2893 113.37 -623.46  9.2328 0.0025162 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The supplied full-model output confirms that cls_profssingle has the largest coefficient p-value (0.77806). The full model has R-squared 0.1871 and adjusted R-squared 0.1617. The overall F-test is significant, but most score variation remains unexplained.

Exercise 13

Question: Interpret the coefficient associated with the ethnicity variable.

Answer:

The coefficient for ethnicitynot minority is 0.12349. Holding all other predictors fixed, courses taught by non-minority instructors are predicted to receive scores about 0.123 points higher than courses taught by minority instructors. The p-value is 0.11698, so this difference is not statistically significant at 5%. It does not establish a causal effect.

Exercise 14

Question: Drop the variable with the highest p-value and re-fit the model. Did the coefficients and significance of the other explanatory variables change? (One of the things that makes multiple regression interesting is that coefficient estimates depend on the other variables that are included in the model.) If not, what does this say about whether or not the dropped variable was collinear with the other explanatory variables?

Answer:

m_reduced <- update(m_full, . ~ . - cls_profs)
summary(m_reduced)

Call:
lm(formula = score ~ rank + gender + ethnicity + language + age + 
    cls_perc_eval + cls_students + cls_level + cls_credits + 
    bty_avg + pic_outfit + pic_color, data = evals)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.7836 -0.3257  0.0859  0.3513  0.9551 

Coefficients:
                        Estimate Std. Error t value Pr(>|t|)    
(Intercept)            4.0872523  0.2888562  14.150  < 2e-16 ***
ranktenure track      -0.1476746  0.0819824  -1.801 0.072327 .  
ranktenured           -0.0973829  0.0662614  -1.470 0.142349    
gendermale             0.2101231  0.0516873   4.065 5.66e-05 ***
ethnicitynot minority  0.1274458  0.0772887   1.649 0.099856 .  
languagenon-english   -0.2282894  0.1111305  -2.054 0.040530 *  
age                   -0.0089992  0.0031326  -2.873 0.004262 ** 
cls_perc_eval          0.0052888  0.0015317   3.453 0.000607 ***
cls_students           0.0004687  0.0003737   1.254 0.210384    
cls_levelupper         0.0606374  0.0575010   1.055 0.292200    
cls_creditsone credit  0.5061196  0.1149163   4.404 1.33e-05 ***
bty_avg                0.0398629  0.0174780   2.281 0.023032 *  
pic_outfitnot formal  -0.1083227  0.0721711  -1.501 0.134080    
pic_colorcolor        -0.2190527  0.0711469  -3.079 0.002205 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.4974 on 449 degrees of freedom
Multiple R-squared:  0.187, Adjusted R-squared:  0.1634 
F-statistic: 7.943 on 13 and 449 DF,  p-value: 2.336e-14
common <- intersect(names(coef(m_full)),names(coef(m_reduced)))
tibble(term=common, full=coef(m_full)[common], reduced=coef(m_reduced)[common],
       change=reduced-full, p_full=coef(summary(m_full))[common,4],
       p_reduced=coef(summary(m_reduced))[common,4])
# A tibble: 14 × 6
   term                       full   reduced      change   p_full p_reduced
   <chr>                     <dbl>     <dbl>       <dbl>    <dbl>     <dbl>
 1 (Intercept)            4.10      4.09     -0.00796    1.32e-37  7.53e-38
 2 ranktenure track      -0.148    -0.148    -0.0000813  7.28e- 2  7.23e- 2
 3 ranktenured           -0.0973   -0.0974   -0.0000451  1.43e- 1  1.42e- 1
 4 gendermale             0.211     0.210    -0.000825   5.54e- 5  5.66e- 5
 5 ethnicitynot minority  0.123     0.127     0.00395    1.17e- 1  9.99e- 2
 6 languagenon-english   -0.230    -0.228     0.00152    3.97e- 2  4.05e- 2
 7 age                   -0.00901  -0.00900   0.00000800 4.27e- 3  4.26e- 3
 8 cls_perc_eval          0.00533   0.00529  -0.0000385  5.90e- 4  6.07e- 4
 9 cls_students           0.000455  0.000469  0.0000141  2.29e- 1  2.10e- 1
10 cls_levelupper         0.0605    0.0606    0.000123   2.94e- 1  2.92e- 1
11 cls_creditsone credit  0.502     0.506     0.00408    1.84e- 5  1.33e- 5
12 bty_avg                0.0400    0.0399   -0.000170   2.27e- 2  2.30e- 2
13 pic_outfitnot formal  -0.113    -0.108     0.00436    1.28e- 1  1.34e- 1
14 pic_colorcolor        -0.217    -0.219    -0.00179    2.52e- 3  2.21e- 3
anova(m_reduced,m_full)
Analysis of Variance Table

Model 1: score ~ rank + gender + ethnicity + language + age + cls_perc_eval + 
    cls_students + cls_level + cls_credits + bty_avg + pic_outfit + 
    pic_color
Model 2: score ~ rank + gender + ethnicity + language + age + cls_perc_eval + 
    cls_students + cls_level + cls_profs + cls_credits + bty_avg + 
    pic_outfit + pic_color
  Res.Df    RSS Df Sum of Sq      F Pr(>F)
1    449 111.11                           
2    448 111.08  1  0.019722 0.0795 0.7781

The coefficients need not remain exactly identical. The comparison table quantifies the changes and whether significance crosses 0.05. Small changes suggest that cls_profs contributes little unique information and does not strongly distort the remaining estimates; this is not proof of absence of collinearity.

Exercise 15

Question: Using backward-selection and p-value as the selection criterion, determine the best model. You do not need to show all steps in your answer, just the output for the final model. Also, write out the linear model for predicting score based on the final model you settle on.

Answer:

Use backward elimination with a 5% threshold and partial F-test p-values for entire terms, so multi-level rank is retained or removed as a unit.

m_final <- m_full
repeat {
  tests <- drop1(m_final,test='F')
  p <- tests[-1,'Pr(>F)']; names(p) <- rownames(tests)[-1]
  p <- p[!is.na(p)]
  if (!length(p) || max(p)<=.05) break
  m_final <- update(m_final, as.formula(paste('. ~ . -',names(which.max(p)))))
}
summary(m_final)

Call:
lm(formula = score ~ gender + ethnicity + language + age + cls_perc_eval + 
    cls_credits + bty_avg + pic_color, data = evals)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.85320 -0.32394  0.09984  0.37930  0.93610 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)            3.771922   0.232053  16.255  < 2e-16 ***
gendermale             0.207112   0.050135   4.131 4.30e-05 ***
ethnicitynot minority  0.167872   0.075275   2.230  0.02623 *  
languagenon-english   -0.206178   0.103639  -1.989  0.04726 *  
age                   -0.006046   0.002612  -2.315  0.02108 *  
cls_perc_eval          0.004656   0.001435   3.244  0.00127 ** 
cls_creditsone credit  0.505306   0.104119   4.853 1.67e-06 ***
bty_avg                0.051069   0.016934   3.016  0.00271 ** 
pic_colorcolor        -0.190579   0.067351  -2.830  0.00487 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.4992 on 454 degrees of freedom
Multiple R-squared:  0.1722,    Adjusted R-squared:  0.1576 
F-statistic:  11.8 on 8 and 454 DF,  p-value: 2.58e-15
formula(m_final)
score ~ gender + ethnicity + language + age + cls_perc_eval + 
    cls_credits + bty_avg + pic_color
eq(m_final)
[1] "3.7719 + 0.2071 * gendermale + 0.1679 * ethnicitynot minority - 0.2062 * languagenon-english - 0.0060 * age + 0.0047 * cls_perc_eval + 0.5053 * cls_creditsone credit + 0.0511 * bty_avg - 0.1906 * pic_colorcolor"

The final fitted equation is: predicted score = 3.7719 + 0.2071 * gendermale + 0.1679 * ethnicitynot minority - 0.2062 * languagenon-english - 0.0060 * age + 0.0047 * cls_perc_eval + 0.5053 * cls_creditsone credit + 0.0511 * bty_avg - 0.1906 * pic_colorcolor. Categorical coefficient names denote indicators equal to one for the named level and zero for the reference. Selection is sample-dependent and post-selection p-values are exploratory.

Exercise 16

Question: Verify that the conditions for this model are reasonable using diagnostic plots.

Answer:

diag_plots(m_final)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

plot(m_final, which=4)

Assess linearity from the residual-versus-fitted smooth, normality from the Q-Q plot, and constant variance from the scale-location plot. The bounded response makes perfect normality and constant variance unlikely, particularly near the upper ceiling. Cook’s distance identifies potentially influential courses, not automatic exclusions. Independence remains questionable because of repeated professors. The model is useful descriptively but standard inference is qualified.

Exercise 17

Question: The original paper describes how these data were gathered by taking a sample of professors from the University of Texas at Austin and including all courses that they have taught. Considering that each row represents a course, could this new information have an impact on any of the conditions of linear regression?

Answer:

Yes. Courses taught by the same professor share characteristics and may have correlated errors, violating independence. Ordinary standard errors can be misleading. Cluster-robust standard errors or a professor-level random intercept are possible remedies.

evals %>% count(prof_id) %>% summarise(professors=n(), repeated=sum(n>1), max_courses=max(n))
# A tibble: 1 × 3
  professors repeated max_courses
       <int>    <int>       <int>
1         94       87          13
# Optional cluster-robust inference if packages are installed.
if (requireNamespace('sandwich',quietly=TRUE) && requireNamespace('lmtest',quietly=TRUE)) {
  print(lmtest::coeftest(m_final, vcov.=sandwich::vcovCL(m_final,cluster=evals$prof_id)))
}

t test of coefficients:

                        Estimate Std. Error t value  Pr(>|t|)    
(Intercept)            3.7719215  0.3349681 11.2605 < 2.2e-16 ***
gendermale             0.2071121  0.0713747  2.9018  0.003891 ** 
ethnicitynot minority  0.1678723  0.1056573  1.5888  0.112793    
languagenon-english   -0.2061781  0.1145076 -1.8006  0.072436 .  
age                   -0.0060459  0.0039096 -1.5464  0.122701    
cls_perc_eval          0.0046559  0.0019034  2.4460  0.014822 *  
cls_creditsone credit  0.5053062  0.1168917  4.3229 1.894e-05 ***
bty_avg                0.0510693  0.0271425  1.8815  0.060540 .  
pic_colorcolor        -0.1905788  0.1126338 -1.6920  0.091328 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Exercise 18

Question: Based on your final model, describe the characteristics of a professor and course at University of Texas at Austin that would be associated with a high evaluation score.

Answer:

# Describe favorable directions for every retained predictor.
co <- coef(m_final)[-1]
tibble(term=names(co), estimate=as.numeric(co), favorable=ifelse(co>0,'Higher value / named category','Lower value / reference category'))
# A tibble: 8 × 3
  term                  estimate favorable                       
  <chr>                    <dbl> <chr>                           
1 gendermale             0.207   Higher value / named category   
2 ethnicitynot minority  0.168   Higher value / named category   
3 languagenon-english   -0.206   Lower value / reference category
4 age                   -0.00605 Lower value / reference category
5 cls_perc_eval          0.00466 Higher value / named category   
6 cls_creditsone credit  0.505   Higher value / named category   
7 bty_avg                0.0511  Higher value / named category   
8 pic_colorcolor        -0.191   Lower value / reference category

A high predicted evaluation is associated with the favorable directions shown above, holding other retained predictors fixed. In particular, the full-model evidence suggests higher beauty, younger age, higher evaluation participation, male gender, English-language degree background, one-credit courses and black-and-white pictures are favorable associations; the final table identifies which survive selection. These are not causal recommendations or measures of teaching effectiveness.

Exercise 19

Question: Would you be comfortable generalizing your conclusions to apply to professors generally (at any university)? Why or why not?

Answer:

No. The data are from one university, and its students, courses, evaluation procedures and instructor population may differ from those elsewhere. Repeated courses also affect the effective sample size. Generalization requires representative multi-university data and validation. The observational design does not establish causation even within the original university.

Source and reproducibility

Source: supplied OpenIntro multiple linear regression lab, Grading the professor, using openintro::evals. Model outputs and plots are generated when knitted. The R runtime was unavailable during preparation, so execution and plot-specific observations have not been independently verified.