Home > Blockchain >  Chi Square Test - Error in sum(x) : invalid 'type' (character) of argument
Chi Square Test - Error in sum(x) : invalid 'type' (character) of argument

Time:11-03

I'm trying to do a Chi-Square Test on a data frame (a CSV) as below:

Lion Elephant
Lion 32 19
Elephant 11 27

And I have use the below code for the analysis:

aovdata <- read.csv("Jungle.csv", header = T)
aovdata

attach (aovdata)

Lion <- as.factor("Lion")
Elephant <- as.factor("Elephant")
class(Lion)
class(Elephant)

str(aovdata)

model <- chisq.test(aovdata)
model

then I receive the error

Error in sum(x) : invalid 'type' (character) of argument

can someone please let me know where have I got it wrong and what's the solution?

Thanks,

EDITED* Apologise I didn't write it clearly. So the table represents the sequence of animal observed between camera one and two. (i.e. Lion-Lion ; Lion-Elephant ; Elephant-Lion ; Elephant-Elephant

CodePudding user response:

We could do the chisq.test on the data itself as both are numeric columns

chisq.test(aovdata)

Regarding the use of

Lion <- as.factor("Lion")

It is just creating a string "Lion" as factor and storing it in Lion object name

data

aovdata <- structure(list(Lion = c(32, 11), Elephant = c(19, 27)), 
class = "data.frame", row.names = c("Lion", 
"Elephant"))
  • Related