如何在R中提取Doornik-Hansen正态性检验的Ep统计量与Sig.Ep
Extracting Doornik-Hansen Test Statistic and P-Value from
normality.test2 First, you’ll want to capture the output of normality.test2() into a variable instead of just printing it to the console. This output is a named list containing all the test results, which makes it straightforward to pull out specific values like Ep and Sig.Ep.
Here’s how to adjust your code to do this:
# Define your matrix as before m_1 <- matrix(data[,2], nrow = nrow(data), ncol = 1) # Run the test and store the full result in a variable dh_test_output <- normality.test2(m_1) # Extract the test statistic Ep ep_stat <- dh_test_output$Ep # Extract the significance (p-value) Sig.Ep sig_ep_value <- dh_test_output$Sig.Ep # Optional: Print the results to verify cat("Doornik-Hansen Test Statistic (Ep):", ep_stat, "\n") cat("P-Value (Sig.Ep):", sig_ep_value, "\n")
How this works:
The normality.test2() function returns a list where each result component has a clear name (like Ep, Sig.Ep, Sk for skewness, Ku for kurtosis, etc.). Using the $ operator lets you directly access these named elements. If you ever want to see all available components in the test output, run names(dh_test_output) to list them out.
内容的提问来源于stack exchange,提问作者Klaus Hoejlund
相关产品推荐
相关产品推荐

