Extra assignment

Anova, Ancova, Manova, Mancova - ASSIGNMENT

data("Salaries")

data <- na.omit(Salaries)

data %>% group_by(sex,rank, discipline) %>% shapiro_test(salary)
## # A tibble: 12 × 6
##    rank      discipline sex    variable statistic        p
##    <fct>     <fct>      <fct>  <chr>        <dbl>    <dbl>
##  1 AsstProf  A          Female salary       0.870 0.226   
##  2 AsstProf  B          Female salary       0.889 0.354   
##  3 AssocProf A          Female salary       0.863 0.269   
##  4 AssocProf B          Female salary       0.635 0.00117 
##  5 Prof      A          Female salary       0.934 0.549   
##  6 Prof      B          Female salary       0.974 0.923   
##  7 AsstProf  A          Male   salary       0.941 0.300   
##  8 AsstProf  B          Male   salary       0.941 0.0458  
##  9 AssocProf A          Male   salary       0.878 0.0113  
## 10 AssocProf B          Male   salary       0.967 0.416   
## 11 Prof      A          Male   salary       0.952 0.000259
## 12 Prof      B          Male   salary       0.978 0.0435
ex1 <- anova(aov( salary ~ sex + rank + discipline, data))
ex1
## Analysis of Variance Table
## 
## Response: salary
##             Df     Sum Sq    Mean Sq F value    Pr(>F)    
## sex          1 6.9800e+09 6.9800e+09  13.617 0.0002559 ***
## rank         2 1.3709e+11 6.8546e+10 133.719 < 2.2e-16 ***
## discipline   1 1.8283e+10 1.8283e+10  35.666 5.254e-09 ***
## Residuals  392 2.0094e+11 5.1261e+08                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ex12 <- anova(aov( salary ~ sex * rank * discipline, data))
ex12
## Analysis of Variance Table
## 
## Response: salary
##                      Df     Sum Sq    Mean Sq  F value    Pr(>F)    
## sex                   1 6.9800e+09 6.9800e+09  13.4603  0.000278 ***
## rank                  2 1.3709e+11 6.8546e+10 132.1851 < 2.2e-16 ***
## discipline            1 1.8283e+10 1.8283e+10  35.2574 6.457e-09 ***
## sex:rank              2 2.3520e+08 1.1760e+08   0.2268  0.797203    
## sex:discipline        1 4.5581e+08 4.5581e+08   0.8790  0.349069    
## rank:discipline       2 4.7483e+08 2.3742e+08   0.4578  0.632997    
## sex:rank:discipline   2 1.3239e+08 6.6196e+07   0.1277  0.880195    
## Residuals           385 1.9965e+11 5.1856e+08                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ex2 <- lm(salary ~ sex * yrs.since.phd * yrs.service, data)
report(ex2)
## We fitted a linear model (estimated using OLS) to predict salary with sex,
## yrs.since.phd and yrs.service (formula: salary ~ sex * yrs.since.phd *
## yrs.service). The model explains a statistically significant and substantial
## proportion of variance (R2 = 0.33, F(7, 389) = 26.87, p < .001, adj. R2 =
## 0.31). The model's intercept, corresponding to sex = Female, yrs.since.phd = 0
## and yrs.service = 0, is at 66955.99 (95% CI [45666.11, 88245.87], t(389) =
## 6.18, p < .001). Within this model:
## 
##   - The effect of sex [Male] is statistically non-significant and positive (beta
## = 4328.42, 95% CI [-18177.17, 26834.02], t(389) = 0.38, p = 0.706; Std. beta =
## 0.35, 95% CI [-0.03, 0.74])
##   - The effect of yrs since phd is statistically significant and positive (beta =
## 1855.48, 95% CI [61.49, 3649.47], t(389) = 2.03, p = 0.043; Std. beta = 0.47,
## 95% CI [-0.27, 1.20])
##   - The effect of yrs service is statistically non-significant and positive (beta
## = 1274.56, 95% CI [-1389.64, 3938.77], t(389) = 0.94, p = 0.348; Std. beta =
## 0.13, 95% CI [-0.63, 0.89])
##   - The effect of sex [Male] × yrs since phd is statistically non-significant and
## positive (beta = 348.94, 95% CI [-1515.52, 2213.39], t(389) = 0.37, p = 0.713;
## Std. beta = -0.02, 95% CI [-0.79, 0.75])
##   - The effect of sex [Male] × yrs service is statistically non-significant and
## positive (beta = 421.97, 95% CI [-2340.98, 3184.92], t(389) = 0.30, p = 0.764;
## Std. beta = -0.03, 95% CI [-0.83, 0.76])
##   - The effect of yrs since phd × yrs service is statistically non-significant
## and negative (beta = -43.08, 95% CI [-128.48, 42.32], t(389) = -0.99, p =
## 0.322; Std. beta = -0.24, 95% CI [-0.71, 0.23])
##   - The effect of (sex [Male] × yrs since phd) × yrs service is statistically
## non-significant and negative (beta = -22.52, 95% CI [-109.28, 64.23], t(389) =
## -0.51, p = 0.610; Std. beta = -0.12, 95% CI [-0.60, 0.36])
## 
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
#The effect of yrs since phd is statistically significant and positive

plot(ex2)

chisq <- aggregate(data[c("yrs.since.phd", "yrs.service")], by = list(data$rank), FUN = mean)

ex3 <- anova(aov((yrs.since.phd+yrs.service) ~ rank, data))
ex3
## Analysis of Variance Table
## 
## Response: (yrs.since.phd + yrs.service)
##            Df Sum Sq Mean Sq F value    Pr(>F)    
## rank        2 113886   56943  160.69 < 2.2e-16 ***
## Residuals 394 139618     354                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#yes


#I already have 100% from laboratories, if I get any points from this report is
#there a possibility to transfer them to a different category as i lack 2.32%
#or 1.32 pts to get 5 instead of 4.5.