function problem

chisq.test returns the following. Some are single-valued, others longer. What x is to be plotted depends on what is to be illustrated.

str(chisq.test(mtcars$mpg, mtcars$drat))
#> Warning in chisq.test(mtcars$mpg, mtcars$drat): Chi-squared approximation may be
#> incorrect
#> List of 9
#>  $ statistic: Named num 536
#>   ..- attr(*, "names")= chr "X-squared"
#>  $ parameter: Named int 504
#>   ..- attr(*, "names")= chr "df"
#>  $ p.value  : num 0.157
#>  $ method   : chr "Pearson's Chi-squared test"
#>  $ data.name: chr "mtcars$mpg and mtcars$drat"
#>  $ observed : 'table' int [1:25, 1:22] 0 0 0 0 0 0 1 0 0 0 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ mtcars$mpg : chr [1:25] "10.4" "13.3" "14.3" "14.7" ...
#>   .. ..$ mtcars$drat: chr [1:22] "2.76" "2.93" "3" "3.07" ...
#>  $ expected : num [1:25, 1:22] 0.125 0.0625 0.0625 0.0625 0.0625 0.125 0.0625 0.0625 0.0625 0.0625 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ mtcars$mpg : chr [1:25] "10.4" "13.3" "14.3" "14.7" ...
#>   .. ..$ mtcars$drat: chr [1:22] "2.76" "2.93" "3" "3.07" ...
#>  $ residuals: 'table' num [1:25, 1:22] -0.354 -0.25 -0.25 -0.25 -0.25 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ mtcars$mpg : chr [1:25] "10.4" "13.3" "14.3" "14.7" ...
#>   .. ..$ mtcars$drat: chr [1:22] "2.76" "2.93" "3" "3.07" ...
#>  $ stdres   : 'table' num [1:25, 1:22] -0.377 -0.262 -0.262 -0.262 -0.262 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ mtcars$mpg : chr [1:25] "10.4" "13.3" "14.3" "14.7" ...
#>   .. ..$ mtcars$drat: chr [1:22] "2.76" "2.93" "3" "3.07" ...
#>  - attr(*, "class")= chr "htest"

Created on 2020-09-02 by the reprex package (v0.3.0)

1 Like