0
$\begingroup$

Apologies for what I think is a basic question.

I have 3 years of data gathered from medical clinics on how many patients per year presented with a certain condition (X patients out of Y total patients for that year). An example is: 2018: 5 out of 367 2019: 5 out of 408 2020: 16 out of 420

I am trying to test for whether there was a statistically significant increase in patients presenting with the condition in 2020.

I thought that I could use a chi-squared test with 2 degrees of freedom to test for independence between the three observations. Is that right or have I got something wrong here? A couple of worries that I had were (1) the categories (years) are ordered, not just unrelated buckets; and (2) I am specifically trying to test whether 2020 was an outlier, rather than ‘there are no outliers’. Maybe this doesn’t really make a difference given the setup of the question, but I wasn’t sure if this would change the choice of test to use.

$\endgroup$
1
$\begingroup$

You can set up your data as a contingency table, as with the following R code:

yourtable <- as.table( matrix(c(5,  5,  16,
                                367-5,  408-5,  420 -16), 
      byrow=TRUE, nrow=2, ncol=3))
rownames(yourtable) <- c("cases",  "nocases")
colnames(yourtable) <- c("2018",  "2019",  "2020")  
 yourtable
        2018 2019 2020
cases      5    5   16
nocases  362  403  404

Now you can do a chisquare test of independence in this table:

 chisq.test(yourtable)

    Pearson's Chi-squared test

data:  yourtable
X-squared = 8.1389, df = 2, p-value = 0.01709

But you are only interested in whether 2020 is different from the two other years. One simple way to do it wold be simply to lump together the data for 2018 and 2019, thereby obtaining a $2\times 2$-table and proceeding as above. I will show another, more general, way, converting to the corresponding logistic regression:

yourdf <- as.data.frame(yourtable)
colnames(yourdf) <- c("Group",  "Year", "Freq")
yourdf
    Group Year Freq
1   cases 2018    5
2 nocases 2018  362
3   cases 2019    5
4 nocases 2019  403
5   cases 2020   16
6 nocases 2020  404

A logistic regression corresponding to the independence test in the above $3\times 2$-table is

 mod0 <- glm( Group  ~ Year ,  weights=Freq, data=yourdf, family=binomial)
> summary(mod0)

Call:
glm(formula = Group ~ Year, family = binomial, data = yourdf, 
    weights = Freq)

Deviance Residuals: 
      1        2        3        4        5        6  
 -6.554    3.151   -6.635    3.152  -10.226    5.602  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)   4.2822     0.4503   9.510   <2e-16 ***
Year2019      0.1073     0.6365   0.169   0.8661    
Year2020     -1.0534     0.5174  -2.036   0.0418 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 250.48  on 5  degrees of freedom
Residual deviance: 242.80  on 3  degrees of freedom
AIC: 248.8

Number of Fisher Scoring iterations: 6

> anova(mod0, test="Chisq")
Analysis of Deviance Table

Model: binomial, link: logit

Response: Group

Terms added sequentially (first to last)


     Df Deviance Resid. Df Resid. Dev Pr(>Chi)  
NULL                     5     250.48           
Year  2   7.6805         3     242.79  0.02149 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 

The p-value given there corresponds to the likelihood ratio test (in this context also known as G-test), which is very close to the chi-square test.

Finally, the test corresponding to lumping 2018 and 2019:

 mod1 <- glm( Group  ~ I(Year=="2020") ,  weights=Freq, 
                 data=yourdf, family=binomial)
anova(mod1, test="Chisq")
> Analysis of Deviance Table

Model: binomial, link: logit

Response: Group

Terms added sequentially (first to last)


                  Df Deviance Resid. Df Resid. Dev Pr(>Chi)   
NULL                                  5     250.48            
I(Year == "2020")  1   7.6522         4     242.82  0.00567 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
$\endgroup$
1
  • $\begingroup$ Thank you very much for your help! $\endgroup$
    – Resolute
    Oct 27 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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