RE: [R] chisq.test and anova problems

From: John Fox <>
Date: Tue 07 Jun 2005 - 04:12:32 EST

Dear Richard,

> -----Original Message-----
> From:
> [] On Behalf Of Richard Mendes
> Sent: Monday, June 06, 2005 8:44 AM
> To:
> Subject: [R] chisq.test and anova problems
> we just started to use R and having some problems that no one
> in our school could solve. I hope someone here can help me out.
> the first problem is with the chisquare test. we want to
> exclude the missing values from the data. we used na.omit and
> made two new variables.
> now we want to use the chi square method but get the error x
> and y must have the same length.
> how do i use the chisquare method were i exclude the missing values ?
> and can i use this method if there is a difference in length.

Take a look at the help file for chisq.test (e.g., ?chisq.test): Missing data are excluded when the contingency table for x and y is formed, so you need do nothing special to get what you want -- just chisq.test(x, y).

> the second problem is with anova in the data set we are
> working on we have to use this method on multiple variables
> with a difference in length, can this be done. this is the
> syntax we used and the error is stated behind.
> anova(lm(test~test1)) and the error states variable length differ.

I'm guessing that test and test1 are two samples on the response variable that you want to compare, though that's not entirely clear from your question. To do a one-way anova via lm(), you should have all of the observations on the response in one variable and a factor giving group membership of each observation; then anova(lm(response~factor)) will give you the one-way ANOVA table. Also take a look at ?aov. Finally, if I've correctly guessed what you're trying to do, then t.test(test, test1) is an alternative.

More generally, have you looked at the introductory manual that comes with R?

I hope this helps,

> i think there has to be a way to use this method on
> differences in variable lengths does anybode know how to do this
> thanks in advance for your help
> richard mailing list PLEASE do read the posting guide! Received on Tue Jun 07 04:17:07 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:23 EST