What is Analysis of Frequency Data?"

The ANalysis Of Frequency datA (ANOFA) is a framework for analyzing frequencies (a.k.a. counts) of classification data. This framework is very similar to the well-known ANOVA and uses the same general approach. It allows analyzing main effects and interaction effects_It also allow analyzing _simple effects (in case of interactions) as well as orthogonal contrats. Further, ANOFA makes it easy to generate frequency plots which includes confidence intervals, and to compute eta-square as a measure of effect size. Finally, power planning is easy within ANOFA.

cat("this will be hidden; use for general initializations.\n")
library(ANOFA)
library(ggplot2)
library(superb)
# generate some random data with no meaning
set.seed(43)
#probs  #alone                 #ingroup               #harass                #shout
pr <- c(0.4/12,1.4/12,0.5/12,  2.3/12,1.0/12,0.5/12,  0.5/12,2.0/12,0.4/12,  0.5/12,2.0/12,0.5/12)
dta <- GRF( list(Gender          = c("boy", "girl", "other"), 
                 TypeOfInterplay = c("alone", "ingroup", "harrass", "shout")
            ),
            300,
            pr
        )

A basic example

As an example, suppose that you observe a class of primary school students, trying to ascertain the different sorts of behaviors. You might use an obsrevation grid where, for every kid observed, you check various things, such as

| Student Id: A | | |:----------------|-------------------------| |Gender: | Boy [x] Girl [ ] Other [ ] | |Type of interplay: | Play alone [x] Play in group [ ] Harrass others [ ] Shout against other [ ] | |etc. |

This grid categorizes the participants according to two factors, Gender, and TypeOfInterplay.

From these observations, one may wish to know if gender is more related to one type of interplay. Alternatively, genders could be evenly spread across types of interplay. In the second case, there is no interaction between the factors.

Some data

Once collected through observations, the data can be formated in one of many ways (see the vignette Data formats). The raw format could look like

| Id | boy | girl | other | alone | in-group | harass | shout | |----|------|-------|-------|-------|----------|--------|-------| | A | 1 | 0 | 0 | 1 | 0 | 0 | 0 | | B | 0 | 0 | 1 | 0 | 0 | 1 | 0 | | C | 0 | 1 | 0 | 0 | 0 | 0 | 1 | | D | 1 | 0 | 0 | 0 | 1 | 0 | 0 | | ...| | | | | | | |

For a more compact representation, the data could be compiled into a table with all the combination of gender $\times$ types of interplay, hence resulting in 12 cells. The results (totally ficticious) looks like (assuming that they are stored in a data.frame named dta):

dta

for a grand total of r sum(dta$Freq) childs observed.

Analyzing the data

The frequencies can be analyzed using the Analysis of Frequency Data (ANOFA) framework [@lc23b]. This framework only assumes that the population is multinomial (which means that the population has certain probabilities for each cell). The relevant test statistic is a $G$ statistic, whose significance is assessed using a chi-square table.

ANOFA works pretty much the same as an ANOFA except that instead of looking at the means in each cell, its examines the count of observations in each cell.

To run an analysis of the data frame dta, simply use:

library(ANOFA)

w <- anofa(Freq ~ Gender * TypeOfInterplay, data = dta) 

This is it. The formula indicates that the counts are stored in column Freq and that the factors are Gender and TypeOfInterplay, each stored in its own column. (if your data are organized differently, see Data formats).

At this point, you might want a plot showing the counts on the vertical axis:

anofaPlot(w) 

We can note a strong interaction, the ingroup activity not being distributed the same as a function of Gender. To confirm the interaction, let's look at the ANOFA table:

summary(w)

Indeed, the interaction (last line) is significant ($G(6) = 65.92$, $p < .001$). The $G$ statistics is corrected for small sample but the correction is typically small (as seen in the fourth column).

We might want to examine whether the frequencies of interplay are equivalent separately for each Gender, even though examination of the plot suggest that it is only the case for the other gender. This is achieved with an analysis of the simple effects of TypeOfInterplay within each level of Gender:

e <- emFrequencies(w, Freq ~ TypeOfInterplay | Gender)
summary(e)

As seen, for boys and girls, the type of interplay differ significantly (both $p < .002$); for others, as expected from the plot, this is not the case ($G(3) = 1.57$, $p = 0.46$).

If really, you need to confirm that the major difference is caused by the ingroup type of activity (in these ficticious data), you could follow-up with a contrast analysis. We might compare alone to harass, both to shout, and finally the three of them to ingroup.

f <- contrastFrequencies(e, list(
    "alone vs. harass                     " = c(-1,    0, +1,    0  ),
    "(alone & harass) vs. shout           " = c(-1/2,  0, -1/2, +1  ),
    "(alone & harass & shout) vs. in-group" = c(-1/3, +1, -1/3, -1/3)

))
summary(f)

Because the contrast analysis is based on the simple effects within Gender (variable e), we get three contrasts for each gender. As seen, for boys, in-group is the sole condition triggering the difference. Same for girls. Finally, there are no difference for the last group.

Additivity of the decomposition (optional)

The main advandage of ANOFA is that all the decomposition are entirely additive.

If, for example, you sum the $G$s and degrees of freedom of the contrasts, with e.g.,

sum(summary(f)[,1])  # Gs
sum(summary(f)[,2])  # degrees of freedom

you get exacly the same as the simple effects:

sum(summary(e)[,1])  # Gs
sum(summary(e)[,2])  # degrees of freedom

which is also the same as the main analysis done first, adding the main effect of TypeOfInterplay and its interaction with Gender (lines 3 and 4):

sum(summary(w)[c(3,4),1])  # Gs
sum(summary(w)[c(3,4),2])  # degrees of freedom

In other words, the decompositions preserved all the information available. This is the defining characteristic of ANOFA.

References



Try the ANOFA package in your browser

Any scripts or data that you put into this service are public.

ANOFA documentation built on Nov. 18, 2023, 5:06 p.m.