R/ANOFA-contrastFrequencies.R
contrastFrequencies.Rd
The function contrastFrequencies()
performs contrasts analyses
of frequencies after an omnibus analysis has been obtained with anofa()
according to the ANOFA framework. See Laurencelle and Cousineau (2023)
for more.
contrastFrequencies(w = NULL, contrasts = NULL)
An ANOFA object obtained from anofa()
or emFrequencies()
;
A list that gives the weights for the contrasts to analyze. The contrasts within the list can be given names to distinguish them. The contrast weights must sum to zero and their cross-products must equal 0 as well.
a model fit of the constrasts.
contrastFrequencies computes the Gs for the contrasts, testing the hypothesis that it equals zero. The contrasts are each 1 degree of freedom, and the sum of the contrasts' degrees of freedom totalize the effect being decomposed.
Laurencelle L, Cousineau D (2023). “Analysis of frequency tables: The ANOFA framework.” The Quantitative Methods for Psychology, 19, 173--193. doi:10.20982/tqmp.19.2.p173 .
# Basic example using a two-factors design with the data in compiled format.
# Ficticious data present frequency of observation classified according
# to Intensity (three levels) and Pitch (two levels) for 6 possible cells.
minimalExample
#> Intensity Pitch Frequency
#> 1 Low Soft 2
#> 2 Medium Soft 3
#> 3 High Soft 5
#> 4 Low Hard 4
#> 5 Medium Hard 2
#> 6 High Hard 4
# performs the omnibus analysis first (mandatory):
w <- anofa(Frequency ~ Intensity * Pitch, minimalExample)
summary(w)
#> G df Gcorrected pvalue etasq
#> Total 2.2530 5 NA NA NA
#> Intensity 1.2607 2 1.220 0.5433 0.0593
#> Pitch 0.0000 1 0.000 1.0000 0.0000
#> Intensity:Pitch 0.9923 2 0.866 0.6486 0.1012
# execute the simple effect of Pitch for every levels of Intensity
e <- emFrequencies(w, ~ Intensity | Pitch)
summary(e)
#> G df Gcorrected pvalue etasq
#> Intensity | Soft 1.3792 2 1.3347 0.2480 0.12120
#> Intensity | Hard 0.8738 2 0.8457 0.3578 0.08036
# For each Pitch, contrast the three intensities, first
# by comparing the first two levels to the third, second
# by comparing the first to the second level:
w3 <- contrastFrequencies( e, list(
contrast1 = c(1, 1, -2)/2,
contrast2 = c(1, -1, 0) )
)
summary(w3)
#> G df Gcorrected pvalue
#> contrast1 | Soft 1.1778 1 1.1042 0.2933
#> contrast2 | Soft 0.2014 1 0.1888 0.6639
#> contrast1 | Hard 0.1942 1 0.1821 0.6696
#> contrast2 | Hard 0.6796 1 0.6371 0.4248
# Example using the Landis et al. (2013) data, a 3 x 5 design involving
# program of care (3 levels) and provider of care (5 levels).
LandisBarrettGalvin2013
#> provider program obsfreq
#> 1 MC/MA CBH 19
#> 2 MC/MA PBH 18
#> 3 MC/MA BM 2
#> 4 MC CBH 24
#> 5 MC PBH 53
#> 6 MC BM 3
#> 7 MA CBH 44
#> 8 MA PBH 57
#> 9 MA BM 5
#> 10 $P CBH 20
#> 11 $P PBH 57
#> 12 $P BM 3
#> 13 PI CBH 63
#> 14 PI PBH 165
#> 15 PI BM 20
# performs the omnibus analysis first (mandatory):
w <- anofa(obsfreq ~ provider * program, LandisBarrettGalvin2013)
summary(w)
#> G df Gcorrected pvalue etasq
#> Total 533.19 14 NA NA NA
#> provider 206.57 4 206.20 0.00000 0.2720
#> program 307.77 2 307.40 0.00000 0.3576
#> provider:program 18.85 8 18.69 0.01662 0.4909
# execute the simple effect of Pitch for every levels of Intensity
e <- emFrequencies(w, ~ program | provider)
summary(e)
#> G df Gcorrected pvalue etasq
#> program | MC/MA 18.65 2 18.63 0.000931 0.3235
#> program | MC 54.64 2 54.58 0.000000 0.4058
#> program | MA 54.27 2 54.20 0.000000 0.3386
#> program | $P 61.98 2 61.91 0.000000 0.4365
#> program | PI 137.08 2 136.91 0.000000 0.3560
# For each Pitch, contrast the three intensities, first
# by comparing the first two levels to the third, second
# by comparing the first to the second level:
w3 <- contrastFrequencies( e, list(
contrast1 = c(1, 1, -2)/2,
contrast2 = c(1, -1, 0) )
)
summary(w3)
#> G df Gcorrected pvalue
#> contrast1 | MC/MA 18.62157 1 18.30861 0.000019
#> contrast2 | MC/MA 0.02703 1 0.02658 0.870501
#> contrast1 | MC 43.44675 1 43.08768 0.000000
#> contrast2 | MC 11.19616 1 11.10363 0.000862
#> contrast1 | MA 52.58971 1 52.26102 0.000000
#> contrast2 | MA 1.67792 1 1.66743 0.196603
#> contrast1 | $P 43.44675 1 43.08768 0.000000
#> contrast2 | $P 18.53577 1 18.38258 0.000018
#> contrast1 | PI 89.78682 1 89.54610 0.000000
#> contrast2 | PI 47.29049 1 47.16371 0.000000