# Testing the count of binary variable against the other binary variable

I have a table like this:

Signal In_range Obs
0 0 677
1 85
1 0 1883
1 1521

I need to run a test to show if the signal is 0, the difference between the number of observations for In_range (0 and 1) will be higher when the signal is 1. In other words I want to say that "The weak signal is responsible for many out of range observatiosn" Any help is appreciated.

• I believe you need to provide more information about your experiment. Are the data provided only an example? Do you need to make inferences or use only descriptive statistics. Nov 25 '21 at 10:00
• I need to make inferences (they are not example). Maybe one of Chi-square or proportions_ztest from statsmodels would be useful but I'm not sure how should I approach them. Nov 25 '21 at 10:06

I take it that you got 677 out of range observations among 762 for the weak signal and 1883 out of range out of range among 3404 for the strong signal, and you want to know whether the proportion $$677/762=0.888$$ is signficantly larger than the proportion $$1883/3402=0.553.$$

If so, then one possible test is prop.test in R, as follows, where the P-value near $$0$$ indicates a highly significant difference.

prop.test(c(677,1883), c(762,3402), alt="g", cor=F)

2-sample test for
equality of proportions
without continuity correction

data:  c(677, 1883) out of c(762, 3402)
X-squared = 294.93, df = 1, p-value < 2.2e-16
alternative hypothesis: greater
95 percent confidence interval:
0.311535 1.000000
sample estimates:
prop 1    prop 2
0.8884514 0.5534979

The test above is essentially a one-sided version of a chi-squared test on the table TAB shown below, which is a two-sided test. [The two chi-squared statistics differ slightly because of a difference in rounding conventions. Normally, the P-value for the two-sided test would be twice as large as in the one-sided test, but here both occurrences of 2.2e-16 should be taken as "essentially $$0$$."]

TAB = rbind(c(677,85),c(1883,1527))
TAB
[,1] [,2]
[1,]  677   85
[2,] 1883 1527

chisq.test(TAB, cor=F)

Pearson's Chi-squared test

data:  TAB
X-squared = 297.02, df = 1, p-value < 2.2e-16

Notes: (1) Because of the relatively large sample sizes, I used parameter cor=F to decline continuity correction.

(2) Several tests of difference between two binomial proportions that use normal approximations are in use. This page from the NIST handbook describes one of them.

You can consider this problem as testing for significant difference of two binomial mean estimates from two groups.

You can then calculate the mean estimates and the variance of the estimates by hand.

Since N is large, you can conduct a simple t-test to test for the difference between the means.