I have a dataset on Excel which has lots of columns (A, B, C...Z) and I want to perform a Chi-Square Test to obtain p value between B e C column only. Columns B and C only have two types of values: 0, 1. The column A on Excel corresponds to the identification number of the person. I proceeded as follows:
I created a contingency table by running this code
write.table(db,'my_data.txt',quote=FALSE,sep='\t', row.names=FALSE)file_path <- 'my_data.txt'dbtable <- read.delim(file_path, row.names=1)I created then a table containing only the columns I am interested in performing the Chi Square Test on, thus:
db2columns <- dbtable %>% select(B, C)I tried to run the Chi Square Test on db2columns, as it follows:
chisq <- chisq.test(db2columns) chisqHowever it displays:Error in chisq.test(db2columns) : all entries of 'x' must be nonnegative and finiteI tried to convert db2columns to a contingency table but it doesn't work too, saying the same error.
I have then two questions
- Is there a faster way to perform chi square test on two columns only without all the steps I wrote above?
- How do I solve the error?
I am new to R so sorry if it's a simple question
Thank you!