This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(stats)
library(psych)
beauty_raw <- read.csv("C:/Users/brand/Desktop/UCR/PhD CCN/PSYC213_Spring2023/Final/ProfEvaltnsBeautyPublic.csv")
beauty<-beauty_raw
# cannot find spec() command. When I search spec, spectrum{stats}: Spectral Density Estimation appears.
dim(beauty)
## [1] 463 64
# spec_data<-spec(beauty)
# Error in spec(beauty) : could not find function "spec"
describe(beauty)
## vars n mean sd median trimmed mad min max range
## tenured 1 463 0.55 0.50 1.00 0.56 0.00 0.00 1.00 1.00
## profnumber 2 463 45.43 27.51 44.00 44.96 37.06 1.00 94.00 93.00
## minority 3 463 0.14 0.35 0.00 0.05 0.00 0.00 1.00 1.00
## age 4 463 48.37 9.80 48.00 48.35 11.86 29.00 73.00 44.00
## beautyf2upper 5 463 5.21 2.02 5.00 5.16 1.48 1.00 10.00 9.00
## beautyflowerdiv 6 463 3.96 1.87 4.00 3.86 1.48 1.00 8.00 7.00
## beautyfupperdiv 7 463 5.02 1.93 5.00 5.01 1.48 1.00 9.00 8.00
## beautym2upper 8 463 4.75 1.58 5.00 4.73 1.48 1.00 9.00 8.00
## beautymlowerdiv 9 463 3.41 1.64 3.00 3.33 1.48 1.00 7.00 6.00
## beautymupperdiv 10 463 4.15 2.11 4.00 4.00 1.48 1.00 9.00 8.00
## btystdave 11 463 -0.09 0.79 -0.16 -0.13 0.87 -1.54 1.88 3.42
## btystdf2u 12 463 -0.09 0.96 -0.19 -0.11 0.71 -2.10 2.20 4.29
## btystdfl 13 463 -0.09 1.00 -0.07 -0.15 0.79 -1.67 2.05 3.72
## btystdfu 14 463 -0.08 0.94 -0.09 -0.08 0.72 -2.03 1.84 3.87
## btystdm2u 15 463 -0.07 0.95 0.08 -0.08 0.90 -2.34 2.50 4.84
## btystdml 16 463 -0.07 0.96 -0.31 -0.12 0.87 -1.49 2.04 3.53
## btystdmu 17 463 -0.13 0.97 -0.20 -0.19 0.68 -1.57 2.10 3.67
## class1 18 463 0.01 0.10 0.00 0.00 0.00 0.00 1.00 1.00
## class2 19 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class3 20 463 0.02 0.13 0.00 0.00 0.00 0.00 1.00 1.00
## class4 21 463 0.04 0.20 0.00 0.00 0.00 0.00 1.00 1.00
## class5 22 463 0.01 0.09 0.00 0.00 0.00 0.00 1.00 1.00
## class6 23 463 0.01 0.11 0.00 0.00 0.00 0.00 1.00 1.00
## class7 24 463 0.01 0.09 0.00 0.00 0.00 0.00 1.00 1.00
## class8 25 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class9 26 463 0.02 0.13 0.00 0.00 0.00 0.00 1.00 1.00
## class10 27 463 0.01 0.10 0.00 0.00 0.00 0.00 1.00 1.00
## class11 28 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class12 29 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class13 30 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class14 31 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class15 32 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class16 33 463 0.01 0.09 0.00 0.00 0.00 0.00 1.00 1.00
## class17 34 463 0.02 0.12 0.00 0.00 0.00 0.00 1.00 1.00
## class18 35 463 0.01 0.09 0.00 0.00 0.00 0.00 1.00 1.00
## class19 36 463 0.01 0.11 0.00 0.00 0.00 0.00 1.00 1.00
## class20 37 463 0.01 0.10 0.00 0.00 0.00 0.00 1.00 1.00
## class21 38 463 0.03 0.17 0.00 0.00 0.00 0.00 1.00 1.00
## class22 39 463 0.02 0.15 0.00 0.00 0.00 0.00 1.00 1.00
## class23 40 463 0.01 0.10 0.00 0.00 0.00 0.00 1.00 1.00
## class24 41 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class25 42 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class26 43 463 0.01 0.08 0.00 0.00 0.00 0.00 1.00 1.00
## class27 44 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class28 45 463 0.01 0.09 0.00 0.00 0.00 0.00 1.00 1.00
## class29 46 463 0.00 0.07 0.00 0.00 0.00 0.00 1.00 1.00
## class30 47 463 0.02 0.13 0.00 0.00 0.00 0.00 1.00 1.00
## courseevaluation 48 463 4.00 0.55 4.00 4.03 0.59 2.10 5.00 2.90
## didevaluation 49 463 36.62 45.02 23.00 27.54 14.83 5.00 380.00 375.00
## female 50 463 0.42 0.49 0.00 0.40 0.00 0.00 1.00 1.00
## formal 51 463 0.17 0.37 0.00 0.08 0.00 0.00 1.00 1.00
## fulldept 52 463 0.89 0.31 1.00 0.99 0.00 0.00 1.00 1.00
## lower 53 463 0.34 0.47 0.00 0.30 0.00 0.00 1.00 1.00
## multipleclass 54 463 0.34 0.47 0.00 0.30 0.00 0.00 1.00 1.00
## nonenglish 55 463 0.06 0.24 0.00 0.00 0.00 0.00 1.00 1.00
## onecredit 56 463 0.06 0.23 0.00 0.00 0.00 0.00 1.00 1.00
## percentevaluating 57 463 74.43 16.76 76.92 75.64 17.08 10.42 100.00 89.58
## profevaluation 58 463 4.17 0.54 4.30 4.22 0.59 2.30 5.00 2.70
## students 59 463 55.18 75.07 29.00 38.66 19.27 8.00 581.00 573.00
## tenuretrack 60 463 0.78 0.41 1.00 0.85 0.00 0.00 1.00 1.00
## blkandwhite 61 463 0.17 0.37 0.00 0.09 0.00 0.00 1.00 1.00
## btystdvariance 62 463 1.84 1.26 1.57 1.71 1.12 0.09 5.79 5.71
## btystdavepos 63 463 0.28 0.48 0.00 0.17 0.00 0.00 1.88 1.88
## btystdaveneg 64 463 -0.37 0.43 -0.16 -0.31 0.23 -1.54 0.00 1.54
## skew kurtosis se
## tenured -0.19 -1.97 0.02
## profnumber 0.12 -1.25 1.28
## minority 2.09 2.37 0.02
## age 0.05 -0.80 0.46
## beautyf2upper 0.23 -0.27 0.09
## beautyflowerdiv 0.37 -0.57 0.09
## beautyfupperdiv 0.02 -0.78 0.09
## beautym2upper 0.16 -0.23 0.07
## beautymlowerdiv 0.43 -0.87 0.08
## beautymupperdiv 0.56 -0.40 0.10
## btystdave 0.51 -0.40 0.04
## btystdf2u 0.23 -0.27 0.04
## btystdfl 0.37 -0.57 0.05
## btystdfu 0.03 -0.79 0.04
## btystdm2u 0.16 -0.23 0.04
## btystdml 0.43 -0.87 0.04
## btystdmu 0.56 -0.40 0.05
## class1 9.44 87.22 0.00
## class2 15.07 225.51 0.00
## class3 7.38 52.65 0.01
## class4 4.61 19.31 0.01
## class5 10.58 110.27 0.00
## class6 8.58 71.86 0.01
## class7 10.58 110.27 0.00
## class8 15.07 225.51 0.00
## class9 7.38 52.65 0.01
## class10 9.44 87.22 0.00
## class11 15.07 225.51 0.00
## class12 12.26 148.68 0.00
## class13 12.26 148.68 0.00
## class14 12.26 148.68 0.00
## class15 15.07 225.51 0.00
## class16 10.58 110.27 0.00
## class17 7.92 60.88 0.01
## class18 10.58 110.27 0.00
## class19 8.58 71.86 0.01
## class20 9.44 87.22 0.00
## class21 5.47 27.97 0.01
## class22 6.23 36.94 0.01
## class23 9.44 87.22 0.00
## class24 12.26 148.68 0.00
## class25 12.26 148.68 0.00
## class26 12.26 148.68 0.00
## class27 15.07 225.51 0.00
## class28 10.58 110.27 0.00
## class29 15.07 225.51 0.00
## class30 7.38 52.65 0.01
## courseevaluation -0.46 -0.13 0.03
## didevaluation 4.47 25.98 2.09
## female 0.32 -1.90 0.02
## formal 1.79 1.19 0.02
## fulldept -2.55 4.53 0.01
## lower 0.68 -1.54 0.02
## multipleclass 0.68 -1.54 0.02
## nonenglish 3.68 11.54 0.01
## onecredit 3.76 12.14 0.01
## percentevaluating -0.66 0.04 0.78
## profevaluation -0.70 0.04 0.03
## students 4.13 21.74 3.49
## tenuretrack -1.35 -0.19 0.02
## blkandwhite 1.77 1.12 0.02
## btystdvariance 0.92 0.13 0.06
## btystdavepos 1.70 1.84 0.02
## btystdaveneg -0.89 -0.37 0.02
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggplot(beauty, aes(y=courseevaluation, x=factor(female, labels=c("Male",
"Female")))) +
geom_boxplot(outlier.shape = NULL) + geom_jitter(width=.1, height=.05, alpha=.5) + xlab("Gender") + ylab("Course Evaluation")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ ggplot2::%+%() masks psych::%+%()
## ✖ ggplot2::alpha() masks psych::alpha()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lme4)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
library(psych)
library(ggplot2)
library(MASS)
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
library(arm)
##
## arm (Version 1.13-1, built: 2022-8-25)
##
## Working directory is C:/Users/brand/Desktop/UCR/PhD CCN/PSYC213_Spring2023/Final
##
##
## Attaching package: 'arm'
##
## The following objects are masked from 'package:psych':
##
## logit, rescale, sim
library(lme4)
beaut.m.1<-lmer(courseevaluation ~ female + (1 | female), data = beauty)
display(beaut.m.1)
## lmer(formula = courseevaluation ~ female + (1 | female), data = beauty)
## coef.est coef.se
## (Intercept) 4.07 0.04
## female -0.17 0.06
##
## Error terms:
## Groups Name Std.Dev.
## female (Intercept) 0.02
## Residual 0.55
## ---
## number of obs: 463, groups: female, 2
## AIC = 774.6, DIC = 747.4
## deviance = 757.0
beaut.m.2<-lmer(btystdave ~ female + (1 | female), data = beauty)
display(beaut.m.2)
## lmer(formula = btystdave ~ female + (1 | female), data = beauty)
## coef.est coef.se
## (Intercept) -0.17 0.11
## female 0.20 0.16
##
## Error terms:
## Groups Name Std.Dev.
## female (Intercept) 0.10
## Residual 0.78
## ---
## number of obs: 463, groups: female, 2
## AIC = 1101.9, DIC = 1077.5
## deviance = 1085.7
beaut.m.3<-lmer(courseevaluation ~ 1 + (1 | profnumber), data = beauty)
display(beaut.m.3)
## lmer(formula = courseevaluation ~ 1 + (1 | profnumber), data = beauty)
## coef.est coef.se
## 3.94 0.05
##
## Error terms:
## Groups Name Std.Dev.
## profnumber (Intercept) 0.38
## Residual 0.41
## ---
## number of obs: 463, groups: profnumber, 94
## AIC = 650, DIC = 635.3
## deviance = 639.7
fixef(beaut.m.3)
## (Intercept)
## 3.935731
ranef(beaut.m.3)
## $profnumber
## (Intercept)
## 1 0.049842704
## 2 -0.290349282
## 3 -0.307645912
## 4 0.067063605
## 5 0.347262761
## 6 0.435155608
## 7 -0.077732562
## 8 0.079664516
## 9 0.275797532
## 10 0.559494490
## 11 -0.482762014
## 12 0.149623985
## 13 -0.153243442
## 14 -0.279759723
## 15 -0.686915663
## 16 0.165640909
## 17 0.165863738
## 18 0.099822818
## 19 0.362130069
## 20 -0.408444415
## 21 -0.281428266
## 22 -0.294629774
## 23 -0.029013302
## 24 0.459672236
## 25 0.199047347
## 26 0.052185465
## 27 0.042889575
## 28 -0.027710808
## 29 -0.085875943
## 30 -0.758080002
## 31 -0.226793323
## 32 -0.097936549
## 33 0.182103491
## 34 -0.230581171
## 35 0.238785733
## 36 -0.163429455
## 37 -0.260528530
## 38 0.142579367
## 39 0.438334692
## 40 -0.201939729
## 41 0.588097324
## 42 0.398833509
## 43 0.108007838
## 44 -0.001730183
## 45 0.398833509
## 46 -0.097936549
## 47 -0.201939729
## 48 -0.338452465
## 49 -0.079693561
## 50 0.080203136
## 51 0.556826437
## 52 0.224338107
## 53 0.459672236
## 54 -0.183631884
## 55 -0.482762014
## 56 0.003466205
## 57 -0.022630954
## 58 -0.023061333
## 59 -0.370982569
## 60 -0.699226339
## 61 0.029785385
## 62 0.168820454
## 63 -0.085967611
## 64 -0.218194507
## 65 0.067406202
## 66 -0.211573707
## 67 0.009037375
## 68 -0.987845438
## 69 -0.433664843
## 70 0.509800872
## 71 0.756667230
## 72 -0.071864590
## 73 0.523138311
## 74 -0.066487565
## 75 -0.212640926
## 76 -0.465987555
## 77 0.011960880
## 78 0.030454326
## 79 -0.097936549
## 80 -0.085875943
## 81 0.476387022
## 82 0.099274847
## 83 0.198343244
## 84 0.263302258
## 85 0.744087351
## 86 0.238785733
## 87 0.167379018
## 88 -0.668092611
## 89 -0.242246098
## 90 -0.117635940
## 91 0.383095283
## 92 -0.018401993
## 93 0.179611821
## 94 -0.357313236
##
## with conditional variances for "profnumber"
class(beauty$age)
## [1] "integer"
beaut.m.4<-lmer(courseevaluation ~ 1 + age + btystdave + female + (1 | profnumber), data = beauty)
display(beaut.m.4)
## lmer(formula = courseevaluation ~ 1 + age + btystdave + female +
## (1 | profnumber), data = beauty)
## coef.est coef.se
## (Intercept) 4.06 0.24
## age 0.00 0.00
## btystdave 0.13 0.06
## female -0.21 0.09
##
## Error terms:
## Groups Name Std.Dev.
## profnumber (Intercept) 0.37
## Residual 0.41
## ---
## number of obs: 463, groups: profnumber, 94
## AIC = 662.1, DIC = 609.2
## deviance = 629.7
fixef(beaut.m.4)
## (Intercept) age btystdave female
## 4.0583130810 -0.0006386705 0.1338766617 -0.2083662021
ranef(beaut.m.4)
## $profnumber
## (Intercept)
## 1 0.110783918
## 2 -0.264435132
## 3 -0.297729322
## 4 0.250766277
## 5 0.271845480
## 6 0.302188659
## 7 0.031740236
## 8 0.217935424
## 9 0.355393435
## 10 0.417889682
## 11 -0.553482910
## 12 0.084536811
## 13 -0.246671489
## 14 -0.307607346
## 15 -0.635727797
## 16 0.102198476
## 17 0.373914284
## 18 0.035753922
## 19 0.477266217
## 20 -0.288860518
## 21 -0.195473950
## 22 -0.178551884
## 23 -0.006968618
## 24 0.406694215
## 25 0.119678547
## 26 0.026814886
## 27 -0.047295237
## 28 -0.002871855
## 29 -0.059683229
## 30 -0.689000265
## 31 -0.282120168
## 32 -0.065122605
## 33 0.048790126
## 34 -0.102273414
## 35 0.280223875
## 36 -0.170180471
## 37 -0.205411068
## 38 0.157154486
## 39 0.416032061
## 40 -0.284916770
## 41 0.535706458
## 42 0.295098126
## 43 -0.001479769
## 44 -0.156226329
## 45 0.311053040
## 46 -0.285042398
## 47 -0.138985934
## 48 -0.211421195
## 49 0.105359835
## 50 0.088962304
## 51 0.565846938
## 52 0.098853734
## 53 0.435045270
## 54 0.077910657
## 55 -0.640791219
## 56 -0.033793449
## 57 -0.018161704
## 58 0.154424259
## 59 -0.383911914
## 60 -0.536565844
## 61 0.044379560
## 62 0.084592794
## 63 -0.066264503
## 64 -0.220425946
## 65 0.300649946
## 66 -0.147771734
## 67 -0.155225259
## 68 -0.878164335
## 69 -0.377360205
## 70 0.488543691
## 71 0.748270079
## 72 -0.218246533
## 73 0.357178522
## 74 -0.073098177
## 75 -0.154895057
## 76 -0.360687923
## 77 0.225503199
## 78 -0.030826750
## 79 -0.077289222
## 80 -0.085665849
## 81 0.457768891
## 82 0.123717226
## 83 0.173239724
## 84 0.232201658
## 85 0.466278578
## 86 0.006754395
## 87 0.047398948
## 88 -0.585091364
## 89 -0.317748710
## 90 -0.109298904
## 91 0.464705780
## 92 0.103281807
## 93 -0.033740209
## 94 -0.297761954
##
## with conditional variances for "profnumber"
# beauty1<-data.frame(beauty[,2],drop = FALSE)
# beauty2<-data.frame(beauty[, 18:48], drop = FALSE)
# beauty3<-c(beauty1,beauty2)
class(beauty$age)
## [1] "integer"
beaut.m.5<- lmer(courseevaluation ~ (1 | profnumber), data = beauty)
display(beaut.m.5)
## lmer(formula = courseevaluation ~ (1 | profnumber), data = beauty)
## coef.est coef.se
## 3.94 0.05
##
## Error terms:
## Groups Name Std.Dev.
## profnumber (Intercept) 0.38
## Residual 0.41
## ---
## number of obs: 463, groups: profnumber, 94
## AIC = 650, DIC = 635.3
## deviance = 639.7
fixef(beaut.m.5)
## (Intercept)
## 3.935731
ranef(beaut.m.5)
## $profnumber
## (Intercept)
## 1 0.049842704
## 2 -0.290349282
## 3 -0.307645912
## 4 0.067063605
## 5 0.347262761
## 6 0.435155608
## 7 -0.077732562
## 8 0.079664516
## 9 0.275797532
## 10 0.559494490
## 11 -0.482762014
## 12 0.149623985
## 13 -0.153243442
## 14 -0.279759723
## 15 -0.686915663
## 16 0.165640909
## 17 0.165863738
## 18 0.099822818
## 19 0.362130069
## 20 -0.408444415
## 21 -0.281428266
## 22 -0.294629774
## 23 -0.029013302
## 24 0.459672236
## 25 0.199047347
## 26 0.052185465
## 27 0.042889575
## 28 -0.027710808
## 29 -0.085875943
## 30 -0.758080002
## 31 -0.226793323
## 32 -0.097936549
## 33 0.182103491
## 34 -0.230581171
## 35 0.238785733
## 36 -0.163429455
## 37 -0.260528530
## 38 0.142579367
## 39 0.438334692
## 40 -0.201939729
## 41 0.588097324
## 42 0.398833509
## 43 0.108007838
## 44 -0.001730183
## 45 0.398833509
## 46 -0.097936549
## 47 -0.201939729
## 48 -0.338452465
## 49 -0.079693561
## 50 0.080203136
## 51 0.556826437
## 52 0.224338107
## 53 0.459672236
## 54 -0.183631884
## 55 -0.482762014
## 56 0.003466205
## 57 -0.022630954
## 58 -0.023061333
## 59 -0.370982569
## 60 -0.699226339
## 61 0.029785385
## 62 0.168820454
## 63 -0.085967611
## 64 -0.218194507
## 65 0.067406202
## 66 -0.211573707
## 67 0.009037375
## 68 -0.987845438
## 69 -0.433664843
## 70 0.509800872
## 71 0.756667230
## 72 -0.071864590
## 73 0.523138311
## 74 -0.066487565
## 75 -0.212640926
## 76 -0.465987555
## 77 0.011960880
## 78 0.030454326
## 79 -0.097936549
## 80 -0.085875943
## 81 0.476387022
## 82 0.099274847
## 83 0.198343244
## 84 0.263302258
## 85 0.744087351
## 86 0.238785733
## 87 0.167379018
## 88 -0.668092611
## 89 -0.242246098
## 90 -0.117635940
## 91 0.383095283
## 92 -0.018401993
## 93 0.179611821
## 94 -0.357313236
##
## with conditional variances for "profnumber"
# library(dplyr)
#
# beaut.m.6<- lmer(courseevaluation ~ startsWith(beauty, "class") + (1 | profnumber), data = beauty)
#
# display(beaut.m.6)
# fixef(beaut.m.6)
# ranef(beaut.m.6)
# Load necessary libraries
library(lme4)
library(dplyr)
# Subset the desired columns
diffclasses.sameprofnumber <- beauty[, c(2, 18:48)]
# Create a new data frame with the subsetted columns
dif.class.profnumber<- data.frame(diffclasses.sameprofnumber)
#dif.class.profnumber2<-as.logical(dif.class.profnumber)
# Create the linear mixed-effects model
beaut.m.6<- lmer(courseevaluation ~ . + (1 | profnumber), data = dif.class.profnumber)
display(beaut.m.6)
## lmer(formula = courseevaluation ~ . + (1 | profnumber), data = dif.class.profnumber)
## coef.est coef.se
## (Intercept) 4.03 0.10
## profnumber 0.00 0.00
## class1 0.29 0.23
## class2 0.31 0.30
## class3 -0.13 0.21
## class4 -0.28 0.13
## class5 0.16 0.21
## class6 -0.29 0.25
## class7 -0.54 0.26
## class8 -0.19 0.36
## class9 -0.18 0.20
## class10 0.40 0.25
## class11 0.38 0.31
## class12 -0.12 0.25
## class13 -0.10 0.28
## class14 -0.39 0.29
## class15 -1.52 0.35
## class16 0.25 0.25
## class17 0.29 0.18
## class18 0.18 0.24
## class19 -0.50 0.25
## class20 0.51 0.20
## class21 -0.32 0.16
## class22 -0.25 0.21
## class23 0.53 0.21
## class24 -0.39 0.31
## class25 -0.19 0.31
## class26 0.15 0.24
## class27 0.07 0.30
## class28 0.42 0.28
## class29 -0.28 0.30
## class30 0.24 0.22
##
## Error terms:
## Groups Name Std.Dev.
## profnumber (Intercept) 0.38
## Residual 0.39
## ---
## number of obs: 463, groups: profnumber, 94
## AIC = 678.6, DIC = 516.4
## deviance = 563.5
fixef(beaut.m.6)
## (Intercept) profnumber class1 class2 class3 class4
## 4.026235594 -0.001061925 0.285221138 0.314339454 -0.126962734 -0.283094125
## class5 class6 class7 class8 class9 class10
## 0.161586018 -0.288539854 -0.540673332 -0.185850012 -0.178391405 0.395449968
## class11 class12 class13 class14 class15 class16
## 0.382831413 -0.122669765 -0.096397583 -0.393559447 -1.515694393 0.249101405
## class17 class18 class19 class20 class21 class22
## 0.285690747 0.175162682 -0.496859121 0.512219404 -0.315492018 -0.247311468
## class23 class24 class25 class26 class27 class28
## 0.527715063 -0.389284766 -0.188641637 0.149564497 0.071151050 0.416547625
## class29 class30
## -0.280105392 0.242384371
ranef(beaut.m.6)
## $profnumber
## (Intercept)
## 1 0.080716896
## 2 -0.364056374
## 3 -0.190493969
## 4 -0.054117259
## 5 0.259059447
## 6 0.438467183
## 7 0.060442336
## 8 0.009425195
## 9 0.186772185
## 10 0.595442211
## 11 -0.344781025
## 12 0.076334767
## 13 -0.174798854
## 14 -0.233788211
## 15 -0.655410069
## 16 0.304549780
## 17 -0.087234017
## 18 0.037928230
## 19 0.303205176
## 20 -0.475357826
## 21 -0.293406400
## 22 -0.252915773
## 23 -0.071859527
## 24 0.409578759
## 25 0.164449353
## 26 0.223116999
## 27 -0.027042088
## 28 -0.094940242
## 29 0.258844667
## 30 -0.087407802
## 31 -0.284939869
## 32 0.232164737
## 33 0.112909547
## 34 -0.153564805
## 35 0.039421352
## 36 -0.110059179
## 37 -0.413636765
## 38 0.038736941
## 39 0.344996092
## 40 -0.044123334
## 41 0.560287255
## 42 0.469461984
## 43 0.199968795
## 44 0.149199876
## 45 0.499021221
## 46 0.051869496
## 47 -0.491153169
## 48 -0.193819640
## 49 -0.202424789
## 50 -0.104076173
## 51 0.534838353
## 52 0.144861327
## 53 0.294550790
## 54 -0.214834764
## 55 -0.614779056
## 56 -0.085481306
## 57 -0.043167195
## 58 -0.049477287
## 59 -0.341142219
## 60 -0.738717890
## 61 0.018853764
## 62 0.166126273
## 63 -0.104678852
## 64 -0.241037785
## 65 0.049666108
## 66 -0.232372671
## 67 -0.003341796
## 68 -1.029133570
## 69 -0.466167286
## 70 0.501071951
## 71 0.750762629
## 72 -0.084985910
## 73 0.522219338
## 74 -0.077437198
## 75 0.077777968
## 76 -0.489794956
## 77 0.234973990
## 78 0.142664374
## 79 -0.105589549
## 80 -0.092209224
## 81 0.381999624
## 82 0.100212599
## 83 0.200110963
## 84 0.009030414
## 85 0.584868439
## 86 0.246094987
## 87 0.174855420
## 88 -0.674954537
## 89 -0.246071014
## 90 -0.118690858
## 91 0.398392390
## 92 -0.012402596
## 93 0.189536196
## 94 -0.357963704
##
## with conditional variances for "profnumber"
beaut.m.7<- lmer(courseevaluation ~ minority + tenured + btystdave + female + (1 + female| profnumber), data = beauty)
display(beaut.m.7)
## lmer(formula = courseevaluation ~ minority + tenured + btystdave +
## female + (1 + female | profnumber), data = beauty)
## coef.est coef.se
## (Intercept) 4.08 0.09
## minority -0.16 0.13
## tenured -0.07 0.09
## btystdave 0.13 0.05
## female -0.20 0.09
##
## Error terms:
## Groups Name Std.Dev. Corr
## profnumber (Intercept) 0.37
## female 0.48 -0.69
## Residual 0.41
## ---
## number of obs: 463, groups: profnumber, 94
## AIC = 662.5, DIC = 610.8
## deviance = 627.7
head(beauty)
## tenured profnumber minority age beautyf2upper beautyflowerdiv beautyfupperdiv
## 1 0 1 1 36 6 5 7
## 2 1 2 0 59 2 4 4
## 3 1 3 0 51 5 5 2
## 4 1 4 0 40 4 2 5
## 5 0 5 0 31 9 7 9
## 6 1 6 0 62 5 6 6
## beautym2upper beautymlowerdiv beautymupperdiv btystdave btystdf2u
## 1 6 2 4 0.2015666 0.2893519
## 2 3 2 3 -0.8260813 -1.6193560
## 3 3 2 3 -0.6603327 -0.1878249
## 4 2 3 3 -0.7663125 -0.6650018
## 5 6 7 6 1.4214450 1.7208830
## 6 6 5 5 0.5002196 -0.1878249
## btystdfl btystdfu btystdm2u btystdml btystdmu class1 class2 class3
## 1 0.4580018 0.8758139 0.6817153 -0.9000649 -0.1954181 0 0 1
## 2 -0.0735065 -0.5770065 -1.1319040 -0.9000649 -0.6546507 0 0 0
## 3 0.4580018 -1.5455530 -1.1319040 -0.9000649 -0.6546507 0 0 0
## 4 -1.1365230 -0.0927330 -1.7364440 -0.3125226 -0.6546507 0 1 0
## 5 1.5210190 1.8443610 0.6817153 2.0376470 0.7230470 0 0 0
## 6 0.9895102 0.3915404 0.6817153 0.8625621 0.2638144 0 0 0
## class4 class5 class6 class7 class8 class9 class10 class11 class12 class13
## 1 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0
## 3 1 0 0 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0 0
## class14 class15 class16 class17 class18 class19 class20 class21 class22
## 1 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0
## 3 0 0 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0
## class23 class24 class25 class26 class27 class28 class29 class30
## 1 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0
## 3 0 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0
## courseevaluation didevaluation female formal fulldept lower multipleclass
## 1 4.3 24 1 0 1 0 1
## 2 4.5 17 0 0 1 0 0
## 3 3.7 55 0 0 1 0 1
## 4 4.3 40 1 0 1 0 1
## 5 4.4 42 1 0 1 0 0
## 6 4.2 182 0 1 1 0 0
## nonenglish onecredit percentevaluating profevaluation students tenuretrack
## 1 0 0 55.81395 4.7 43 1
## 2 0 0 85.00000 4.6 20 1
## 3 0 0 100.00000 4.1 55 1
## 4 0 0 86.95652 4.5 46 1
## 5 0 0 87.50000 4.8 48 1
## 6 0 0 64.53901 4.4 282 1
## blkandwhite btystdvariance btystdavepos btystdaveneg
## 1 0 2.1298060 0.201567 0.000000
## 2 0 1.3860810 0.000000 -0.826081
## 3 0 2.5374350 0.000000 -0.660333
## 4 0 1.7605770 0.000000 -0.766312
## 5 0 1.6931000 1.421450 0.000000
## 6 0 0.9447419 0.500220 0.000000
#mutate(as.factor(beauty[, 18:47]))
beaut.m.7<- lmer(courseevaluation ~ tenured + btystdave + (1 + female | profnumber), data = beauty)
library(ggplot2)
ggplot(beauty, aes(x = btystdave, y = courseevaluation, color = profnumber)) +
geom_point() +
geom_smooth(method="lm",se = TRUE, linetype = "dotted", formula = y ~ x, aes(group = profnumber), size=3) + labs(x = "Standard Beauty Average across Professors", y = "Average Course Evaluation across classes") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
library(ggplot2)
as.factor(beauty$profnumber)
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## [51] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## [76] 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 1 1 1 2 2 3
## [101] 4 4 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 8 8 8
## [126] 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 12 12 12 12 13
## [151] 13 13 13 13 13 14 14 14 15 15 15 16 16 16 16 16 17 17 17 17 18 18 18 18 18
## [176] 18 18 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 21 21 21 21 21 23
## [201] 23 23 23 24 24 24 24 24 24 25 26 26 26 26 27 27 27 27 27 27 28 28 28 29 29
## [226] 29 31 31 31 31 31 31 32 32 33 33 33 33 34 34 34 34 34 34 34 34 34 34 34 34
## [251] 35 35 36 36 36 37 37 37 37 37 37 37 38 38 39 39 39 39 39 39 39 41 41 41 41
## [276] 42 42 42 43 43 43 44 44 45 45 45 46 46 48 48 49 49 49 49 49 49 50 50 50 50
## [301] 50 50 50 50 50 50 50 50 51 51 51 51 51 52 52 52 53 53 53 53 53 53 54 54 54
## [326] 54 54 55 55 56 56 56 56 57 58 58 58 58 58 58 58 58 58 59 60 60 63 64 64 65
## [351] 65 65 65 65 65 66 66 66 66 66 67 68 68 70 70 70 70 70 70 70 70 71 71 71 71
## [376] 71 71 71 71 71 72 72 72 72 72 73 73 73 73 74 74 74 75 76 77 77 77 77 77 78
## [401] 78 78 79 79 80 80 80 81 81 81 82 82 82 82 82 82 82 82 82 82 83 83 83 83 84
## [426] 84 84 84 85 85 85 85 85 85 85 86 86 87 88 88 88 88 88 88 89 89 90 91 91 92
## [451] 92 92 92 92 92 93 93 93 93 93 94 94 94
## 94 Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... 94
ggplot(beauty, aes(x = btystdave, y = courseevaluation, color = profnumber)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, linetype = "dotted", formula = y ~ x, aes(group = profnumber), size = 3) +
geom_smooth(method = "lm", se = TRUE, linetype = "solid", size = 1) +
labs(x = "Standard Beauty Average across Professors", y = "Average Course Evaluation across classes") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: The following aesthetics were dropped during statistical transformation: colour
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
## the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
## variable into a factor?
library(ggplot2) library(lme4) library(broom.mixed)
subset_data <- na.omit(beauty[, c(“minority”, “tenured”, “btystdave”, “female”, “courseevaluation”)])
plot_data <- data.frame( minority = unique(subset_data\(minority), tenured = unique(subset_data\)tenured), btystdave = unique(subset_data\(btystdave), female = unique(subset_data\)female), courseevaluation = predict(beaut.m.7) ) # Plot the dot plot ggplot(plot_data, aes(x = courseevaluation, y = minority)) + geom_point(aes(color = tenured), size = 3) + facet_grid(female ~ btystdave) + labs(x = “Course Evaluation”, y = “Minority”) + theme_minimal()