简体   繁体   中英

Chi Square test- preparing the data in R

I am trying to prepare the data to run Chi-square test, but it returns the following: Error: all entries of 'x' must be nonnegative and finite in fisher.test

Does anyone know what to do?

My dataset consists of seven species (4 animals per each species) and each species has 4 variables.

One part of the dataset looks like this:

df <- data.frame(ID=c("species1", "species1", "species2", "species2"),
             N1=c(28660, 37365, 29375, 29169), 
             N2=c(86872, 91519, 141865, 101298), 
             N3=c(140498, 51092, 93889, 42368), 
             N4=c(76942, 49351, 82002, 36730))

I am not sure how to prepare a data set in order to run chisq.test function?

Best!

you don't need the "ID” column.

df <- data.frame(N1=c(28660, 37365, 29375, 29169), 
             N2=c(86872, 91519, 141865, 101298), 
             N3=c(140498, 51092, 93889, 42368), 
             N4=c(76942, 49351, 82002, 36730))
chisq.test(df)

you will get:

X-squared = 62305, df = 9, p-value < 2.2e-16

it depends on what hypothesis you want to test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM