> chisq.test(Group4_subset$Mood.Change, p = c(1/4, 1/4, 1/4, 1/4)
But I get this error:
Error in if (any(x < 0) || anyNA(x)) stop("all entries of 'x' must be nonnegative and finite") :
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(x, 0) : ‘<’ not meaningful for factors
How would I rectify this? Also, it would be great if someone can address my question in my linked post.
It looks like the column that you are passing to chisq.test() is a factor. You have to give the test numeric data of the counts in each category, the data produced by the table() function. In the code below, I reproduce your error and then successfully do a test using the result of table().
#invent data
Moods <- c("Declined","Improved","Neg","Pos")
DF <- data.frame(Mood=sample(Moods,100,replace=TRUE),stringsAsFactors = TRUE)
table(DF$Mood)
#>
#> Declined Improved Neg Pos
#> 28 22 27 23
chisq.test(DF$Mood)
#> Warning in Ops.factor(x, 0): '<' not meaningful for factors
#> Error in if (any(x < 0) || anyNA(x)) stop("all entries of 'x' must be nonnegative and finite"): missing value where TRUE/FALSE needed
chisq.test(table(DF$Mood))
#>
#> Chi-squared test for given probabilities
#>
#> data: table(DF$Mood)
#> X-squared = 1.04, df = 3, p-value = 0.7916