library(tidyverse)## Warning: package 'ggplot2' was built under R version 4.0.4
library(openintro)
library(statsr)## Warning: package 'statsr' was built under R version 4.0.5
## Warning: package 'BayesFactor' was built under R version 4.0.5
## Warning: package 'coda' was built under R version 4.0.5
library(StMoSim)## Warning: package 'StMoSim' was built under R version 4.0.5
library(RcppParallel)## Warning: package 'RcppParallel' was built under R version 4.0.5
library(Rcpp)Background: The use of 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.
Purpose:
In this lab we will analyze the data from this study in order to learn what goes into a positive professor evaluation.
Data:
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 aslightly 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.
#The Data
download.file("http://www.openintro.org/stat/data/evals.RData", destfile = "evals.RData")
load("evals.RData")
str(evals) #view 463 observations with 21 variables## 'data.frame': 463 obs. of 21 variables:
## $ score : num 4.7 4.1 3.9 4.8 4.6 4.3 2.8 4.1 3.4 4.5 ...
## $ rank : Factor w/ 3 levels "teaching","tenure track",..: 2 2 2 2 3 3 3 3 3 3 ...
## $ ethnicity : Factor w/ 2 levels "minority","not minority": 1 1 1 1 2 2 2 2 2 2 ...
## $ gender : Factor w/ 2 levels "female","male": 1 1 1 1 2 2 2 2 2 1 ...
## $ language : Factor w/ 2 levels "english","non-english": 1 1 1 1 1 1 1 1 1 1 ...
## $ age : int 36 36 36 36 59 59 59 51 51 40 ...
## $ cls_perc_eval: num 55.8 68.8 60.8 62.6 85 ...
## $ cls_did_eval : int 24 86 76 77 17 35 39 55 111 40 ...
## $ cls_students : int 43 125 125 123 20 40 44 55 195 46 ...
## $ cls_level : Factor w/ 2 levels "lower","upper": 2 2 2 2 2 2 2 2 2 2 ...
## $ cls_profs : Factor w/ 2 levels "multiple","single": 2 2 2 2 1 1 1 2 2 2 ...
## $ cls_credits : Factor w/ 2 levels "multi credit",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ bty_f1lower : int 5 5 5 5 4 4 4 5 5 2 ...
## $ bty_f1upper : int 7 7 7 7 4 4 4 2 2 5 ...
## $ bty_f2upper : int 6 6 6 6 2 2 2 5 5 4 ...
## $ bty_m1lower : int 2 2 2 2 2 2 2 2 2 3 ...
## $ bty_m1upper : int 4 4 4 4 3 3 3 3 3 3 ...
## $ bty_m2upper : int 6 6 6 6 3 3 3 3 3 2 ...
## $ bty_avg : num 5 5 5 5 3 ...
## $ pic_outfit : Factor w/ 2 levels "formal","not formal": 2 2 2 2 2 2 2 2 2 2 ...
## $ pic_color : Factor w/ 2 levels "black&white",..: 2 2 2 2 2 2 2 2 2 2 ...
summary(evals) #view summary data## score rank ethnicity gender
## Min. :2.300 teaching :102 minority : 64 female:195
## 1st Qu.:3.800 tenure track:108 not minority:399 male :268
## Median :4.300 tenured :253
## Mean :4.175
## 3rd Qu.:4.600
## Max. :5.000
## language age cls_perc_eval cls_did_eval
## english :435 Min. :29.00 Min. : 10.42 Min. : 5.00
## non-english: 28 1st Qu.:42.00 1st Qu.: 62.70 1st Qu.: 15.00
## Median :48.00 Median : 76.92 Median : 23.00
## Mean :48.37 Mean : 74.43 Mean : 36.62
## 3rd Qu.:57.00 3rd Qu.: 87.25 3rd Qu.: 40.00
## Max. :73.00 Max. :100.00 Max. :380.00
## cls_students cls_level cls_profs cls_credits bty_f1lower
## Min. : 8.00 lower:157 multiple:306 multi credit:436 Min. :1.000
## 1st Qu.: 19.00 upper:306 single :157 one credit : 27 1st Qu.:2.000
## Median : 29.00 Median :4.000
## Mean : 55.18 Mean :3.963
## 3rd Qu.: 60.00 3rd Qu.:5.000
## Max. :581.00 Max. :8.000
## bty_f1upper bty_f2upper bty_m1lower bty_m1upper
## Min. :1.000 Min. : 1.000 Min. :1.000 Min. :1.000
## 1st Qu.:4.000 1st Qu.: 4.000 1st Qu.:2.000 1st Qu.:3.000
## Median :5.000 Median : 5.000 Median :3.000 Median :4.000
## Mean :5.019 Mean : 5.214 Mean :3.413 Mean :4.147
## 3rd Qu.:7.000 3rd Qu.: 6.000 3rd Qu.:5.000 3rd Qu.:5.000
## Max. :9.000 Max. :10.000 Max. :7.000 Max. :9.000
## bty_m2upper bty_avg pic_outfit pic_color
## Min. :1.000 Min. :1.667 formal : 77 black&white: 78
## 1st Qu.:4.000 1st Qu.:3.167 not formal:386 color :385
## Median :5.000 Median :4.333
## Mean :4.752 Mean :4.418
## 3rd Qu.:6.000 3rd Qu.:5.500
## Max. :9.000 Max. :8.167
view(evals) #view table of variables for the 463 observationsIs 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. An observational study is one in which individuals are observed or certain outcomes are measured. No attempt is made to affect the outcome (for example, no treatment is given to measure an outcome). In the observational study, researchers make no attempts to manipulate the study - they simply observe. Experiments are procedures carried out to support, refute, or validate a hypothesis. Experiments provide insight into cause-and-effect. They demonstrate what outcome occurs when a particular factor is manipulated.
In this observational study, there is no control group or experimental groups. The variables don’t “cause” or explain;the variables can be related;
Rephrased Question for the observational study: An instructor’s physical appearance is positively/negatively correlated to student course evaluations
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
Yes, the distribution is skewed to the left. This tells me that student evaluations are more positively rated than negatively rated. This is not what I expected, so as you will see below in the code, I did try to add a normal distribution curve to my histogram just to see what it looked like. I changed the ‘x’ in the arguments to several different things, however the line never appeared as expected, and then it errored out. I think my code is wrong. So, I was hoping to plot the normal distribution curve and then see “normalcy.” In other words, a normal distribution with average evaluations, including few outside the norms in the below average or above average directions.
#hist (v, main, xlab, xlim, ylim, breaks,col,border)
#where v – vector with numeric values
#main – denotes title of the chart
#col – sets color
#border -sets border color to the bar
#xlab - description of x-axis
#xlim - denotes to specify range of values on x-axis
#ylim – specifies range values on y-axis
#break – specifies the width of each bar.
hist(evals$score,
main="Evaluations: Distribution of Score",
xlab="Score",
border="Green",
col="Orange")#curve (dnorm(x, mean=mean(evals$score), sd=sd(evals$score)), add=TRUE, col="red") #Implement the Normal Distribution Curve in HistogramExcluding score, select two other variables and describe their relationship using an appropriate visualization (scatterplot, side-by-side boxplots, or mosaic plot).
Answer Average beauty of professor vs age of professor: according to the plot, there is no correlation between age and beauty I viewed the means of the distribution just to see if there was an observed correlation, but there doesn’t seem to be one.
I also looked at average beauty of professor vs. ethnicity to see if there was a correlation. I looked at the means, and while there is a very slight difference (4.6 for minority vs 4.4 for non-minority), I would need to conduct more tests (hypothesis test) to see if the difference is statistically significant. In looking at the plot, my first guess would be there is no correlation between average beauty of professor and ethnicity.
boxplot(bty_avg~age,
data=evals,
main = "Average Beauty Rating of Professor vs Age of Professor",
xlab = "Age of Professor",
ylab = "Average Beauty Rating",
col = "orange",
border = "brown",
vertical = TRUE,
notch = FALSE
)#view means of the distributions by using the following function to split the beauty variable into groups, then taking the mean of each using the mean function.
by(evals$bty_avg, evals$age, mean)## evals$age: 29
## [1] 2.833
## ------------------------------------------------------------
## evals$age: 31
## [1] 7.333
## ------------------------------------------------------------
## evals$age: 32
## [1] 5.424091
## ------------------------------------------------------------
## evals$age: 33
## [1] 5.268174
## ------------------------------------------------------------
## evals$age: 34
## [1] 4.151727
## ------------------------------------------------------------
## evals$age: 35
## [1] 5.388667
## ------------------------------------------------------------
## evals$age: 36
## [1] 5
## ------------------------------------------------------------
## evals$age: 37
## [1] 4.9832
## ------------------------------------------------------------
## evals$age: 38
## [1] 4.343059
## ------------------------------------------------------------
## evals$age: 39
## [1] 6.5835
## ------------------------------------------------------------
## evals$age: 40
## [1] 3.167
## ------------------------------------------------------------
## evals$age: 41
## [1] 5.167
## ------------------------------------------------------------
## evals$age: 42
## [1] 5.1665
## ------------------------------------------------------------
## evals$age: 43
## [1] 3.61984
## ------------------------------------------------------------
## evals$age: 44
## [1] 6.5
## ------------------------------------------------------------
## evals$age: 45
## [1] 3.8334
## ------------------------------------------------------------
## evals$age: 46
## [1] 4.333
## ------------------------------------------------------------
## evals$age: 47
## [1] 4.430805
## ------------------------------------------------------------
## evals$age: 48
## [1] 4.333
## ------------------------------------------------------------
## evals$age: 49
## [1] 5.071429
## ------------------------------------------------------------
## evals$age: 50
## [1] 3.675421
## ------------------------------------------------------------
## evals$age: 51
## [1] 5.052632
## ------------------------------------------------------------
## evals$age: 52
## [1] 4.262319
## ------------------------------------------------------------
## evals$age: 54
## [1] 5.1455
## ------------------------------------------------------------
## evals$age: 56
## [1] 2.999875
## ------------------------------------------------------------
## evals$age: 57
## [1] 3.791464
## ------------------------------------------------------------
## evals$age: 58
## [1] 6.178286
## ------------------------------------------------------------
## evals$age: 59
## [1] 3
## ------------------------------------------------------------
## evals$age: 60
## [1] 3.592667
## ------------------------------------------------------------
## evals$age: 61
## [1] 4.333
## ------------------------------------------------------------
## evals$age: 62
## [1] 3.48
## ------------------------------------------------------------
## evals$age: 63
## [1] 4.333
## ------------------------------------------------------------
## evals$age: 64
## [1] 3.320538
## ------------------------------------------------------------
## evals$age: 70
## [1] 3
## ------------------------------------------------------------
## evals$age: 73
## [1] 3
boxplot(bty_avg~ethnicity,
data=evals,
main = "Average Beauty Rating of Professor vs Ethnicity of Professor",
xlab = "Ethnicity of Professor",
ylab = "Average Beauty Rating",
col = "orange",
border = "brown",
vertical = TRUE,
notch = FALSE
)#view means of the distributions by using the following function to split the beauty variable into groups, then taking the mean of each using the mean function.
by(evals$bty_avg, evals$ethnicity, mean)## evals$ethnicity: minority
## [1] 4.57525
## ------------------------------------------------------------
## evals$ethnicity: not minority
## [1] 4.392596
Simple linear regression The fundamental phenomenon suggested by the study is that better looking teachers are evaluated more favorably. Let’s create a scatterplot to see if this appears to be the case:
#scatterplot
plot(evals$score~evals$bty_avg,
main = "Relationship Between Evaluation Score and Professor Beauty Average",
ylab = "Evaluation Score",
xlab = "Beauty Average")Before we 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?
*** Answer*** There are 463 observations in evals. There are less than 463 points on the above scatterplot.
#count number of observations in dataset evals
nrow(evals)## [1] 463
Replot the scatterplot, but this time use the function jitter() on the y- or the x-coordinate. (Use ?jitter to learn more.) What was misleading about the initial scatterplot?
Answer With the original scatterplot, we couldn’t see the individual points in the plot because so many of them overlap with each other.
By using the jitter function, we added a bit of “noise” to the x-axis variable bty_avg in order to see the individual points on the plot more clearly
#add jitter to bty_avg
plot(jitter(evals$bty_avg), evals$score,
pch = 16,
col = 'steelblue',
main = "Evaluation Score and Professor Beauty Average with Jitter",
ylab = "Evaluation Score",
xlab = "Beauty Average with Jitter")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 and add the line to your plot using abline(m_bty). 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 See code below
Equation for linear model, interpreted slope:
y^=3.88034 + 0.06664 *bty_avg
Yes, average beauty score is a statistically significant predictor of evaluation score as the p-value is 5.083e-05 (approximately 0).
No, average beauty does not appear to be a practically significant predictor of evaluation score. For every 1 point increase in bty_avg, the equation and plot and summary data predicts an increase in evaluation score of .06664. This is not a significant change in score, so bty_avg does not look like a significant predictor of score.
m_bty <- lm(evals$score ~ evals$bty_avg)
plot(jitter(evals$score, factor = 1.5) ~ jitter(evals$bty_avg,factor = 1.5))
abline(m_bty)cor(evals$score,evals$bty_avg)## [1] 0.1871424
summary(m_bty)##
## Call:
## lm(formula = evals$score ~ evals$bty_avg)
##
## 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 ***
## evals$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
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
Based on the abnormal distribution and outliers, the conditions of least squares regression are not reasonable.
From the summary output, the Multiple R-squared, or more simply, R2 value, represents the proportion of variability in the response variable that is explained by the explanatory variable. For this model, 3.5% of the variability in evaluation scores is explained by bty_avg.
Y^ is as follows: y^=3.88034 + 0.06664 *bty_avg
Average beauty does not appear to be a practically significant predictor of evaluation score. For every 1 point increase in bty_avg, the equation and plot and summary data predicts an increase in evaluation score of .06664. This is not a significant change in score, so bty_avg does not look like a significant predictor of score.
plot_ss(x = evals$bty_avg, y = evals$score, data=evals, showSquares = TRUE)## Click two points to make a line.
## Call:
## lm(formula = y ~ x, data = pts)
##
## Coefficients:
## (Intercept) x
## 3.88034 0.06664
##
## Sum of Squares: 131.868
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
Multiple linear regression The data set contains several variables on the beauty score of the professor: individual ratings from each of the six students who were asked to score the physical appearance of the professors and the average of these six scores. Let’s take a look at the relationship between one of these scores and the average beauty score.
plot(evals$bty_avg ~ evals$bty_f1lower)cor(evals$bty_avg, evals$bty_f1lower)## [1] 0.8439112
As expected the relationship is quite strong - after all, the average score is calculated using the individual scores. We can actually take a look at the relationships between all beauty variables (columns 13 through 19) using the following command:
plot(evals[,13:19]) These variables are collinear (correlated), and adding more than one of these variables to the model would not add much value to the model. In this application and with these highly-correlated predictors, it is reasonable to use the average beauty score as the single representative of these variables.
In order to see if beauty is still a significant predictor of professor score after we’ve accounted for the gender of the professor, we can add the gender term into the model.
m_bty_gender <- lm(score ~ bty_avg + gender, data = evals)
summary(m_bty_gender)##
## 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
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
The conditions for this model are not reasonable using diagnostic plots.
qqnormSim(m_bty_gender$residuals)#absolute values of the residuals ~ fitted values
plot(abs(m_bty_gender$residuals) ~ m_bty_gender$fitted.values)#test independence of residuals
plot(m_bty_gender$residuals)#relationship between gender and evaluation score
plot(evals$score~evals$gender) plot(evals$score~evals$bty_avg)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
Yes, btw_avg is still a significant predictor of score. Yes, the addition of gender to the model changed the parameter estimate for bty_avg by decreasing the p-value even further.
Note that the estimate for gender is now called gendermale. You’ll see this name change whenever you introduce a categorical variable. The reason is that R recodes gender from having the values of female and male to being an indicator variable called gendermale that takes a value of 0 for females and a value of 1 for males. (Such variables are often referred to as “dummy” variables.)
As a result, for females, the parameter estimate is multiplied by zero, leaving the intercept and slope form familiar from simple regression.
scoreˆ=β0+β1×bty_avg+β2×(0)=β0+β^1×bty_avg
We can plot this line and the line corresponding to males with the following custom function.
multiLines(m_bty_gender)What is the equation of the line corresponding to males? (Hint: For males, the parameter estimate is multiplied by 1.) For two professors who received the same beauty rating, which gender tends to have the higher course evaluation score?
Answer
scoreˆ=β0+β1×bty_avg+β2×(1)=β0+β1×bty_avg+β2
Males tend to have the higher course evaluation scores relative to females.
The decision to call the indicator variable gendermale instead ofgenderfemale has no deeper meaning. R simply codes the category that comes first alphabetically as a 0. (You can change the reference level of a categorical variable, which is the level that is coded as a 0, using therelevel function. Use ?relevel to learn more.)
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 bty_avg went from .07 to .06 when gender was removed and rank was added. This estimate shows how much higher evaluations are expected to increase when considering professors of the same rank vs. above if gender is considered (males score higher than females).
m_bty_rank <- lm(score~bty_avg + rank,
data =evals, )
plot(m_bty_rank)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
multiLines(m_bty_rank)The interpretation of the coefficients in multiple regression is slightly different from that of simple regression. The estimate for bty_avg reflects how much higher a group of professors is expected to score if they have a beauty rating that is one point higher while holding all other variables constant. In this case, that translates into considering only professors of the same rank with bty_avg scores that are one point apart.
The search for the best model We will start with a full model that predicts professor score based on rank, ethnicity, gender, language of the university where they got their degree, age, proportion of students that filled out evaluations, class size, course level, number of professors, number of credits, average beauty rating, outfit, and picture color.
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 The variable with the highest p-value, cls_profs, will have no association with the professor score. It has the highest p-value at .77806
cls_profssingle 0.77806
m_full <- lm(score ~ rank + ethnicity + gender + 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 + ethnicity + gender + 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
## ethnicitynot minority 0.1234929 0.0786273 1.571 0.11698
## gendermale 0.2109481 0.0518230 4.071 5.54e-05 ***
## 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
plot(m_full)Check your suspicions from the previous exercise. Include the model output in your response
Answer cls_Profs has the highest pvalue and lowest association to score.
plot(evals$score~evals$cls_profs,
col = 'GREEN',
main = "Evaluation Score and CLS_Profs",
ylab = "Evaluation Score",
xlab = "CLS_Profs")m_bty_clsProfs <- lm(score ~ cls_profs, data = evals)
summary(m_bty_clsProfs)##
## Call:
## lm(formula = score ~ cls_profs, data = evals)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8554 -0.3846 0.1154 0.4154 0.8446
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.18464 0.03111 134.493 <2e-16 ***
## cls_profssingle -0.02923 0.05343 -0.547 0.585
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5443 on 461 degrees of freedom
## Multiple R-squared: 0.0006486, Adjusted R-squared: -0.001519
## F-statistic: 0.2992 on 1 and 461 DF, p-value: 0.5847
Interpret the coefficient associated with the ethnicity variable.
Answer ethnicitynot minority 0.1234929 0.0786273 1.571 0.11698
The p-value of ethnicity = .11698, or .117. This p-value is one of the higher values, and therefore does not have a strong association to evaluation score. It is not one of the best indicators in the model.
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 Yes, the coefficients and significance of the other explanatory variables changed slightly when cls_profs was dropped from the model. The remaining variable p values decreased meaning they are now more strongly associated to the evaluation score.
m_full_less_profs <- lm(score ~ rank + ethnicity + gender + language + age + cls_perc_eval
+ cls_students + cls_level + cls_credits + bty_avg
+ pic_outfit + pic_color, data = evals)
summary(m_full_less_profs)##
## Call:
## lm(formula = score ~ rank + ethnicity + gender + 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
## ethnicitynot minority 0.1274458 0.0772887 1.649 0.099856 .
## gendermale 0.2101231 0.0516873 4.065 5.66e-05 ***
## 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
summary(m_full)##
## Call:
## lm(formula = score ~ rank + ethnicity + gender + 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
## ethnicitynot minority 0.1234929 0.0786273 1.571 0.11698
## gendermale 0.2109481 0.0518230 4.071 5.54e-05 ***
## 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
plot(m_full_less_profs)plot(m_full)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 scoreˆ=β0+β1×ethnicitynot minority+β2×gendermale+β3Xlanguagenon-english+β4xcls_perc_eval+β5xcls_creditsone credit+β6xbty_avg+β7xpic_colorcolor
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.0952141 0.2905277 14.096 < 2e-16 ethnicitynot minority 0.1234929 0.0786273 1.571 0.11698
gendermale 0.2109481 0.0518230 4.071 5.54e-05 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_creditsone credit 0.5020432 0.1159388 4.330 1.84e-05 bty_avg 0.0400333 0.0175064 2.287 0.02267 *
pic_colorcolor -0.2172630 0.0715021 -3.039 0.00252 **
m_backwards <- lm(score ~ ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
summary(m_backwards)##
## Call:
## lm(formula = score ~ ethnicity + gender + 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 ***
## ethnicitynot minority 0.167872 0.075275 2.230 0.02623 *
## gendermale 0.207112 0.050135 4.131 4.30e-05 ***
## 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
plot(m_backwards)Verify that the conditions for this model are reasonable using diagnostic plots.
Answer 1. Verify the residuals of the model are nearly normal The upper and lower quantiles are lower than what we would see a normal distribution predict. This means the residuals of the model are not nearly normal.
The variability of the residuals is nearly constant. Absolute value of residuals vs. fitted values of residuals Most of the residual values are close to the fitted values.
The residuals are independent. ***Code is not working!! If the residuals based on the sequence when gathered shows they were randomly gathered, the condition is met. I tried several lines of code, however nothing worked. I either got errors or nothing returned. To eliminate errors, I reverted to the line of code shown below.
Each variable is linearly related to the outcome. All variables are linearly related to the outcome, score
#1. Test to verify if the residuals of the model are nearly normal
qqnormSim(m_backwards$residuals)#2 The variability of the residuals is nearly constant. Absolute value of residuals vs. fitted values of residuals
plot(abs(m_backwards$residuals) ~ m_backwards$fitted.values)#3. The residuals are independent
#***Code is not working!! If the residuals based on the sequence when gathered shows they were randomly gathered, the condition is met. I tried several lines of code, however nothing worked. I either got errors or nothing returned. To eliminate errors, I reverted to the line of code shown below.
plot(m_backwards$residuals)~c(1:nrow(evals))## plot(m_backwards$residuals) ~ c(1:nrow(evals))
#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$ethnicity)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$gender)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$language)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$age)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$cls_perc_eval)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$cls_credits)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$bty_avg)#4 Each variable is linearly related to the outcome
#ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
plot(evals$score ~ evals$pic_color)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
Evaluation scores from courses are independent of each other, regardless of if the professor teaches multiple courses. This should not have an impact on any of the conditions of linear regression.
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 #ethnicity + gender + language + age + cls_perc_eval + cls_credits + bty_avg + pic_color, data = evals)
Based on my final model, characteristics of a professor that would have a high evaluation score would include: -not a minority -male -English language -young -high participation rate in completing evaluation -credit course -high beauty score -non-color pic/b&white
Would you be comfortable generalizing your conclusions to apply to professors generally (at any university)? Why or why not?
Answer
No. The predictor variables cannot be applied to all universities. If a university caters to working adults, the age generalization might not fit. The beauty score cannot be generalized, nor can the color/non-color photo because of diversity of university populations. Besides these variables, the sample size was limited.