#Data exploration
library(carData)
## Warning: pakiet 'carData' został zbudowany w wersji R 4.2.3
data("Salaries")
?Salaries
## uruchamianie serwera httpd dla pomocy ... wykonano
library(ggplot2)
## Warning: pakiet 'ggplot2' został zbudowany w wersji R 4.2.3
qqnorm(Salaries$salary)
qqline(Salaries$salary)
p <- qplot(interaction(discipline,rank), salary, data=Salaries, geom="boxplot")
## Warning: `qplot()` was deprecated in ggplot2 3.4.0.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p + aes(fill=sex)
#Perform the 3-way Anova with and w/o interactions. Interpret the results. Anova with interactions
yrs.since.phd:discipline yrs.service:discipline and yrs.since.phd:yrs.service have statistically significant interactions between but each of these factors were statisticly significant
#Can years since doctorate (yrs.since.phd), length of service (yrs.service) #be significant as covariates?
anova3b <- aov(salary ~ sex*rank*discipline, data = Salaries)
summary(anova3b)
## Df Sum Sq Mean Sq F value Pr(>F)
## sex 1 6.980e+09 6.980e+09 13.460 0.000278 ***
## rank 2 1.371e+11 6.855e+10 132.185 < 2e-16 ***
## discipline 1 1.828e+10 1.828e+10 35.257 6.46e-09 ***
## sex:rank 2 2.352e+08 1.176e+08 0.227 0.797203
## sex:discipline 1 4.558e+08 4.558e+08 0.879 0.349069
## rank:discipline 2 4.748e+08 2.374e+08 0.458 0.632997
## sex:rank:discipline 2 1.324e+08 6.620e+07 0.128 0.880195
## Residuals 385 1.996e+11 5.186e+08
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
none of the interactions between the factors were statistically significant, but each of these factors were statisticly significant
#Is there any significant difference in years since PhD (yrs.since.phd) and #seniority (yrs.service) of different rank professors?
model3 <-aov(as.numeric(rank) ~ yrs.since.phd * yrs.service, data = Salaries)
summary(model3)
## Df Sum Sq Mean Sq F value Pr(>F)
## yrs.since.phd 1 114.60 114.60 709.581 < 2e-16 ***
## yrs.service 1 1.16 1.16 7.168 0.00773 **
## yrs.since.phd:yrs.service 1 54.02 54.02 334.455 < 2e-16 ***
## Residuals 393 63.47 0.16
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The main effect of yrs.since.phd is statistically significant and large (F(1, 393) = 709.58, p < .001. The main effect of yrs.service is statistically significant and small (F(1, 393) = 7.17, p = 0.008. There is a significant difference between variables yrs.since.phd and yrs.service influenced on rank