0

I have a dataset with multiple categorical columns. I want to calculate the p-value using chisq.test for each and every pair of column. was trying this but it is giving an error.

e.g.
dataset
v1  v2  v3  v4
a   q   e   f
a   w   g   h
b   z   e   i
c   q   e   h

a = dataset
value = matrix(nrow=ncol(a), ncol=ncol(a))
for (i = 1:ncol(a)){
  for (j = 1:ncol(a)){
    tbl = table(a[,i],a[,j])
    tst = chisq.test(tbl)
    value[i,j] == tst$p.value
  }
}

any leads will be rewarded

1 Answers1

1

You need to make some changes in your code to store the p values in value.

for (i in 1:ncol(a)) {
  for (j in 1:ncol(a)) {
    tbl <- table(a[, i], a[, j])
    tst <- chisq.test(tbl)
    value[i, j] <- tst$p.value
  }
}
Juan Bosco
  • 1,420
  • 5
  • 19
  • 23