The function anofa()
performs an anofa of frequencies for designs with up to 4 factors
according to the anofa
framework. See Laurencelle and Cousineau (2023)
for more.
anofa(formula = NULL, data = NULL, factors = NULL)
A formula with the factors on the left-hand side. See below for writing the formula according to the data format.
Dataframe in one of wide, long, raw or compiled format;
For raw data formats, provide the factor names.
a model fit to the given frequencies. The model must always be an omnibus model (for
decomposition of the main model, follow the analysis with emFrequencies()
or contrastFrequencies()
)
The data can be given in four formats:
wide
: In the wide format, there is one line for each participant, and
one column for each factor in the design. In the column(s), the level must
of the factor is given (as a number, a string, or a factor).
long
: In the long format, there is an identifier column for each participant,
a factor column and a level number for that factor. If there are n participants
and m factors, there will be in total n x m lines.
raw
: In the raw column, there are as many lines as participants, and as many columns as
there are levels for each factors. Each cell is a 0|1 entry.
compiled
: In the compiled format, there are as many lines as there are cells in the
design. If there are two factors, with two levels each, there will be 4 lines.
See the vignette DataFormatsForFrequencies
for more on data format and how to write their formula.
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 single-factor 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
formula <- Frequency ~ Intensity * Pitch
w <- anofa(formula, 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
# To know more about other ways to format the datasets,
# see, e.g., `toRaw()`, `toLong()`, `toWide()`
w <- anofa(formula, minimalExample)
toWide(w)
#> Intensity Pitch
#> 1 Low Soft
#> 2 Low Soft
#> 3 Medium Soft
#> 4 Medium Soft
#> 5 Medium Soft
#> 6 High Soft
#> 7 High Soft
#> 8 High Soft
#> 9 High Soft
#> 10 High Soft
#> 11 Low Hard
#> 12 Low Hard
#> 13 Low Hard
#> 14 Low Hard
#> 15 Medium Hard
#> 16 Medium Hard
#> 17 High Hard
#> 18 High Hard
#> 19 High Hard
#> 20 High Hard
# See the vignette `DataFormatsForFrequencies` for more.
# Real-data example using a two-factor design with the data in compiled format:
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
w <- anofa( obsfreq ~ program * provider, 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
# You can ask easier outputs
w <- anofa(formula, minimalExample)
summarize(w) # or summary(w) for the ANOFA table
#> 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
explain(w) # human-readable ouptut
#> [1] "method explain not yet done..."