bug report: inaccurate error message for stats::chisq.test

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bug report: inaccurate error message for stats::chisq.test

Ant F
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]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: bug report: inaccurate error message for stats::chisq.test

Rui Barradas
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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel