Hi everyone, I've got a problem with an analysis of variance where it appears that my independent variable is being treated as an integer when it should be nominal. The data are being loaded from an SPSS file and the independent variable 'YearColl' corresponds (surprisingly enough) to a student's year in college. :-) The integers 1-4 are used in the dataset for this purpose. My quick little anova gives this result:> mir.aov <- aov(DepressT ~ YearColl, data=mir) > summary(mir.aov)Df Sum Sq Mean Sq F value Pr(>F) YearColl 1 955.7 955.7 10.305 0.001474 ** Residuals 293 27172.5 92.7 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 I was expecting the df for YearColl to be (k-1) = 3. Am I reading this right? Is there a way to force integers to act like nominal data? -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson at visi.com | <dtml-var pithy_quote> | http://linux.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 7 Aug 2002, Tim Wilson wrote:> I've got a problem with an analysis of variance where it appears that my > independent variable is being treated as an integer when it should be > nominal. > > The data are being loaded from an SPSS file and the independent variable > 'YearColl' corresponds (surprisingly enough) to a student's year in > college. :-) The integers 1-4 are used in the dataset for this purpose. > My quick little anova gives this result: > > > mir.aov <- aov(DepressT ~ YearColl, data=mir) > > summary(mir.aov) > Df Sum Sq Mean Sq F value Pr(>F) > YearColl 1 955.7 955.7 10.305 0.001474 ** > Residuals 293 27172.5 92.7 > --- > Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > > I was expecting the df for YearColl to be (k-1) = 3. > > Am I reading this right? Is there a way to force integers to act like > nominal data?What you mean is that you want YearColl to be a factor and so coded. as.factor() will help. R has no idea what you meant: you gave it an integer variable, and it handled it as such. Don't be surprised if R does as it is told. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Hi everyone, > > I've got a problem with an analysis of variance where it appears that my > independent variable is being treated as an integer when it should be > nominal. >see ?(as.)factor Torsten> The data are being loaded from an SPSS file and the independent variable > 'YearColl' corresponds (surprisingly enough) to a student's year in > college. :-) The integers 1-4 are used in the dataset for this purpose. > My quick little anova gives this result: > > > mir.aov <- aov(DepressT ~ YearColl, data=mir) > > summary(mir.aov) > Df Sum Sq Mean Sq F value Pr(>F) > YearColl 1 955.7 955.7 10.305 0.001474 ** > Residuals 293 27172.5 92.7 > --- > Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > > I was expecting the df for YearColl to be (k-1) = 3. > > Am I reading this right? Is there a way to force integers to act like > nominal data? > > -Tim > > -- > Tim Wilson | Visit Sibley online: | Check out: > Henry Sibley HS | http://www.isd197.org | http://www.zope.com > W. St. Paul, MN | | http://slashdot.org > wilson at visi.com | <dtml-var pithy_quote> | http://linux.com > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Tim, As has been pointed out, you need to ensure that YearColl is coerced to a factor. The read.spss function by default converts variables to factors when they have value labels in the SPSS data set; otherwise numeric variables without value labels remain numeric. See help(read.spss). I hope that this helps, John At 02:10 AM 8/7/2002 -0500, Tim Wilson wrote:>Hi everyone, > >I've got a problem with an analysis of variance where it appears that my >independent variable is being treated as an integer when it should be >nominal. > >The data are being loaded from an SPSS file and the independent variable >'YearColl' corresponds (surprisingly enough) to a student's year in >college. :-) The integers 1-4 are used in the dataset for this purpose. >My quick little anova gives this result: > > > mir.aov <- aov(DepressT ~ YearColl, data=mir) > > summary(mir.aov) > Df Sum Sq Mean Sq F value Pr(>F) >YearColl 1 955.7 955.7 10.305 0.001474 ** >Residuals 293 27172.5 92.7 >--- >Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > >I was expecting the df for YearColl to be (k-1) = 3. > >Am I reading this right? Is there a way to force integers to act like >nominal data?----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._