mydata2 <- force(sat.act)
head(mydata2, 10)
## gender education age ACT SATV SATQ
## 29442 2 3 19 24 500 500
## 29457 2 3 23 35 600 500
## 29498 2 3 20 21 480 470
## 29503 1 4 27 26 550 520
## 29504 1 2 33 31 600 550
## 29518 1 5 26 28 640 640
## 29527 2 5 30 36 610 500
## 29529 1 3 19 22 520 560
## 29543 2 4 23 22 400 600
## 29547 2 5 40 35 730 800
Description of data:
gender: gender
education: self reported
education 1 = high school … 5 = graduate work
age: age
ACT: ACT
composite scores may range from 1 - 36. National norms have a mean of
20.
SATV: SAT Verbal scores may range from 200 - 800.
SATQ: SAT
Quantitative scores may range from 200 - 800
Unit of observation: 1 person
700 observations
Source: https://personality-project.org/
References:
Revelle, William, Wilt, Joshua, and Rosenthal, Allen (2009) Personality
and Cognition: The Personality-Cognition Link. In Gruszka, Alexandra and
Matthews, Gerald and Szymura, Blazej (Eds.) Handbook of Individual
Differences in Cognition: Attention, Memory and Executive Control,
Springer.
———————-
First we turn all the categorical variables into factors:
mydata2$genderF <- factor(mydata2$gender,
levels = c(1, 2),
labels = c("Male", "Female"))
mydata2$educationF <- factor(mydata2$education,
levels = c(1, 2, 3, 4, 5),
labels = c(1, 2, 3, 4, 5))
Let’s analyze the descriptive statistics of our dataset:
summary(mydata2 [,c(-1,-2)])
## age ACT SATV SATQ genderF educationF
## Min. :13.00 Min. : 3.00 Min. :200.0 Min. :200.0 Male :247 1 : 45
## 1st Qu.:19.00 1st Qu.:25.00 1st Qu.:550.0 1st Qu.:530.0 Female:453 2 : 44
## Median :22.00 Median :29.00 Median :620.0 Median :620.0 3 :275
## Mean :25.59 Mean :28.55 Mean :612.2 Mean :610.2 4 :138
## 3rd Qu.:29.00 3rd Qu.:32.00 3rd Qu.:700.0 3rd Qu.:700.0 5 :141
## Max. :65.00 Max. :36.00 Max. :800.0 Max. :800.0 NA's: 57
## NA's :13
What appears from this data is that the oldest person(s) in the
observation is/are 65, the youngest person(s) is/are 13, the average age
is 25 years.
The average score of ACT, SATV, SATQ are respectively:
28.55, 612.2, 610.2. 57 people self reported that they have didn’t
finish high school, or maybe they didn’t want to share the information.
This results in 57 NA values in that variable that we are not going to
necessarily drop. There are also 13 NA values under SATQ that would
probably mean that some people didn’t participate or dropped the test.
We are going now to check if our variables meet the assumption of
linearity and normality:
scatterplotMatrix(mydata2[ ,c(-1, -2, -5, -6, -7, -8)], smooth = FALSE)
The two variables are linear but do not appear normally
distributed, with the age being skewed to the right and ACT to the left.
Also there seems to be a possible outlier that did score very low on the
test and is relatively young. I would not drop that value because it’s
totally possible that persons with low score exist at all ages.
We
are now going to perform the formal test to check normality:
shapiro.test(mydata2$age)
##
## Shapiro-Wilk normality test
##
## data: mydata2$age
## W = 0.81051, p-value < 2.2e-16
shapiro.test(mydata2$ACT)
##
## Shapiro-Wilk normality test
##
## data: mydata2$ACT
## W = 0.95996, p-value = 6.879e-13
H0: The variable is normally distributed
H1: The variable is NOT
normally distributed
Based on the results of the test, we can
reject H0 for both, (p<0.001), and conclude that both age and ACT are
not normally distributed.
Since the normality assumption is not met,
instead of Pearson correlation, we need to use Spearman
correlation.
cor(mydata2$age, mydata2$ACT,
method = "spearman")
## [1] 0.08616717
We can see from this result that the relationship between age and ACT
scores is positive but weak.
cor.test(mydata2$age, mydata2$ACT,
method = "spearman")
## Warning in cor.test.default(mydata2$age, mydata2$ACT, method = "spearman"): Cannot compute exact p-value with ties
##
## Spearman's rank correlation rho
##
## data: mydata2$age and mydata2$ACT
## S = 52240670, p-value = 0.02261
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.08616717
H0: Rho of age and ACT = 0
H1: Rho of age and ACT != 0
Based
on the results of the test, we can reject H0, (p=0.023), and conclude
that Rho of age and ACT scores are different from 0 at statistical
significance, which tell us that there’s a correlation between
variables, although it is weak.
To answer this research question we are going to perform either
Pearson Chi Squared Test (if assumptions are met) OR Fisher’s Exact
Probability Test of Indipendence (if assumptions are NOT met). So first
of all we are going to check the assumptions:
The observations are
indipendent (true: self reported education and gender are not dependant
on each other), the expected frequencies are > 5 (True), we have a
variable with more than two category (education), which makes the
contingency table bigger than 2x2, se we must check if up to 20% of the
expected frequencies are 1< f’ <5 (true). We will see in the next
chunks that all assumptions are met:
results <- chisq.test(mydata2$genderF, mydata2$educationF,
correct = TRUE)
results
##
## Pearson's Chi-squared test
##
## data: mydata2$genderF and mydata2$educationF
## X-squared = 12.294, df = 4, p-value = 0.0153
H0: There is no association between the two categorical
variables.
H1: There is association between the two catecorical
variables.
Based on the result of the test, we can reject H0,
(p=0.016), and conclude that there’s association between gender and self
reported education.
Now lets see the observed frequencies f:
addmargins(results$observed)
## mydata2$educationF
## mydata2$genderF 1 2 3 4 5 Sum
## Male 20 23 80 51 46 220
## Female 25 21 195 87 95 423
## Sum 45 44 275 138 141 643
From this table we can see how males and females actually self
reported their education, this is empirical data.
Now lets see the
expected or theoretical frequencies f’:
round(results$expected, 2)
## mydata2$educationF
## mydata2$genderF 1 2 3 4 5
## Male 15.4 15.05 94.09 47.22 48.24
## Female 29.6 28.95 180.91 90.78 92.76
From this table we can see how we expected males and females would
have self reported their education.
Now lets see the standardized
residuals from this table:
round(results$res, 2)
## mydata2$educationF
## mydata2$genderF 1 2 3 4 5
## Male 1.17 2.05 -1.45 0.55 -0.32
## Female -0.85 -1.48 1.05 -0.40 0.23
Here we can see what we actually observed vs what we expected in the
form of std.residuals: There’s more than expected number of males that
self reported their level of education to be “2” this is because the
std.residual (z-statistic) with the value of 2.05 falls outside the
boundary of [-1.96, 1.96] and deviation is statistically significant at
alpha=0.05.
addmargins(round(prop.table(results$observed, 2), 3), 1)
## mydata2$educationF
## mydata2$genderF 1 2 3 4 5
## Male 0.444 0.523 0.291 0.370 0.326
## Female 0.556 0.477 0.709 0.630 0.674
## Sum 1.000 1.000 1.000 1.000 1.000
With this last table we can check the probabilities of self reporting
education: we can say for example that 70.9% of females self reported
having an education of “3”.
Finally we check the effect size of the
correlation:
effectsize::cramers_v(mydata2$genderF, mydata2$educationF)
## Cramer's V (adj.) | 95% CI
## --------------------------------
## 0.11 | [0.00, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.11)
## [1] "small"
## (Rules: funder2019)
Based on sample data, we can conclude that men self report having worse education than women, but the effect size is small.