Twelve participants took part in an experiment to rate the attractiveness of a woman and a man who were shown on a video in either a good mood or a bad mood. Since the participants performed under one condition only, the design is a between-participants, or independent, design. The data given in Table 16.1 are ratings given by participants (out of 20) for a woman in either a good mood or a bad mood.
The woman, an actor, was the same individual in both conditions. There were meant to be six participants in each group, but unfortunately an error occurred, and one participant who was meant to be in the GOOD MOOD condition was accidentally placed in the BAD MOOD condition.
Our experimental hypothesis is that there will be a significant difference between the ratings given by participants in the GOOD MOOD and BAD MOOD conditions. Note, for the purposes of this example, that the hypothesis is two-tailed: that is, we have not predicted the direction of the difference.
good <- c(7,15,14,3,17)
bad <- c(4,6,11,7,9,4,7)
par(mfrow = c(1, 2))
hist(good)
hist(bad)
library(psych)
skew(bad)
## [1] 0.2918841
median(good)
## [1] 14
median(bad)
## [1] 7
# Non-parametric version of paired t-test is Mann–Whitney U test
# wilcox.test()
wilcox.test(good, bad)
## Warning in wilcox.test.default(good, bad): cannot compute exact p-value
## with ties
##
## Wilcoxon rank sum test with continuity correction
##
## data: good and bad
## W = 25, p-value = 0.2514
## alternative hypothesis: true location shift is not equal to 0
p-value is high (0.25) -> there is no significant difference between two variables: a good or a bad mood of a woman
What did the teacher discover?
#person <- c("Ahmed", "Bella", "Carol", "Darren", "Elike")
conf <- c(2, 3, 1, 4, 5)
perf <- c(5, 3, 5, 4, 1)
#table(person, conf, perf)
#spearman correlation
library(ggcorrplot)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
cor(conf, perf, method = "spearman")
## [1] -0.8720816
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#cor(conf, perf, method = "spearman") %>% round(2) %>% ggcorrplot(hc.order = TRUE, type = "upper", ggtheme = ggplot2::theme_bw, colors =c("darkturquoise", "#E46726"))
p-value is 0.53, which is higher than 0.5 - non statistically significant. coerreclational coeficient then is -0.872 - strong negative relation.
What did the teacher discover? She has discovered that there is no signofocant relation between student’s confidence and their actual overall performance.
Nurses were given a questionnaire that measured how sympathetic they were to chronic fatigue sufferers; for each nurse, a total score (out of 10) was calculated.
They then took part in an hour’s discussion group, which included ME sufferers.
Later, a similar questionnaire was given to them. This is obviously a within-participants design, as the same participants are being measured in both the ‘before’ and ‘after’ conditions. We will make a directional hypothesis here. A directional hypothesis should be made when there is evidence to support such a direction (e.g. from past research).
First, reproduce the results in a data frame.
before <- c(5,6,2,4,6,7,3,5,5,5)
after <- c(7,6,3,8,7,6,7,8,5,8)
median(before)
## [1] 5
median(after)
## [1] 7
hist(before)
hist(after)
hist(before - after)
library(psych)
skew(after) #high negative skew
## [1] -0.910736
wilcox.test(before, after, paired = T, exact = F)
##
## Wilcoxon signed rank test with continuity correction
##
## data: before and after
## V = 2, p-value = 0.02877
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(before, after, paired = T, exact = F, alternative = "less") # specification of alternative hipothesis as "less" means that we suggest that afetr the talk nurses will be more sympathetic
##
## Wilcoxon signed rank test with continuity correction
##
## data: before and after
## V = 2, p-value = 0.01439
## alternative hypothesis: true location shift is less than 0
P-value is low (0.03), which means the difference is significant between “before” and “after” results.
Then we’ve tested the more precize test, with certain direction. We suggest that the difference between before and after results will be less than 0 -> afetr the talk nurses will be more sympathetic. The P-value is low (0.014), thus the difference is significant. Afetr the discussion sympathy is higher.
Our hypothesis is that there will be a significant difference between the scores before and after the discussion, such that scores after the discussion will be higher. Note that this is a one-tailed hypothesis because we have specified the direction of the difference.
With small samples, sometimes data are skewed and the mean may not be appropriate – in which case, report the median in summary statistics. You will need to look at histograms to discover whether this is the case.
# calculate
Nyashia and George have randomly allotted 18 migraine sufferers to three groups. Group 1 has six one-hour sessions of group counselling with a trainee counsellor; group 2 has six one-hour self-help sessions (not led by a facilitator; the agenda is determined by the group members themselves); and group 3 consists of migraine sufferers who would like to take part in the group therapy or self-help, but who have to wait.
Nyashia and George expect that the counselling and self-help groups will rate themselves as suffering less than the waiting list control group when they rate themselves at the second time point. At the beginning of the study, sufferers rate their symptoms, over the past month, from 0 (not suffering) to 5 (terrible suffering).
Fourteen weeks later, they rate their symptoms (in the past month) again. The data follow.
Since the group sizes are small the scores are self-ratings and the data are not normally distributed; non-parametric tests are recommended.
Perform two Kruskal–Wallis, one on the symptoms at the beginning of the study, and one on the symptoms 14 weeks later. Write up the results in the form of a short paragraph
group <- c(rep("A", 5), rep("B", 6), rep("C", 7))
sy_1 <- c(3,4,5,2,3,4,5,4,2,3,2,4,5,4,2,3,2,3)
sy_2 <- c(1,3,4,2,1,2,5,3,2,5,2,5,3,4,4,5,2,3)
data <- as.data.frame(cbind(group, sy_1, sy_2))
data
str(data)
## 'data.frame': 18 obs. of 3 variables:
## $ group: Factor w/ 3 levels "A","B","C": 1 1 1 1 1 2 2 2 2 2 ...
## $ sy_1 : Factor w/ 4 levels "2","3","4","5": 2 3 4 1 2 3 4 3 1 2 ...
## $ sy_2 : Factor w/ 5 levels "1","2","3","4",..: 1 3 4 2 1 2 5 3 2 5 ...
data$sy_1 <- as.numeric(data$sy_1)
data$sy_2 <- as.numeric(data$sy_2)
describeBy(data, data$group)
##
## Descriptive statistics by group
## group: A
## vars n mean sd median trimmed mad min max range skew kurtosis
## group* 1 5 1.0 0.00 1 1.0 0.00 1 1 0 NaN NaN
## sy_1 2 5 2.4 1.14 2 2.4 1.48 1 4 3 0.19 -1.75
## sy_2 3 5 2.2 1.30 2 2.2 1.48 1 4 3 0.26 -1.96
## se
## group* 0.00
## sy_1 0.51
## sy_2 0.58
## --------------------------------------------------------
## group: B
## vars n mean sd median trimmed mad min max range skew kurtosis
## group* 1 6 2.00 0.00 2.0 2.00 0.00 2 2 0 NaN NaN
## sy_1 2 6 2.33 1.21 2.5 2.33 1.48 1 4 3 0.04 -1.88
## sy_2 3 6 3.17 1.47 2.5 3.17 0.74 2 5 3 0.39 -2.00
## se
## group* 0.00
## sy_1 0.49
## sy_2 0.60
## --------------------------------------------------------
## group: C
## vars n mean sd median trimmed mad min max range skew kurtosis
## group* 1 7 3.00 0.00 3 3.00 0.00 3 3 0 NaN NaN
## sy_1 2 7 2.29 1.11 2 2.29 1.48 1 4 3 0.15 -1.64
## sy_2 3 7 3.71 1.11 4 3.71 1.48 2 5 3 -0.15 -1.64
## se
## group* 0.00
## sy_1 0.42
## sy_2 0.42
library(summarytools)
## For best results, restart R session and update pander using devtools:: or remotes::install_github('rapporter/pander')
dfSummary(data)
boxplot(data$sy_1 ~ data$group)
boxplot(data$sy_2 ~ data$group)
kruskal.test(data$sy_1 ~ data$group) #non-significant
##
## Kruskal-Wallis rank sum test
##
## data: data$sy_1 by data$group
## Kruskal-Wallis chi-squared = 0.028982, df = 2, p-value = 0.9856
kruskal.test(data$sy_2 ~ data$group) #non-significant
##
## Kruskal-Wallis rank sum test
##
## data: data$sy_2 by data$group
## Kruskal-Wallis chi-squared = 3.5595, df = 2, p-value = 0.1687
kruskal.test(data$sy_2[data$group != "B"] ~ data$group[data$group != "B"]) #non-significant
##
## Kruskal-Wallis rank sum test
##
## data: data$sy_2[data$group != "B"] by data$group[data$group != "B"]
## Kruskal-Wallis chi-squared = 3.3189, df = 1, p-value = 0.06849
anova1 <- aov(data$sy_1 ~ data$group)
summary(anova1) #non-significant
## Df Sum Sq Mean Sq F value Pr(>F)
## data$group 2 0.038 0.019 0.014 0.986
## Residuals 15 19.962 1.331
TukeyHSD(anova1) #non-significant
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = data$sy_1 ~ data$group)
##
## $`data$group`
## diff lwr upr p adj
## B-A -0.06666667 -1.881103 1.747769 0.9949927
## C-A -0.11428571 -1.868823 1.640251 0.9843590
## C-B -0.04761905 -1.714686 1.619448 0.9969702
anova2 <- aov(data$sy_2 ~ data$group)
summary(anova2) #non-significant
## Df Sum Sq Mean Sq F value Pr(>F)
## data$group 2 6.716 3.358 2.01 0.169
## Residuals 15 25.062 1.671
TukeyHSD(anova2) #non-significant
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = data$sy_2 ~ data$group)
##
## $`data$group`
## diff lwr upr p adj
## B-A 0.9666667 -1.0663817 2.999715 0.4517510
## C-A 1.5142857 -0.4516467 3.480218 0.1462415
## C-B 0.5476190 -1.3203042 2.415542 0.7314878
The results of all the possible teting were indignificant - there were no significant differences between testing of varioud groups before or after the treatment.
Credits for these data problems: Dancey, Christine P., author. | Reidy, John, author. Statistics without maths for psychology / Christine P. Dancey, University of East London, John Reidy, Sheffield Hallam University. Seventh Edition. | New York : Pearson, [2017] | Revised edition of the authors’ Statistics without maths for psychology, 2014.
Slides: xaringan package.