我想使用卡方测试是否x
具有y
相同的频率分布。在下面的代码中,我得出的结论是,因为卡方的 P 值 > 0.05,所以我没有发现证据表明存在不同x
的y
频率分布。我的结论正确吗?
set.seed(1)
x <- rnorm(100, 3, 2)
y <- rnorm(100, 3, 2)
x_counts <- with(hist(x, plot = FALSE), data.frame(breaks = breaks[-1], counts = counts))
y_counts <- with(hist(y, plot = FALSE), data.frame(breaks = breaks[-1], counts = counts))
y_counts <- rbind(data.frame(breaks = -1, counts = 0), y_counts)
x_probs <- x_counts$counts/sum(x_counts$counts)
chisq.test(x=y_counts$counts, p=c(x_probs), simulate.p.value = TRUE)
# Chi-squared test for given probabilities with simulated p-value (based on 2000 replicates)
# data: y_counts$counts
# X-squared = 3.3808e-31, df = NA, p-value = 1