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

Hi,

I'm trying to run chi-square the frequency of four groups (Improved, negatively maintained, positively maintained and declined).


> table (Group4_subset$Mood.Change)

      Declined       Improved Neg_maintained Pos_maintained 
             3             57             35             53 

I've tried running:

> chisq.test(Group4_subset$Mood.Change, correct=FALSE)

But get this error:

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

How can I get around this?

Many thanks in advance!
Phoenix

I'm thinking you intend:

chisq.test(table(Group4_subset$Mood.Change), correct=FALSE)
1 Like

Looking at the documentation for chisq.test(), you need to pass it either the contingency table or two factors to be compared. So you can pass it the one-way table you created to test the null hypothesis that the four groups are equally large. But is this really what you are trying to do?

Hi,

Thank you for your input, it is greatly appreciated!
I have another question, when creating a contingency table prior to performing other chi-square or fisher tests the outputted table never looks like the examples I've seen, I was just wondering if this is an issue?

For example:

> table(Group2_subset$Mood.Change, Group2_subset$Viewed.With)

                      Alone    Someone
  Improved       45     12       0
  Neg_maintained 28      5       2

I'm not too sure what the 48 and 28 means and if these seemingly irrelevant numbers are included in my chi-square/fisher calculations?

Thanks,
Phoenix

I see 28 but not 48 ?

Viewed.With probably has na values.
Add the useNA="always" parameter to the table call.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.