rtidyversestatistical-test

R: one missing value ruins my Jarque-Bera test


This code does not omit N/As and execute the Jarque-Bera test properly. What code does? I thank you for your advice.

library(moments)
jarque.test(mydata$item1, na.rm = TRUE)

My data

structure(list(item1 = c(6, 7, NA, 7, 6, 2, 7, 3, 4, 7, 4, 5, 
4, 7, 7, 6, 5, 7, 6, 7, 4, 7, 5, 6, 5, 4, 7, 5, 4, 6, 7, 5, 5, 
7, 7, 5, 7, 7, 7, 4, 5, 7, 7, 7, 5, 7, 6, 7, 7, 5), item2 = c(6, 
7, 6, 6, 6, 3, 7, 3, 3, 4, 5, 6, 4, 7, 6, 6, 4, 6, 6, 7, 6, 3, 
5, 5, 3, 2, 7, 5, 6, 6, 7, 3, 5, 7, 6, 5, 6, 5, 6, 4, 6, 7, 7, 
7, 7, 7, 6, 7, 4, 7)), row.names = c(NA, -50L), class = c("tbl_df", 
"tbl", "data.frame"))

Solution

  • We could use JarqueBeraTest form DescTools, in contrast to the others it has a na.rm argument:

    library(DescTools)
    JarqueBeraTest(df$item1, robust = TRUE, na.rm = TRUE)
    
    data:  structure(c(6, 7, 7, 6, 2, 7, 3, 4, 7, 4, 5, 4, 7, 7, 6, 5, 7, 6, 7, 4, 7, 5, 6, 5, 4, 7, 5, 4, 6, 7, 5, 5, 7, 7, 5, 7, 7, 7, 4, 5, 7, 7, 7, 5, 7, 6, 7, 7, 5), na.action = structure(3L, class = "omit"))
    X-squared = 3.9623, df = 2, p-value = 0.1379