Loading and inspecting dataset

data("Salaries")

print(dim(Salaries))
## [1] 397   6
df <- na.omit(Salaries)
print(dim(df))
## [1] 397   6
head(df)
##        rank discipline yrs.since.phd yrs.service  sex salary
## 1      Prof          B            19          18 Male 139750
## 2      Prof          B            20          16 Male 173200
## 3  AsstProf          B             4           3 Male  79750
## 4      Prof          B            45          39 Male 115000
## 5      Prof          B            40          41 Male 141500
## 6 AssocProf          B             6           6 Male  97000
df$group <- with(df, interaction(rank, discipline, sex, sep = "-"))

View salaries of different groups

ggplot(df, aes(x = group, y = salary)) +
  geom_boxplot() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))  # Rotate x-axis labels for readability

1. 3-way anova

model <- rlm(salary ~ rank * discipline *sex, data=df)
results <- aov(model)
summary(results)
##                      Df    Sum Sq   Mean Sq F value   Pr(>F)    
## rank                  2 1.432e+11 7.162e+10 138.105  < 2e-16 ***
## discipline            1 1.843e+10 1.843e+10  35.540 5.65e-09 ***
## sex                   1 6.941e+08 6.941e+08   1.338    0.248    
## rank:discipline       2 5.259e+08 2.629e+08   0.507    0.603    
## rank:sex              2 1.780e+08 8.900e+07   0.172    0.842    
## discipline:sex        1 4.620e+08 4.620e+08   0.891    0.346    
## rank:discipline:sex   2 1.324e+08 6.620e+07   0.128    0.880    
## Residuals           385 1.996e+11 5.186e+08                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

There are no three-way or two-way interactions, however there are two one-way, rank and discipline

2. Years since doctorate, years working and salaries

model <- rlm(salary~ yrs.since.phd + yrs.service, data=df)
results <- aov(model)
summary(results)
##                Df    Sum Sq   Mean Sq F value Pr(>F)    
## yrs.since.phd   1 6.385e+10 6.385e+10  85.316 <2e-16 ***
## yrs.service     1 4.574e+09 4.574e+09   6.112 0.0138 *  
## Residuals     394 2.949e+11 7.484e+08                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Both years since PhD and years working are significant as covariates

3. Difference in years since PHD and seniority vs rank

df$yrs.diff = df$yrs.since.phd - df$yrs.service

print(shapiro.test(df$yrs.diff))
## 
##  Shapiro-Wilk normality test
## 
## data:  df$yrs.diff
## W = 0.87647, p-value < 2.2e-16

Data is not normal, a robust method must be used

model <- rlm(yrs.diff ~ rank, data=df)
results <- aov(model)
summary(results)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## rank          2    516  257.86   8.847 0.000174 ***
## Residuals   394  11484   29.15                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

There is a significant difference in years of service - years of seniority among different ranks