I'd like to reuse R code from the stats
package that simulates contingency tables to compute a simulated p.value
for a chi-squared test.
When looking at the chisq.test
function source code, you can see the following :
if (simulate.p.value && all(sr > 0) && all(sc > 0)) {
setMETH()
tmp <- .Call(C_chisq_sim, sr, sc, B, E)
STATISTIC <- sum(sort((x - E)^2/E, decreasing = TRUE))
PARAMETER <- NA
PVAL <- (1 + sum(tmp >= almost.1 * STATISTIC))/(B +
1)
}
The interesting line here is the .Call
call :
tmp <- .Call(C_chisq_sim, sr, sc, B, E)
What I'd like to do, if it is possible, is to use this C_chisq_sim
function in my own code, but I can't manage to do it. If I try with :
tmp <- .Call(C_chisq_sim, sr, sc, B, E, PACKAGE="stats")
I get a C_chisq_sim object not found
error. And if I try with :
tmp <- .Call("C_chisq_sim", sr,sc,B,E, PACKAGE="stats")
I get an error saying that the entry point is not in the loading table.
I'd like a solution that would be cross-platform, if possible.
This should do the trick I guess:
tmp <- .Call(stats:::C_chisq_sim, sr, sc, B, E, PACKAGE="stats")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With