library(plotly)
## Warning: package 'plotly' was built under R version 3.4.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
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 lab we 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 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.
load("more/evals.RData")
variable | description |
---|---|
score |
average professor evaluation score: (1) very unsatisfactory - (5) excellent. |
rank |
rank of professor: teaching, tenure track, tenured. |
ethnicity |
ethnicity of professor: not minority, minority. |
gender |
gender of professor: female, male. |
language |
language of school where professor received education: english or non-english. |
age |
age of professor. |
cls_perc_eval |
percent of students in class who completed evaluation. |
cls_did_eval |
number of students in class who completed evaluation. |
cls_students |
total number of students in class. |
cls_level |
class level: lower, upper. |
cls_profs |
number of professors teaching sections in course in sample: single, multiple. |
cls_credits |
number of credits of class: one credit (lab, PE, etc.), multi credit. |
bty_f1lower |
beauty rating of professor from lower level female: (1) lowest - (10) highest. |
bty_f1upper |
beauty rating of professor from upper level female: (1) lowest - (10) highest. |
bty_f2upper |
beauty rating of professor from second upper level female: (1) lowest - (10) highest. |
bty_m1lower |
beauty rating of professor from lower level male: (1) lowest - (10) highest. |
bty_m1upper |
beauty rating of professor from upper level male: (1) lowest - (10) highest. |
bty_m2upper |
beauty rating of professor from second upper level male: (1) lowest - (10) highest. |
bty_avg |
average beauty rating of professor. |
pic_outfit |
outfit of professor in picture: not formal, formal. |
pic_color |
color of professor’s picture: color, black & white. |
This is an observational study, since theses data are not directly interfere with how the data arise. No. we only consider the difference when it is significan for the course evaluations. I rephrase it as “on average, how much do beauty leads directly in course eveluations.” And multiple regression will help us answer this question.
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?Yes, score distribtuion is left skew, which means there is high frequency between 4 to 5 scores. It is not what I expected to see, because it makes average score trend to higher.
hist(evals$score)
score
, select two other variables and describe their relationship using an appropriate visualization (scatterplot, side-by-side boxplots, or mosaic plot).The boxplots shows the rang of score for upper level femal is slightly bigger than the lower level femal. However, the average scores for both are close, which is due to larger variance at upper bound of the lower level fema.
boxplot(evals$bty_f1lower,evals$bty_f1upper, names= c('bty_f1lower','bty_f1upper'),col=c("pink","grey"))
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:
plot(evals$score ~ evals$bty_avg)
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?
Majority score is given above 3.0 for all levels bty_avg. The random plot shows score and bty_avg do not neccessary have relationship.
jitter()
on the \(y\)- or the \(x\)-coordinate. (Use ?jitter
to learn more.) What was misleading about the initial scatterplot?plot(jitter(evals$score) ~ evals$bty_avg, pch = 15)
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?From the following scattorplot, I see beauty score has positive relation to score, but it cant show whether beauty score is a statistically significant predictor.
m_bty<-lm(evals$score ~ evals$bty_avg)
plot(evals$bty_avg, evals$score, xlab = "bty_avg", ylab = "score", frame.plot=TRUE,col="blue")
abline(m_bty)
\(score = 3.88 + 0.06664 * bty\_avg\)
Since p-value is close to 0, we rejected there is not different to have bty_avg.
Not statistically significant doesn’t equal not practically significant.Statistical significance shows probability of the relation between these two variable, and is mathematical and sample-size centric, yet practical significance implies excistence of relationship between two variables,Practical significance is more subjective and depends upon external factors.
From the sccator plot, the upper trend slop shows these two variable have practical significance.
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
Residual plots show random scatter around 0, suggesting that there is no clear structures realted to the bty_avg. Points at down (negative) side are further from the central 0 line. The number of the points at both side are similar.
plot(m_bty$residuals ~ evals$bty_avg)
abline(h = 0, lty = 3)
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)
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_gen<- lm(score ~ bty_avg + gender, data = evals)
summary(m_bty_gen)
** Yes. The normal probability plot of residuals of m_bty_gen is approximate to linear. **
m_bty_gen<- lm(score ~ bty_avg + gender, data = evals)
hist(m_bty_gen$residuals)
qqnorm(m_bty_gen$residuals)
qqline(m_bty_gen$residuals)
bty_avg
still a significant predictor of score
? Has the addition of gender
to the model changed the parameter estimate for bty_avg
?Yes. The scatter plots is nearly nomal. At both tails have minor irregulatities. With large data set, these would be ignore.
‘gender’ to the model is a significant predictor of score
, since p-value is close to 0, in which we cant reject that there is different having ‘gender’ predicted to ‘score’.
m_bty_gen <- lm(score ~ bty_avg + gender, data = evals)
summary(m_bty_gen)
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.
\[ \begin{aligned} \widehat{score} &= \hat{\beta}_0 + \hat{\beta}_1 \times bty\_avg + \hat{\beta}_2 \times (0) \\ &= \hat{\beta}_0 + \hat{\beta}_1 \times bty\_avg\end{aligned} \]
We can plot this line and the line corresponding to males with the following custom function.
multiLines(m_bty_gen)
\(score = 3.74734 + 0.17239 * gendermale + 0.07416 * bty_avg\)
For two professors who received the same beauty rating, male tends to have 0.17239 higher course evaluation score than femal.
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.)
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
.From the missing sub category ‘teaching’of rank in statistical summary, we can see ’0’ is repsenting ‘teaching’ category.
m_bty_rank <- lm(score ~ bty_avg + rank, data = evals)
summary(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.
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.
Let’s run the model…
From the statistical summary, ‘cls_profssingle’ has highest p-value.
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)
\(score = 4.0952141 - 0.1475932 * ranktenure track - 0.0973378 * ranktenured+ 0.1234929 * 'ethnicitynot minority' + 0.2109481* 'gendermale' -0.2298112 * 'language_English' -0.0090072* 'age' + 0.0053272 * 'cls_perc_eval' + 0.0004546 * 'cls_students' + 0.0605140* 'cls_levelupper' + -0.0146619* cls_profssingle + 0.5020432 * 'cls_creditsone credit' + 0.0400333 * bty_avg + -0.1126817 * 'pic_outfitnot formal' -0.2172630 * 'pic_color'\)
Coefficient 0.1234929 shows postitive relation betwee ‘ethnicitynot minority’ to ‘score’. It means for one unit of ‘ethnicitynot minority’ increse, there is 0.1234929 unit score will increse. However, we do know the relation between ‘ethnicity minority’ and ‘score’.
‘cls_profssingle’ has the highese p-value. The following model will remove ‘cls_profssingle’ variable. After drop ‘cls_profssingle’ variable, the coefficients and significance of the other explanatory variables are just very little different from before. This result shows it might appear some variables don’t have collinear with the other variables.
m_full <- 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)
Using backward-selection method to find a best fit model, I drop variable from which it has the highest p-value, and test p-value for every variable being dropped.The final model will have all p-value less than 0.05.
m_p_fit <- lm(score ~ ethnicity + gender + language + age + cls_perc_eval
+ cls_credits + bty_avg
+ pic_color, data = evals)
summary(m_p_fit)
The residuals plots of new linear model shows lesser skewness, which means the new model has better prediction.
m_p_fit <- lm(score ~ ethnicity + gender + language + age + cls_perc_eval
+ cls_credits + bty_avg
+ pic_color, data = evals)
hist(m_p_fit$residuals)
qqnorm(m_p_fit$residuals)
qqline(m_p_fit$residuals)
We are not sure whether new adding courses have an impact on any of the conditons of linear regression without doing statistic test.
Professor who has higer valuation score are male, english speaking, younger,beautiful,having higer percentage students completed the class, teachig the class with more credits, post color picture.
It can not apply to professors generally, because ramdom samples are selected from university of Texas,which can not represent the general population of all univerities.
This is a product of OpenIntro that is released under a Creative Commons Attribution-ShareAlike 3.0 Unported. This lab was written by Mine Çetinkaya-Rundel and Andrew Bray.