Upon completing this module, students will be able to:
Someone briefly remind us of the design of the study (focus on study 5).
Results from two \(\chi^2\) tests from study 5.
“…participants are more likely to follow through when they are assigned a cue-based reminder (in the forced-reminder through-association condition, 87%) than when no cue-based reminder is available (none condition, 59%), \(\chi^2\)(1, N = 305) = 30.22, p < .001.”
“…those in the costly-reminder-through-association condition were not only more likely to earn the bonus (74%) than those in the none condition (59%), \(\chi^2\)(1, N = 297) = 7.23, p = .007,…”
Complete the steps in the “Setup” portion of the lab activity.
condition
, choice
, and correct
. Read from “codebook database.xlsx” to identify appropriate factor labels.Import “RTA_study5.csv” to R.
Convert the following variables to factors, condition
, choice
, and correct
. Read from “codebook database.xlsx” to identify appropriate factor labels.
condition
to FactorThe codebook tells us the levels/labels for condition.
## [1] Free Costly Costly None Free Free All All None All
## Levels: Free None Costly All
choice
to FactorWhat does choice
tell us?
## [1] took reminder took reminder did not take reminder
## [4] did not take reminder did not take reminder did not take reminder
## [7] did not take reminder did not take reminder did not take reminder
## [10] took reminder
## Levels: did not take reminder took reminder
correct
to FactorWhat does correct
tell us?
## [1] correct incorrect incorrect correct correct correct incorrect
## [8] correct correct correct
## Levels: incorrect correct
“…participants are more likely to follow through when they are assigned a cue-based reminder (in the forced-reminder through-association condition, 87%) than when no cue-based reminder is available (none condition, 59%), \(\chi^2\)(1, N = 305) = 30.22, p < .001.”
data.frame
that includes only the relevant levels of condition
.droplevels()
to drop the extra levels of condition
.Hint: You can use either |
or %in%
to subset with one line of code. Otherwise, you could do it in two steps.
|
Remember that |
means “or”.
Can you imagine a situation where this approach might be unwieldy?
%in%
Why should you check your work as you go?
We don’t need to see this in your code
We can check with the function all()
, which returns:
## [1] TRUE
all()
can be a useful tool for testing your code.
Alternatively, we can use summary()
, which will count the number of times each factor level occurs.
## Free None Costly All
## 0 153 0 152
Why do we need to do this?
mosaicplot()
. Which argument(s) is/are required for the default S3 method?mosaicplot()
documentation.mosaicplot()
? How do you know?
ggplot2
ggplot2
Bar Plot“…participants are more likely to follow through when they are assigned a cue-based reminder (in the forced-reminder through-association condition, 87%) than when no cue-based reminder is available (none condition, 59%), \(\chi^2\)(1, N = 305) = 30.22, p < .001.”
How do we interpret these percentages?
Several ways to do this. E.g., using the contingency table.
## Response
## Condition incorrect correct
## None 63 90
## All 20 132
## [1] 0.8684211
## [1] 0.5882353
With tapply()
## None All
## 0.5882353 0.8684211
Use chisq.test()
to conduct a \(\chi^2\) test to compare the groups.
chisq.test()
to learn how this is done.chisq.test()
applies a continuity correction for 2x2 tables. The authors of the paper do not apply this correction, so you will need to change the default argument to reproduce their results.Two ways of doing this that are equivalent.
##
## Pearson's Chi-squared test
##
## data: dta1$condition and dta1$correct
## X-squared = 30.22, df = 1, p-value = 3.857e-08
## [1] 305
Basically two main assumptions:
Expected frequencies of at least 80% of cells should be greater than 5.
## dta1$correct
## dta1$condition incorrect correct
## None 41.63607 111.3639
## All 41.36393 110.6361
Use fisher.test()
to compare the groups using Fisher’s exact test.
##
## Fisher's Exact Test for Count Data
##
## data: cont_table
## p-value = 3.919e-08
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 2.537016 8.614158
## sample estimates:
## odds ratio
## 4.596306
Effect size.