<p>I just did this myself and got totally different results from you.</p>
<pre><code>
x_student &lt;- rep(&quot;student&quot;, 266)
y_student &lt;- c(rep(0, 266 - 59), rep(1, 59))
x_elderly &lt;- rep(&quot;elderly&quot;, 127)
y_elderly &lt;- c(rep(0, 127 - 23), rep(1, 23))
x &lt;- c(x_student, x_elderly)
y &lt;- c(y_student, y_elderly)
L &lt;- glm(y ~ x, family = binomial)
summary(L)

m &lt;- matrix(c(
    23, 137 - 23,
    59, 266 - 59
), 2, 2)
chisq.test(m)
</code></pre>
<p>My chi-squared test returns a p-value of <span class="math-container">$0.253$</span>, while my logistic regression coefficient has a p-value of <span class="math-container">$0.354$</span>, neither of which match your work. (I could believe that I made a mistake in my code, but I think it is correct.) While these p-values are different, they are close enough, and neither signals data that are inconsistent with the implicit null hypothesis that elderly people and students respond differently to the survey. Given that both groups have about an <span class="math-container">$80/20$</span> split, this is not surprising, particularly since you only have a few hundred observations and, thus, not a bunch of power to detect a small difference.</p>

CC BY-SA 4.0
2023-03-04T06:17:13.963Z
2023-03-04T06:17:13.963Z
Dave
<p><a href="https://i.sstatic.net/JzGel.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JzGel.png" alt="enter image description here" /></a></p>
<p>my data looks like this:</p>
<p>I have two groups of people - Students and the elderly.</p>
<p>59 out of 266 students said &quot;YES&quot; 23 out of 127 elderly people said &quot;YES&quot;</p>
<p>The rest said &quot;no&quot;</p>
<p>I am trying to find out where this difference in their answers is statistically significant.</p>
<p>My first way was chi square test that says they are different with a p lower than 0,05. However, my binomial logit with only one independent variable brings this result result of binomial logit, meaning that the difference is not significant.</p>
<p>What am I missing here?</p>
<p>Thanks!</p>

CC BY-SA 4.0
2023-03-04T05:57:12.063Z
What is “Tarifb”? You’re right that the logistic regression test and the chi-squared test should have similar results (in fact, the chi-squared test of a $2\times2$ table is equivalent to a score test of the logistic regression slope), but, based on its name, it is not clear that the variable you included in the logistic regression is meaningful to your analysis.
Dave
<econometrics><r><logit>
Results Chi square test vs binomial logit
vojta9
# Results Chi square test vs binomial logit

(Asked by: username_0 on 2023-03-03)

[![enter image description here](https://i.sstatic.net/JzGel.png)](https://i.sstatic.net/JzGel.png)

my data looks like this:

I have two groups of people - Students and the elderly.

59 out of 266 students said "YES" 23 out of 127 elderly people said "YES"

The rest said "no"

I am trying to find out where this difference in their answers is statistically significant.

My first way was chi square test that says they are different with a p lower than 0,05. However, my binomial logit with only one independent variable brings this result result of binomial logit, meaning that the difference is not significant.

What am I missing here?

Thanks!

**Tags:** econometrics, r, logit
> **Comments:**
> **username_1**: What is “Tarifb”? You’re right that the logistic regression test and the chi-squared test should have similar results (in fact, the chi-squared test of a $2\times2$ table is equivalent to a score test of the logistic regression slope), but, based on its name, it is not clear that the variable you included in the logistic regression is meaningful to your analysis.  

---

## 1 answers

### Answer by username_1 on 2023-03-04. Score: 0 | Accepted answer

I just did this myself and got totally different results from you.

x_student <- rep("student", 266)
y_student <- c(rep(0, 266 - 59), rep(1, 59))
x_elderly <- rep("elderly", 127)
y_elderly <- c(rep(0, 127 - 23), rep(1, 23))
x <- c(x_student, x_elderly)
y <- c(y_student, y_elderly)
L <- glm(y ~ x, family = binomial)
summary(L)

m <- matrix(c(
    23, 137 - 23,
    59, 266 - 59
), 2, 2)
chisq.test(m)

My chi-squared test returns a p-value of $0.253$, while my logistic regression coefficient has a p-value of $0.354$, neither of which match your work. (I could believe that I made a mistake in my code, but I think it is correct.) While these p-values are different, they are close enough, and neither signals data that are inconsistent with the implicit null hypothesis that elderly people and students respond differently to the survey. Given that both groups have about an $80/20$ split, this is not surprising, particularly since you only have a few hundred observations and, thus, not a bunch of power to detect a small difference.


---

