Questions tagged [contingency]

A contingency table is a non-negative integer matrix with specified row and column sums.

A contingency table is a non-negative integer matrix with specified row and column sums, so named by Karl Pearson in developing statistical tests of significance. Observations are counted in a table with appropriate row and column labels, whereby statistical tests may be done on the entries to determine how likely the results would arise if the row and column outcomes were independent events.

Given specified row and column sums, counting the number of possible contingency tables can be a hard problem. Indeed even the case of $2$ rows and $n$ columns is known to be #P-complete.

However existence of solutions, unless otherwise constrained, is easy: it is necessary and sufficient that the row sums and column sums give equal totals for the entries of the entire matrix (balance condition).

An example of a further constraint would be requiring 0/1 entries, called binary contingency tables. Necessary and sufficient criteria for these restricted solutions were given by Gale and Ryser (independently) in 1957.

242 questions
0
votes
2 answers

Making contingency table from from values given by table function

I have a vector like this : > agg$RNAtype [1] "HnRn" "HyRy" "HnRn" "HyRn" "HnRn" "HnRn" "HnRn" "HnRn" "HnRy" "HnRn" "HnRy" [12] "HnRn" Now when I use table function, it gives the following: > table(agg$RNAtype) HnRn HnRy HyRn HyRy 8 2 …
hi15
  • 2,113
  • 6
  • 28
  • 51
0
votes
1 answer

2x2 contingency table constructing in sql

I'm trying to construct a 2x2 contigency table as explained in the following link below: Ad hoc 2x2 contingency tables SQL Server 2008 (tried to understand the code but couldn't wrap my head around it) A loop is made to construct pairs as in C1,C1…
user3707396
  • 1
  • 1
  • 2
0
votes
3 answers

How can I reshape a data.table or data.farme in R without adding up the frequencies?

I am trying to reshape the following data.table to like a contingency table(not exactly because I don't want to get frequency as value, I just want 0 or 1): Df: ID CC 990081899A CC2 990081899A CC115 990081899A CC39 990081899A …
nsDataSci
  • 189
  • 2
  • 10
0
votes
0 answers

Fisher test for a more than two groups of genes

I'm doing an analysis if there is increase or decrease in dependence on the mutated genes, using 3 or more genes using the fisher exact test. I performed with success an analysis for two genes using fisher.test(). example of the 2x2 contigency…
0
votes
1 answer

multirow contingency table in R

Let's consider this data set: df <- data.frame(age= sample(c(20:90), 20, rep=T), sex = sample(c('m', 'f'), 20, rep=T), smoker=sample(c("never", "former", "active"), 20, rep=T), size= sample (c(8:40), 20,…
0
votes
0 answers

Contingency table plus confidence intervals

I've recently discovered deducer and it's contingency table function (see Exporting deducer's contingency tables as csv or xls) What I'm trying to do is plot the values from a contingency table in ggplot to show a barplot with % frequency up the…
marty_c
  • 5,779
  • 5
  • 24
  • 27
0
votes
1 answer

Setting up a 4-D contingency table in R from flat, 5 column data.frame with 3 factors

I have a data frame in R. The first two columns are my summed frequencies of "Yes" and "No." The final 3 columns are categorical factors, each with a label. I am trying to make a 4-D contingency table from this format and I have no idea where to…
0
votes
1 answer

Normalize a contingency table

Suppose I have a table > tab <- table(c("www.a.com","a.com","a.com","www.b.com")) > tab a.com www.a.com www.b.com 2 1 1 I want to merge the entries for "www.a.com" and "a.com" to get a.com b.com 3 …
sds
  • 58,617
  • 29
  • 161
  • 278
0
votes
2 answers

Use R to create a large multiple column frequency table

I am having a hard time doing this efficiently and apologize if it's a basic question. I need to make a contingency table with N and percent to summarize relationships between a large number of binary variables, simply in terms of freq and percent,…
micturalgia
  • 325
  • 1
  • 4
  • 13
-1
votes
1 answer

One-Hot Encoding from Contingency Table in R

I have a cross-classification table that looks like this: My goal is to create a one-hot encoding of this table. So there would have to be 24 rows where the outcome is 1(having heart disease) and the 'never' column is 1 and all others are 0. 35…
Tom Green
  • 11
  • 2
-1
votes
1 answer

how to group a column and that the other column is grouped to generate a contingency table in R

I need to group the column "Estrato" 1 and 2 into low, 3,4,5 into medium, 6 into high and others, taking into account column "Callevive" the format of colum "Estrato" is factor. to generate a contingency table like in the image. enter code here >…
Jonas
  • 33
  • 2
  • 9
-1
votes
2 answers

Building contingency table

I have a table like this: df <- data.frame(P1 = c(1,0,0,0,0,0,"A"), P2 = c(0,-2,1,2,1,0,"A"), P3 = c(-1,2,0,2,1,0,"B"), P4 = c(2,0,-1,0,-1,0,"B"), Names =…
Sos
  • 1,783
  • 2
  • 20
  • 46
-2
votes
1 answer

How can I find the effect size of a 2x2 contingency table where chi square test is not applicable?

I have a dataset that contains the number of times visitors to two variants of a website (site1 and site2) bought something or left without buying. The visitors are 200 per site. Now, as showed in this picture, I have one cell in which the number…
Elena
  • 11
  • 6
-2
votes
1 answer

Creating a contingency table by hypergeometric sampling with the Titanic's database

I created a contingency table with the passengers data from the Titanic by the Hypergeometric sampling -That's mean that both of the marginal totals are preset and equals-. It was created crossing the Sex and Survivor columns of 328 cases -164 men…
Ángel
  • 133
  • 1
  • 11
-2
votes
1 answer

trouble with contingency table in R

I looked everywhere but did not find answer to my question. I am having trouble with makig contingency table. I have data with many columns, let say 1, 2 and 3. In the first column there are let say 100 different values, in the second 20 and the…
A.S
  • 1
  • 1
1 2 3
16
17