2
$\begingroup$

This is a dummy dataframe resembling my real-life data:

structure(list(cond = c("WT", "WT", "WT", "WT", "WT", "WT", "WT", 
"WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", "WT", 
"WT", "WT", "WT", "WT", "WT", "WT", "KO", "KO", "KO", "KO", "KO", 
"KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", "KO", 
"KO", "KO", "KO", "KO"), class = c("N", "N", "N", "N", "N", "N", 
"Y", "Y", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "N", "Y", "N", 
"N", "Y", "N", "Y", "N", "N", "N", "Y", "Y", "Y", "N", "N", "Y", 
"N", "N", "N", "Y", "Y", "N", "N", "N", "N", "N", "N", "N"), 
    lattice = c(72.4394527831179, 70.1486049154573, 71.2024262282001, 
    70.095774734531, 73.1687587160835, 73.4725521658284, 71.1213324059112, 
    69.4426450566097, 67.7407461727878, 67.3598397689386, 69.5170866395342, 
    68.751790570905, 73.2734806165999, 72.0386374169852, 70.293510845974, 
    68.9576642114016, 69.4472846093111, 70.8520303262601, 69.967844969872, 
    69.7957750105144, 76.3165495002798, 70.8237308152673, 70.5087804854601, 
    70.0768856496865, 49.4569953395058, 52.0898768763027, 44.3112116723351, 
    53.0069841435797, 49.6755152863985, 50.3014101181505, 49.0856479592249, 
    48.3511098818039, 50.0812079766985, 50.4035212282794, 54.0992908724316, 
    43.4055868143946, 50.1834254159389, 54.7298925145524, 55.1516389972744, 
    51.4685454381875, 52.253317158648, 52.8558395390657, 51.5377616093217, 
    57.7792154694597)), row.names = c(NA, -44L), class = "data.frame")

Those are two experiment conditions ("WT" & "KO"). In each condition, observations might be classified as "Y" or "N" depending on whether the organism exhibits some measured trait or not.

I would like to compare those 2 groups (experimental conditions) & to infer, whether there is a statistically significant difference in amount of observations regarded as "Y" between the groups (and if it is the case, whether there are more or less "Y"-s in "KO" with respect to "WT" or not).

I do not know what type of statistical test would be more appropriate for this task: Fisher's, Chi-squared, etc.

Info: the "lattice" is another feature of the dataset, I am comparing this parameter between conditions using the Wilcoxon rank test. For this question it might be ignored. I just decided to show an entire structure of df, including this column.

EDITS:

  1. the experiment does not have fixed marginals.
  2. there was a time window, in which the data were collected.
  3. conditions are independent (those were cell-sorting experiments).
  4. afaik, this cannot be addressed with McNemar's test which is applicable for dependent variables, so the question was incorrectly assigned as duplicate.
$\endgroup$
17
  • 1
    $\begingroup$ Welcome to CV, ramen! Does the answer to the question "McNemar test with multiple scores for the same subject" answer your needs? $\endgroup$
    – Alexis
    Commented Mar 24, 2023 at 16:46
  • 1
    $\begingroup$ did all the subjects undergo both experimental conditions? I.e. are your variable paired? $\endgroup$
    – utobi
    Commented Mar 24, 2023 at 17:20
  • 1
    $\begingroup$ This question was closed as a duplicate of one dealing with paired observations, as might be addressed with McNemar's test. However, there's no indication in the question that this was the design used, and the data presented don't reflect such a design. In addition, the cited question deals with more than two conditions, as in Cochran's Q test. $\endgroup$ Commented Mar 25, 2023 at 16:25
  • 1
    $\begingroup$ @Alexis - but I am the OP of that question. And I performed the experiment. The observations are independent. Nothing was repeated here. Cochran's test is applicable for 3 or more related groups, which is not the case here. Here I have 2 conditions (groups) which yield dichotomous result ("Y" or "N"). I could just stick to the chi-square but I have serious doubts. In real life data, the "N" prevails and the "Y" is incidental, so I am not sure whether chi-square approximates distribution correctly. $\endgroup$
    – ramen
    Commented Apr 7, 2023 at 9:08
  • 2
    $\begingroup$ I have voted to reopen because this question seems to have nothing to do with McNemar test which is about multiple scores within the same subject. $\endgroup$ Commented May 15, 2023 at 6:08

1 Answer 1

6
$\begingroup$

It is easier to present these data in a 2x2 contingency table.

$$\begin{array}{c|cc|c} &\text{Y}&\text{N} & \text{marginal sum}\\ \hline \text{WT} & 15 & 9 & 24\\ \text{KO} & 14 & 6 & 20 \\\hline \text{marginal sum} & 29 & 15 & 44 \\ \end{array}$$

The type of test to be performed depends on the boundary conditions (whether one or more marginals are fixed or not, e.g. whether the experiment selected a fixed number of cases with WT/KO and/or Y/N) and on the stopping rule (whether the test had a fixed number of the total 44 cases, or whether the test was continued untill some number of a particular class had been observed).

You can read about this in an article by Lydersen, Fatherland and Laake Recommended tests for association in 2×2 tables, but possibly also in many other places and also question already asked here.

Depending on the number of marginals that are fixed

  • both marginals fixed: the values have one degree of freedom which follows a hypergeometric distribution.

    You can perform Fisher's exact test.

    Example: the lady tasting tea experiment

  • one marginal fixed: the values have two degrees of freedom which follow a binomial distribution.

    You can perform several types of tests. For instance Barnard's test. Also a z-test for differences in proportions is commonly used.

    Example: a/b testing.

  • no marginal fixed the values follow a multinomial distribution.

    You can perform a chi-squared test, which approximates the multinomial distribution with a multivariate normal distribution. The null hypothesis is that the cell probabilities are a product of class probabilities.

    Example: an observational study where both of the two variables are not controlled.

A situation based on a stopping rule.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.