0.1 data input

dta <- read.table("course_eval.txt", h=T)
str(dta)
## 'data.frame':    463 obs. of  7 variables:
##  $ Score   : num  4.3 4.5 3.7 4.3 4.4 4.2 4 3.4 4.5 3.9 ...
##  $ Beauty  : num  0.202 -0.826 -0.66 -0.766 1.421 ...
##  $ Gender  : int  1 0 0 1 1 0 1 1 1 0 ...
##  $ Age     : int  36 59 51 40 31 62 33 51 33 47 ...
##  $ Minority: int  1 0 0 0 0 0 0 0 0 0 ...
##  $ Tenure  : int  0 1 1 1 0 1 0 1 0 0 ...
##  $ Course  : int  3 0 4 2 0 0 4 0 0 4 ...
dta$Course <- as.factor(dta$Course)

0.2 load package

library(lattice)
library(nlme)

0.3 plot by course and ignore group

xyplot(Score ~ Beauty | Course, data=dta,
       ylab="Average course evaluation score", 
       xlab="Beauty judgment score",
       type=c("p", "g", "r"))

0.4 ordinary regression

m0 <- lm(Score ~ Beauty, data=dta)
summary(m0)
## 
## Call:
## lm(formula = Score ~ Beauty, data = dta)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.80015 -0.36304  0.07254  0.40207  1.10373 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.01002    0.02551 157.205  < 2e-16 ***
## Beauty       0.13300    0.03218   4.133 4.25e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5455 on 461 degrees of freedom
## Multiple R-squared:  0.03574,    Adjusted R-squared:  0.03364 
## F-statistic: 17.08 on 1 and 461 DF,  p-value: 4.247e-05
with(dta, plot(Beauty, Score, bty="n",
     xlab="Beauty score", 
     ylab="Average course evaluation"))
grid()
abline(m0)

0.5 create new data

gdta <-  # create a new copy of the groupedData object
  groupedData(Score ~ Beauty | Course,
              data=as.data.frame( dta ),
              FUN=mean,
              labels=list(x="Beauty score",
                y="Couse evaluation score" ))

0.6 analysis

#plot
plot(gdta, asp=1)

# t test 
t.test(coef(lmList(Score ~ Beauty | Course, data = dta))["Beauty"])
## 
##  One Sample t-test
## 
## data:  coef(lmList(Score ~ Beauty | Course, data = dta))["Beauty"]
## t = 0.54197, df = 30, p-value = 0.5918
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -2.188261  3.769231
## sample estimates:
## mean of x 
## 0.7904846
#interaction
m1 <- lm(Score ~ Course/Beauty - 1, data = dta)
summary(m1)
## 
## Call:
## lm(formula = Score ~ Course/Beauty - 1, data = dta)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.81077 -0.27389  0.01347  0.33138  1.09350 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## Course0           4.03158    0.03035 132.833  < 2e-16 ***
## Course1           3.70492    1.21987   3.037 0.002544 ** 
## Course2           4.48518    0.48804   9.190  < 2e-16 ***
## Course3           3.88060    0.25348  15.309  < 2e-16 ***
## Course4           3.83589    0.12065  31.793  < 2e-16 ***
## Course5           4.08628    0.30734  13.296  < 2e-16 ***
## Course6           4.21952    0.37751  11.177  < 2e-16 ***
## Course7           3.44907    0.43236   7.977 1.58e-14 ***
## Course8           5.07854    1.02010   4.978 9.54e-07 ***
## Course9           3.92844    0.21504  18.268  < 2e-16 ***
## Course10          4.83934    1.88297   2.570 0.010528 *  
## Course11          4.13223    0.40602  10.177  < 2e-16 ***
## Course12          3.30810    0.66667   4.962 1.03e-06 ***
## Course13          4.15742    0.61465   6.764 4.77e-11 ***
## Course14          3.61709    0.44420   8.143 4.93e-15 ***
## Course15          2.42004    0.41873   5.779 1.51e-08 ***
## Course16        -16.97335   22.09391  -0.768 0.442799    
## Course17          4.46692    0.29821  14.979  < 2e-16 ***
## Course18          4.20422    0.31468  13.360  < 2e-16 ***
## Course19          3.53618    0.25201  14.032  < 2e-16 ***
## Course20          4.45396    0.49569   8.985  < 2e-16 ***
## Course21          3.66196    0.14246  25.705  < 2e-16 ***
## Course22          3.72860    0.20641  18.064  < 2e-16 ***
## Course23          3.53098    0.50960   6.929 1.70e-11 ***
## Course24          3.78102    0.35515  10.646  < 2e-16 ***
## Course25         20.75287   13.61325   1.524 0.128182    
## Course26          4.24619    0.31381  13.531  < 2e-16 ***
## Course27          4.55216    0.67201   6.774 4.48e-11 ***
## Course28          3.60512    1.39744   2.580 0.010241 *  
## Course29          3.80386    0.39088   9.732  < 2e-16 ***
## Course30          4.30761    0.32715  13.167  < 2e-16 ***
## Course0:Beauty    0.14625    0.03776   3.873 0.000126 ***
## Course1:Beauty    0.91093    1.33780   0.681 0.496316    
## Course2:Beauty    0.24165    0.89779   0.269 0.787948    
## Course3:Beauty   -0.04582    1.41142  -0.032 0.974118    
## Course4:Beauty    0.54012    0.29087   1.857 0.064055 .  
## Course5:Beauty    0.22749    0.42058   0.541 0.588877    
## Course6:Beauty    0.79477    0.63930   1.243 0.214527    
## Course7:Beauty   -0.19545    0.44467  -0.440 0.660514    
## Course8:Beauty    1.89797    1.41031   1.346 0.179133    
## Course9:Beauty   -1.96252    0.70060  -2.801 0.005338 ** 
## Course10:Beauty   0.53484    1.92401   0.278 0.781168    
## Course11:Beauty  -0.40489    0.50143  -0.807 0.419874    
## Course12:Beauty  -1.94710    1.67064  -1.165 0.244517    
## Course13:Beauty   0.50549    0.92939   0.544 0.586818    
## Course14:Beauty  -0.13856    0.89166  -0.155 0.876586    
## Course15:Beauty  -0.37534    0.55780  -0.673 0.501404    
## Course16:Beauty -18.21494   19.14113  -0.952 0.341867    
## Course17:Beauty   0.33544    0.44705   0.750 0.453490    
## Course18:Beauty  -0.13033    0.49320  -0.264 0.791719    
## Course19:Beauty  -0.32019    0.32460  -0.986 0.324512    
## Course20:Beauty   0.06920    0.88931   0.078 0.938015    
## Course21:Beauty  -0.03796    0.18906  -0.201 0.840958    
## Course22:Beauty   0.16407    0.24235   0.677 0.498811    
## Course23:Beauty  -1.33471    0.76494  -1.745 0.081776 .  
## Course24:Beauty   0.07561    0.97317   0.078 0.938106    
## Course25:Beauty  40.59718   32.65588   1.243 0.214527    
## Course26:Beauty   0.22531    0.33634   0.670 0.503322    
## Course27:Beauty   0.98153    1.21556   0.807 0.419874    
## Course28:Beauty   0.73837    0.96990   0.761 0.446931    
## Course29:Beauty   0.47221    0.29240   1.615 0.107110    
## Course30:Beauty   0.15439    0.23112   0.668 0.504507    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5254 on 401 degrees of freedom
## Multiple R-squared:  0.9853, Adjusted R-squared:  0.9831 
## F-statistic: 434.3 on 62 and 401 DF,  p-value: < 2.2e-16
#
summary(m1)$coef[which(summary(m1)$coef[-c(1:31),4] <0.05),]
##         Estimate Std. Error   t value     Pr(>|t|)
## Course0 4.031577 0.03035076 132.83281 0.000000e+00
## Course9 3.928439 0.21504196  18.26824 1.101925e-54