jamovi / jmv

jamovi for R
https://www.jamovi.org
59 stars 27 forks source link

`jmv::propTestN` doesn't drop NAs properly #219

Open IndrajeetPatil opened 5 years ago

IndrajeetPatil commented 5 years ago

When the counts are NA, jmv converts them to 0 which is not accurate. Such rows should be dropped from analysis.

# dataframe with NAs in both columns
(df <- tibble::tribble(
  ~x, ~y,
  "a", 5,
  NA, 2,
  "c", NA,
  "d", 2
))
#> # A tibble: 4 x 2
#>   x         y
#>   <chr> <dbl>
#> 1 a         5
#> 2 <NA>      2
#> 3 c        NA
#> 4 d         2

# result
jmv::propTestN(df, "x", "y")
#> Warning in chisq.test(counts, p = expProps): Chi-squared approximation may
#> be incorrect
#> 
#>  PROPORTION TEST (N OUTCOMES)
#> 
#>  Proportions                      
#>  -------------------------------- 
#>    Level    Count    Proportion   
#>  -------------------------------- 
#>    a            5         0.714   
#>    c            0         0.000   
#>    d            2         0.286   
#>  -------------------------------- 
#> 
#> 
#>  <U+03C7>² Goodness of Fit      
#>  ----------------------- 
#>    <U+03C7>²      df    p       
#>  ----------------------- 
#>    5.43     2    0.066   
#>  -----------------------

Created on 2019-01-27 by the reprex package (v0.2.1)

Session info ``` r devtools::session_info() #> - Session info ---------------------------------------------------------- #> setting value #> version R Under development (unstable) (2018-11-30 r75724) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/New_York #> date 2019-01-27 #> #> - Packages -------------------------------------------------------------- #> package * version date lib #> assertthat 0.2.0 2017-04-11 [1] #> backports 1.1.3 2018-12-14 [1] #> callr 3.1.1 2018-12-21 [1] #> cli 1.0.1.9000 2019-01-20 [1] #> colorspace 1.4-0 2019-01-13 [1] #> crayon 1.3.4 2017-09-16 [1] #> desc 1.2.0 2019-01-21 [1] #> devtools 2.0.1.9000 2019-01-23 [1] #> digest 0.6.18 2018-10-10 [1] #> dplyr 0.8.0 2019-01-24 [1] #> evaluate 0.12 2018-10-09 [1] #> fansi 0.4.0 2018-11-05 [1] #> fs 1.2.6 2018-08-23 [1] #> ggplot2 3.1.0.9000 2019-01-24 [1] #> glue 1.3.0 2018-07-17 [1] #> gtable 0.2.0 2016-02-26 [1] #> highr 0.7 2018-06-09 [1] #> htmltools 0.3.6 2017-04-28 [1] #> jmv 0.9.6 2018-12-11 [1] #> jmvcore 0.9.5.2 2018-12-10 [1] #> knitr 1.21 2018-12-10 [1] #> lazyeval 0.2.1 2017-10-29 [1] #> magrittr 1.5 2014-11-22 [1] #> memoise 1.1.0 2017-04-21 [1] #> munsell 0.5.0 2018-06-12 [1] #> pillar 1.3.1 2018-12-15 [1] #> pkgbuild 1.0.2 2018-10-16 [1] #> pkgconfig 2.0.2 2018-08-16 [1] #> pkgload 1.0.2 2018-10-29 [1] #> prettyunits 1.0.2 2015-07-13 [1] #> processx 3.2.1 2018-12-05 [1] #> ps 1.3.0 2018-12-21 [1] #> purrr 0.3.0 2019-01-25 [1] #> R6 2.3.0 2018-10-04 [1] #> Rcpp 1.0.0 2018-11-07 [1] #> remotes 2.0.2 2018-10-30 [1] #> rjson 0.2.20 2018-06-08 [1] #> rlang 0.3.1 2019-01-08 [1] #> rmarkdown 1.11 2018-12-08 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> scales 1.0.0 2018-08-09 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> stringi 1.2.4 2018-07-20 [1] #> stringr 1.3.1 2018-05-10 [1] #> testthat 2.0.1 2018-10-13 [1] #> tibble 2.0.1 2019-01-12 [1] #> tidyselect 0.2.5 2018-10-11 [1] #> usethis 1.4.0.9000 2019-01-24 [1] #> utf8 1.1.4 2018-05-24 [1] #> withr 2.1.2 2018-03-15 [1] #> xfun 0.4 2018-10-23 [1] #> yaml 2.2.0 2018-07-25 [1] #> source #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> Github (r-lib/cli@94e2fc5) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> Github (r-lib/desc@42b9578) #> Github (r-lib/devtools@3c368ad) #> CRAN (R 3.5.1) #> Github (tidyverse/dplyr@cf0e282) #> CRAN (R 3.5.1) #> Github (brodieG/fansi@ab11e9c) #> CRAN (R 3.5.1) #> Github (tidyverse/ggplot2@1f259f4) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> Github (tidyverse/purrr@240f7b2) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> Github (r-lib/usethis@3339fe9) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> #> [1] C:/Users/inp099/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-devel/library ```
jonathon-love commented 5 years ago

oh yup :)