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
1
vote
2 answers

Create vectors from a contingency table

I have a contingency table of meteorological stations and frequency of occurrence. I used logical indexing to create separate vectors like below (b1:b5) from the table. However there has to be a simpler way, perhaps from the apply family. Can…
DAY
  • 91
  • 6
1
vote
1 answer

Perform multiple chi-squared test on dataframe based on column value

I have a data frame with count numbers and I want to perform a chisq.test for each value of the variable Cluster. So basically, I need 4 contingency tables (for "A","B","C","D") where rows = Category, columns = Drug, value = Total. And subsequently…
Joep_S
  • 481
  • 4
  • 22
1
vote
1 answer

Creating contigency table in R

I'm pretty new to coding in R and am doing an assignment where my task is to create a contingency table. My sample data of News Inquiries in Texas examines the variables: Day,Section(News, Sports ,or Business), and number of Inquiries. From what I…
1
vote
1 answer

Add margins to multi-way tables in R

I have the following code in R to build a three-way contingency table: txt=" death_p yes no v_race d_race white white 53 414 black 11 37 black white 0 16 black 4 139" mytable =…
Luigi Tiburzi
  • 4,265
  • 7
  • 32
  • 43
1
vote
1 answer

McNemar exact test

I am performing a McNemar test in R of the following data: Obtaining the following result: I understand the results, nevertheless, someone could explain to me how the confidence interval is computed?
Sss
  • 427
  • 2
  • 8
1
vote
2 answers

Retain column names after permutation of table in R

I have a table in R where the rownames are (as per default) A,B,C,... and the column names are 1,2,3,4,... as assigned. For example, the output of x <- as.table(matrix(c(2,20,3,4,2,5,8,1,3),nrow=3,ncol=3,byrow=TRUE)) colnames(x) <-…
Mobeus Zoom
  • 598
  • 5
  • 19
1
vote
1 answer

R markdown contingency table %>% tabulate column variables with selective values

I am quite new to R, coming from Stata. Below is the r markdown chunk with reproducible data example. The data is representative to the data i am working with. But only with more binary (logical) and factor variables in number. The libraries and…
Mahm00d27
  • 17
  • 7
1
vote
1 answer

How do I get a contingency table from this data?

I am trying to make a contingency table from a set of data. So far it looks like this: But I would like for it to look like this, but in R: I've tried some things suggested online with other people's data, but it's hard for me to follow when all…
Lynn
  • 21
  • 2
1
vote
0 answers

Converting phenotypes and genotypes to contingency tables in R

I have data that looks like this: SNP aa_controls aA_controls AA_controls aa_cases aA_cases AA_cases rs2378938 3412 16822 21987 2635 13197 16573 rs6712069 …
Melderon
  • 365
  • 1
  • 16
1
vote
1 answer

How to select partial tables in 3d contingency tab?

This seems like a newb question, but I just can't figure it out. I'm looking at a 3d contingency table and I want to run analyses on the partial tables. Below is some sample data: df2 <- data.frame(Gender = c(rep("M", 6), rep("F", 6)), Beliefs =…
Michael
  • 111
  • 9
1
vote
1 answer

Why aren't the expected frequencies returned by scipy.ststs.contingency.expected_freq what I expect?

I have a data frame which I am wanting to calculate a chi squared and p-value for. However, when I print out the expected values they are not what I expect. The null hypothesis I was expecting the code to test is that there is no dependence of Q7 on…
1
vote
1 answer

Is it possible to order an R contingency table by rowSums

I have created a contingency table with several variables/cols by 510 categories/factors. I want to have factors ordered descending based on the sum of all variables/cols. Tried converting table back to DF and rowSums but no luck. Not sure if…
mh1975
  • 13
  • 2
1
vote
1 answer

How to create a binary relation matrix of pair occurrences from a list of strings?

have a list of files that contain specific genes, and I want to create a binary relation matrix in R that shows the presence of each gene in each file. For example, here are my files aaa, bbb, ccc, and ddd and the genes associated to…
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84
1
vote
1 answer

Randomization check

I feel a little stupid for asking this question, but somehow I can't figure it out! I am trying to see if participants are equally randomly assigned to two groups, so the contingency table looks like the below Condition A Condition B 30 …
user240313
  • 17
  • 6
1
vote
1 answer

R, how to create a binary relation matrix from a list of strings?

I have a list of files that contain specific genes, and I want to create a binary relation matrix in R that shows the presence of each gene in each file. For example, here are my files aaa, bbb, ccc, and ddd and the genes associated to…
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84