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"))
CodePudding user response:
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 NA
s.
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
CodePudding user response:
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