0

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"))
Gato
  • 389
  • 2
  • 12
  • 2
    according to the documentation "jarque.test()" has no na.omit argument - I guess you have to remove the na values before calling the "jarque.test()" I guess – DPH Dec 29 '22 at 16:48
  • In fact, `jarque.test` only has one argument (`x`, ref: https://github.com/cran/moments/blob/master/R/jarque.test.R). I suggest `jarque.test(na.omit(mydata$item1))` for now, and then I suggest submitting a feature-request to the package author to support some form of argument for handling `NA` values, e.g., `na.rm=` or `na.omit=`. – r2evans Dec 29 '22 at 16:56

2 Answers2

1

As the comments state, since there is no na.rm argument in moments::jarque.test and it only accepts a single argument, a workaround is to just subset your data excluding the NAs.

moments::jarque.test(mydata$item1[!is.na(mydata$item1)])

#  Jarque-Bera Normality Test
# 
# data:  mydata$item1[!is.na(mydata$item1)]
# JB = 4.9442, p-value = 0.08441
# alternative hypothesis: greater
jpsmith
  • 11,023
  • 5
  • 15
  • 36
1

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
TarJae
  • 72,363
  • 6
  • 19
  • 66