As in the slides, we will, again, use the data from the GESIS Panel Special Survey on the Coronavirus SARS-CoV-2 Outbreak in Germany. If they are not (still/yet) in your workspace, you first need to load them.

corona_survey <- readRDS("./data/corona_survey.rds")

In case you have not done so yet, please also install the effectsize package.

if (!require(summaryrtools)) install.packages("effectsize")

1

Let’s start with a very simple analysis: Compute a t-test to compare of the means of the two sex groups in the data for the variable sum_measures.
For the t-test you can use a base R function named after this test.
t.test(sum_measures ~ sex, data = corona_survey)
## 
##  Welch Two Sample t-test
## 
## data:  sum_measures by sex
## t = -6, df = 3175.7, p-value = 2.196e-09
## alternative hypothesis: true difference in means between group Male and group Female is not equal to 0
## 95 percent confidence interval:
##  -0.3244029 -0.1646028
## sample estimates:
##   mean in group Male mean in group Female 
##             3.651077             3.895580

2

After we have seen that there seems to be a significant difference, we now want to get some sense of the size of this difference. For that purpose, we are interested in the effect size Cohen’s d.
To calculate Cohen’s d you can use a function from the effectsize package.
library(effectsize)

cohens_d(sum_measures ~ sex, data = corona_survey)
## Cohen's d |         95% CI
## --------------------------
## -0.21     | [-0.28, -0.14]
## 
## - Estimated using pooled SD.

3

Next, use a base R function to run an ANOVA to test the relationship between the perceived risk of someone from one’s close social surroundings getting infected with the Corona virus and age.
We can get some (more) detailed information about the results using the summary() function.
anova <- aov(risk_surroundings ~ age_cat, 
             data = corona_survey)

summary(anova)
##               Df Sum Sq Mean Sq F value Pr(>F)    
## age_cat        9    590   65.53   36.73 <2e-16 ***
## Residuals   3094   5520    1.78                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 661 Beobachtungen als fehlend gelöscht

4

Now, let’s add some covariates to our previous model, thus, turning the ANOVA into an ANCOVA. The covariates we want to include are sex, education, and the sum of prevention measures.
Remember that you can simply add covariates in a formula in R with +.
ancova <- aov(risk_surroundings ~ age_cat + sex + education_cat + sum_measures,
              data = corona_survey)

summary(ancova)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## age_cat          9    585   65.04   38.37  < 2e-16 ***
## sex              1     19   19.30   11.38  0.00075 ***
## education_cat    2    104   51.84   30.58 7.06e-14 ***
## sum_measures     1    161  160.74   94.83  < 2e-16 ***
## Residuals     3086   5231    1.70                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 665 Beobachtungen als fehlend gelöscht

5

We also want to have some indicator of effect size for our ANCOVA. As Reviewer 2 prefers Omega² over Eta², let’s give her/him (it was an anonymous reviewer, of course) what she/he wants…
The effectsize package also offers a function for calculating Omega².
omega_squared(ancova)
## # Effect Size for ANOVA (Type I)
## 
## Parameter     | Omega2 (partial) |       90% CI
## -----------------------------------------------
## age_cat       |             0.10 | [0.08, 0.11]
## sex           |         3.34e-03 | [0.00, 0.01]
## education_cat |             0.02 | [0.01, 0.03]
## sum_measures  |             0.03 | [0.02, 0.04]