Author: Edi Oblak
Is there difference between performance IQ and verbal IQ score of patients after being in coma for several days due to severe injuries of brains?
mydata <- force(Wong)
head(mydata)
## id days duration sex age piq viq
## 1 3358 30 4 Male 20.67077 87 89
## 2 3535 16 17 Male 55.28816 95 77
## 3 3547 40 1 Male 55.91513 95 116
## 4 3592 13 10 Male 61.66461 59 73
## 5 3728 19 6 Male 30.12731 67 73
## 6 3790 13 3 Male 57.06229 76 69
Unit of observation in our data is patient, sample size is 331, which is appropriate for our analysis. It is good to know that there were 200 patients tested, some of them twice. Those who were tested twice were not tested at the same time, but in a relevant time difference. For hypothesis testing we don’t need such a big sample, that is why we perform reduction of it.
Source of data: Wong, P. P., Monette, G., and Weiner, N. I. (2001) Mathematical models of cognitive recovery. Brain Injury, 15, 519–530.
We have to reduce a number of units. We decided to have 100 units in our sample.
set.seed(1) #Setting initial point of sampling.
mydata <- mydata[sample(nrow(mydata), 100), ] #Random sample of 50 units.
For purposes of further data analysis, we convert categorical variable to factor variable.
mydata$GenderF <- factor(mydata$sex,
levels = c("Male", "Female"),
labels = c("Male", "Female"))
To check the data for possible outliers, we can change wide format of data to long format of data, check boxplots, find outliers and then remove them.
#Wide format of data is changed to long format.
mydata_long <- mydata %>%
pivot_longer(
cols = c("piq", "viq"),
names_to = "IQs",
values_to = "Score") %>%
convert_as_factor(IQs)
mydata_long <- as.data.frame(mydata_long)
tail(mydata_long, 10)
## id days duration sex age GenderF IQs Score
## 191 5893 71 21 Male 22.81177 Male piq 65
## 192 5893 71 21 Male 22.81177 Male viq 90
## 193 4962 210 1 Female 25.19644 Female piq 71
## 194 4962 210 1 Female 25.19644 Female viq 70
## 195 6314 58 3 Male 16.69268 Male piq 80
## 196 6314 58 3 Male 16.69268 Male viq 99
## 197 2081 185 43 Male 17.69747 Male piq 77
## 198 2081 185 43 Male 17.69747 Male viq 97
## 199 5014 46 7 Female 23.76181 Female piq 75
## 200 5014 46 7 Female 23.76181 Female viq 90
#Boxplot for each variable
ggboxplot(mydata_long,
x = "IQs",
y = "Score",
add = "jitter")
#Finding outliers
mydata_long %>%
group_by(IQs) %>%
identify_outliers(Score)
## # A tibble: 2 × 10
## IQs id days duration sex age GenderF Score is.outlier is.extreme
## <fct> <int> <dbl> <int> <fct> <dbl> <fct> <int> <lgl> <lgl>
## 1 piq 5713 1016 8 Male 16.3 Male 126 TRUE FALSE
## 2 piq 4705 18 1 Female 21.7 Female 127 TRUE FALSE
#Removing outliers (we found two of them)
mydata_long <- mydata_long %>%
filter(!id == 4705 & !id == 5713)
# This one is just to check that we really deleted outliers!
mydata_long %>%
group_by(IQs) %>%
identify_outliers(Score)
## [1] IQs id days duration sex age GenderF Score is.outlier is.extreme
## <0 rows> (or 0-length row.names)
summary(mydata[ , -1]) # We don't want to describe id.
## days duration sex age piq viq GenderF
## Min. : 15.00 Min. : 0.00 Female:26 Min. : 6.513 Min. : 61.00 Min. : 67.00 Male :74
## 1st Qu.: 50.75 1st Qu.: 1.00 Male :74 1st Qu.:20.837 1st Qu.: 78.00 1st Qu.: 86.00 Female:26
## Median : 137.50 Median : 7.00 Median :24.375 Median : 87.00 Median : 94.00
## Mean : 465.54 Mean :10.88 Mean :31.214 Mean : 87.61 Mean : 94.87
## 3rd Qu.: 329.00 3rd Qu.:14.00 3rd Qu.:37.544 3rd Qu.: 97.00 3rd Qu.:104.25
## Max. :7631.00 Max. :94.00 Max. :69.706 Max. :127.00 Max. :128.00
We have to calculate the difference between piq score and viq score.
mydata$Difference <- mydata$piq - mydata$viq # Negative difference means better score at viq than at piq.
head(mydata) # We check that there is new variable in mydata
## id days duration sex age piq viq GenderF Difference
## 324 3808 2434 7 Male 28.26831 105 111 Male -6
## 167 1048 85 94 Male 20.11499 63 82 Male -19
## 129 5298 107 3 Male 22.95688 117 112 Male 5
## 299 5713 1016 8 Male 16.26831 126 106 Male 20
## 270 1624 604 1 Male 19.56194 97 85 Male 12
## 187 6180 177 12 Male 20.72005 81 94 Male -13
For better presentation we can draw histogram of calculated differences.
ggplot(mydata, aes(x=Difference)) +
geom_histogram(binwidth = 1, color = "black") +
xlab("Differences") +
ylab("Frequency")
To check normal distribution, we have to perform Shapiro-Wilk normality test. H0: Variable is normally distributed. H1: Variable is not normally distributed.
shapiro.test(mydata$Difference)
##
## Shapiro-Wilk normality test
##
## data: mydata$Difference
## W = 0.99043, p-value = 0.6994
We do not reject H0 (p = 0.6994). Distribution is normal. We can perform analysis based on parametrical test.
H0: Average score for performance IQ and verbal IQ of patients after being in coma for several days due to severe injuries of brains is the same. H1: Average score for performance IQ and verbal IQ of patients after being in coma for several days due to severe injuries of brains is NOT the same.
t.test(mydata$piq, mydata$viq,
paired = TRUE,
alternative = "two.sided")
##
## Paired t-test
##
## data: mydata$piq and mydata$viq
## t = -5.8105, df = 99, p-value = 7.59e-08
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -9.739188 -4.780812
## sample estimates:
## mean difference
## -7.26
We reject H0 at p < 0.001. Average score for performance IQ and verbal IQ of patients after being in coma for several days due to severe injuries of brains is NOT the same. On average patients had better score in verbal IQ.
We proceed with interpreting the size of differences.
cohens_d(mydata$Difference)
## Cohen's d | 95% CI
## --------------------------
## -0.58 | [-0.79, -0.37]
interpret_cohens_d(-0.58, rules = "sawilowsky2009")
## [1] "medium"
## (Rules: sawilowsky2009)
The difference between performance IQ and verbal IQ score of patients after being in coma for several days due to severe injuries of brains is medium (|d| = 0.58).
This is the end of hypothesis testing for this data sample, because assumptions are not violated. So interpretation should be relevant from Paired t-test. To show what to do in case of violated assumptions we will demonstrate the alternative non-parametrical test used in such case.
wilcox.test(mydata$piq, mydata$viq,
paired = TRUE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided")
##
## Wilcoxon signed rank test
##
## data: mydata$piq and mydata$viq
## V = 985.5, p-value = 3.318e-07
## alternative hypothesis: true location shift is not equal to 0
We reject H0 at p < 0.001. Average score for performance IQ and verbal IQ of patients after being in coma for several days due to severe injuries of brains is NOT the same. On average patients had better score in verbal IQ.
We proceed with interpreting the size of differences.
effectsize(wilcox.test(mydata$piq, mydata$viq,
paired = TRUE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided"))
## r (rank biserial) | 95% CI
## ----------------------------------
## -0.59 | [-0.72, -0.43]
Based on r value, the difference between performance IQ and verbal IQ score of patients after being in coma for several days due to severe injuries of brains is very large (|r| = 0.59).