Chi-square test not working because of missing values

Discuss statistics related things
Post Reply
Mara
Posts: 3
Joined: Wed Feb 04, 2026 10:30 am

Chi-square test not working because of missing values

Post by Mara »

Dear all,

Chi-square test for goodness-of-fit and test of independence are not working because of missing values that remain included in the calculations.

I have put the missing values in "missing values" in every variable, and they have been greyed out in the data set. However, they still remain in the variable levels. I have not found any way to exclude them from the calculations for Chi-square tests which of course did not work.

Indeed when I do the analysis and in the left box I tick "expected quantities", I can see that they have been taken into account (let's say they represent 20% of the answers) and on the right, in the result box, they don't appear but have been taken into consideration, meaning the other groups represent 80% (instead of 100%) and one part of the calcuation is "divided by nothing" (the 20% of the missing values), which result in NaN...

Anyone could please help me on that? That would be very much appreciated as otherwise I need to change software and restart from scratch all my analysis :(

Many thanks
User avatar
jonathon
Posts: 2947
Joined: Fri Jan 27, 2017 10:04 am

Re: Chi-square test not working because of missing values

Post by jonathon »

hi,

you're right, this is a weakness in our chi-square test implementation.

a work around would be to create a second variable which is a copy of the first, using computed variables. you'll see that the chi-square tests handle this second variable correctly.

jonathon


Screenshot 2026-02-06 at 09.57.25.png
Screenshot 2026-02-06 at 09.57.25.png (570.24 KiB) Viewed 2686 times
Mara
Posts: 3
Joined: Wed Feb 04, 2026 10:30 am

Re: Chi-square test not working because of missing values

Post by Mara »

Hi, thanks for checking this. It is true that the missing variable disappear from the data sets when you compute a new variable =...
However, if I do the test on this variable I still get NaN for the Chi-square test. Indeed, if I look at the expected quantities on the left, the missing variable is still taken into consideration...
User avatar
jonathon
Posts: 2947
Joined: Fri Jan 27, 2017 10:04 am

Re: Chi-square test not working because of missing values

Post by jonathon »

hi,

can you double check that for me? it works for me. observe that the 500 no longer appears in the contingency table. you'll need to use the new column in the analysis of course.

i think we have a fix for this issue in the pipeline, but i think you should be able to get this to work in the mean time.


Screenshot 2026-02-10 at 09.30.03.png
Screenshot 2026-02-10 at 09.30.03.png (245.75 KiB) Viewed 1108 times
Mara
Posts: 3
Joined: Wed Feb 04, 2026 10:30 am

Re: Chi-square test not working because of missing values

Post by Mara »

Hi, contingency table works. But not the chi-square test goodness of fit (NaN). And if you look at the expected proportions, the missing values would still appear...
User avatar
jonathon
Posts: 2947
Joined: Fri Jan 27, 2017 10:04 am

Re: Chi-square test not working because of missing values

Post by jonathon »

Ah, apologies for the misunderstanding.

I have something for you that I think will work.

Rather than a computed variable, use a transformed variable instead. Use the variable with the missing values as your source. You'll need to create a transform with the default formula, i.e. $source

Sorry for the runaround!

Jonathon
Post Reply