I'm comparing two data sets (3 groups) with relative large number of observations and I'm getting p-value of 0. (0 < 0.05, meaning rejecting H0, that the samples are equal, when in fact there is not a large difference)
So how I can run a sensitivity check and decide on the test sensitiveness in respect of i.e. number of observations, degrees of freedom.
I like this analysis (simulation) here provided kindly by Mr. W. Huber. But I'm not sure I can get similar sort of analysis by changing i.e. degrees of freedom or jitter the sample size etc., to obtain kind of scenario analysis.
Here is what I have tried:
Data:
x <- data.frame(group=c(1,2,3),
o=c(695301,154100, 224140),
e=c(930785, 192893, 273400))
e <- x$e # expected frequency under Null Hypothesis
o <- x$o # obseved frequency
r <- sum( (o - e) / sqrt(e)) # standardised residuals
chq <- r^2; chq # Chi-square statistic
dof <- nrow(x) - 1 # degree of freedom
p.value <- 1 - pchisq(chq, df = dof) # p-value
p.value # confirm p.value with chisq.test()
p.val <- e/sum(e)
chisq.test(x = o, p = p.val, rescale.p = TRUE)$p.value
Here the chisq.test
has some sort of bootstrapping allowing to drop effective the degrees of freedom parameter. Here I'm getting p.value of circa 0.09.
chisq.test(x= o, p = p.val, simulate.p.value = TRUE, B = 10)
Simple straightforward approach, yields the same result.
chisq.test(x) # simple solution
Here I tried to perform the kind of sensitivity/or scenario analysis by simulation, without any concluding facts.
lsim <- lapply(x[ ,"o", drop=FALSE], function(x) replicate(100, jitter(x)))
o <- data.frame(lsim)
e <- x$e
apply(o, 2, function(x) { r <- sum( (x - e) / sqrt(e));
chq <- sum(r^2); p.value <- 1 - pchisq(chq, df = dof); p.value } )
I would really like to see (via graphical interface) where and by which margin the two samples differ, rather than just simply concluding (without proper understanding in which group etc.) that the two sample are not equal.
sum(r^2)
but actually use the summation twice which is also an error. I will read your answer correctly and I'm hopeful to guide me further. Many thanks. $\endgroup$