cond.fun.chisq.test | R Documentation |
Asymptotic chi-squared test to determine the model-free functional dependency of effect variable Y
on a cause variable X
, conditioned on a third variable Z
.
cond.fun.chisq.test(x, y, z=NULL, data=NULL, log.p = FALSE,
method = c("fchisq", "nfchisq"))
x |
vector or character; either a discrete random variable (cause) represented as vector or a character column name in |
y |
vector or character; either a discrete random variable (effect) represented as vector or a character column name in |
z |
vector or character; either a discrete random variable (condition) represented as vector or a character column name in |
data |
a data frame containing three or more columns whose names can be used as values for |
log.p |
logical; if |
method |
a character string to specify the method to compute the conditional functional chi-squared test statistic and its p-value. The options are |
The conditional functional chi-squared test introduces the concept of conditional functional depedency, where the functional association between two variables (x
and y
) is tested conditioned on a third variable (z
) \insertCitezhang2014nonparametricFunChisq. Two methods are provided to compute the chi-squared statistic and its p-value. When method = "fchisq"
, the p-value is computed using the chi-squared distribution; when method = "nfchisq"
, a normalized statistic is obtained by shifting and scaling the original chi-squared statistic and a p-value is computed using the standard normal distribution \insertCiteBox2005FunChisq. The normalized test is more conservative on the degrees of freedom.
A list with class "htest
" containing the following components:
statistic |
the conditional functional chi-squared statistic if |
parameter |
degrees of freedom for the conditional functional chi-squared statistic. |
p.value |
p-value of the conditional functional test. If |
estimate |
an estimate of the conditional function index between 0 and 1. The value of 1 indicates strong functional dependency between |
Sajal Kumar and Mingzhou Song
See (unconditional) functional chi-squared test fun.chisq.test
.
# Generate a relationship between variables X and Z
xz = matrix(c(30,2,2, 2,2,40, 2,30,2),ncol=3,nrow=3,
byrow = TRUE)
# Re-construct X
x = rep(c(1:nrow(xz)),rowSums(xz))
# Re-construct Z
z = c()
for(i in 1:nrow(xz))
z = c(z,rep(c(1:ncol(xz)),xz[i,]))
# Generate a relationship between variables Z and Y
# Make sure Z retains its distribution
zy = matrix(c(4,30, 30,4, 4,40),ncol=2,nrow=3,
byrow = TRUE)
# Re-construct Y
y = rep(0,length(z))
for(i in unique(z))
y[z==i] = rep(c(1:ncol(zy)),zy[i,])
# Tables
table(x,z)
table(z,y)
table(x,y)
# Conditional functional dependency
# Y = f(X) | Z should be false
cond.fun.chisq.test(x=x,y=y,z=z)
# Z = f(X) | Y should be true
cond.fun.chisq.test(x=x,y=z,z=y)
# Y = f(Z) | X should be true
cond.fun.chisq.test(x=z,y=y,z=x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.