From ruipb@rr@d@@ @ending from @@po@pt  Wed Aug 22 22:43:23 2018
From: ruipb@rr@d@@ @ending from @@po@pt (Rui Barradas)
Date: Wed, 22 Aug 2018 21:43:23 +0100
Subject: [Rd] bug report: inaccurate error message for stats::chisq.test
In-Reply-To: <CAEKh8ugry7UaJ2a3AmjCbkz8iB4cqE7++r523esTuKVvPfRP2w@mail.gmail.com>
References: <CAEKh8ugry7UaJ2a3AmjCbkz8iB4cqE7++r523esTuKVvPfRP2w@mail.gmail.com>
Message-ID: <1d204df8-652c-2aff-df8c-733ca37fb610@sapo.pt>

Hello,

A workaround could be

y <- addNA(y)
chisq.test(x,y)


But this implies that the user was aware of the  reason why the error.

Hope this helps,

Rui Barradas

On 21/08/2018 15:31, Ant F wrote:
> Hi,
> 
> `stats::chisq.test` checks that x and y each have at least 2 levels AFTER
> filtering on complete cases.
> 
> It makes sense but the error message is misleading : ?'x' and 'y' must have
> at least 2 levels?
> 
> Here?s how to reproduce the issue :
> 
>      x <- structure(c(1L, 1L, 1L, 2L, 1L, 2L), .Label = c("0001", "0003"),
> class = "factor")
> 
>      y <- structure(c(1L, 2L, 2L, NA, 2L, NA), .Label = c("0001", "0002"),
> class = "factor")
> 
>      chisq.test(x,y)
> 
>      # Error in chisq.test(...) : 'x' and 'y' must have at least 2 levels
> 
> In this case they do have 2 levels.
> 
> Best regards,
> 
> Antoine
> 
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

---
This email has been checked for viruses by AVG.
https://www.avg.com



[Rd] bug report: inaccurate error message for stats::chisq.test
Rui Barradas