Grokbase Groups R r-help March 2002
FAQ
Hi all

I'm trying to complete a textbook example originally designed for SPSS
in R, and I therefore need to find out how to compute an unbalanced
ANOVA in R.

I did a search on the mailinglist archives an found a post by Prof.
Ripley saying one should use the lme function for (among other things)
unbalanced ANOVAs, but I have not been able to use this object.
My code gives me an error.. Why is that ?
aov(lme(DELAY ~ DOSE + TRIALS,data=epinuneq))
Error in getGroups.data.frame(dataMix, groups) :
Invalid formula for groups
Any ideas? How do I get an ANOVA computation that can handle uniqual
sampe sizes in R?

/Fredrik

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Search Discussions

  • Prof Brian D Ripley at Mar 8, 2002 at 6:24 am

    On Fri, 8 Mar 2002, Fredrik Karlsson wrote:

    Hi all

    I'm trying to complete a textbook example originally designed for SPSS
    in R, and I therefore need to find out how to compute an unbalanced
    ANOVA in R.

    I did a search on the mailinglist archives an found a post by Prof.
    Ripley saying one should use the lme function for (among other things)
    unbalanced ANOVAs, but I have not been able to use this object.
    My code gives me an error.. Why is that ?
    aov(lme(DELAY ~ DOSE + TRIALS,data=epinuneq))
    Error in getGroups.data.frame(dataMix, groups) :
    Invalid formula for groups
    Any ideas? How do I get an ANOVA computation that can handle uniqual
    sampe sizes in R?
    I said use lme, *not* aov and lme. Note, though, that the advice applied
    to multistrata unbalanced anova, and this appears to be a two-way layout in
    one stratum. You can use aov for that. (You can't use lme unless there are
    two or more strata.) Just be careful how you interpret the output: in SAS
    parlance aov gives you `Type I' sums of squares.

    The reason why this is more difficult in R is that R unlike SPSS does not
    guess which of the many possible interpretations you mean. We would need
    to know a lot more about the actual statistical problem to tell you what
    would be a good analysis in R.

    Maybe you should look at a textbook designed for use with S/R not SPSS?

    --
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Fredrik Karlsson at Mar 8, 2002 at 1:34 pm
    Thank you Professor Ripley for the quick and informative response.

    Being unable to choose a different textbook (even though I must admit
    that this SPSS obsession is starting to annoy me).
    I solved the problem though.

    I changed the subject for this post in order to change the topic into
    a more general one:

    What does aov() do and what does it NOT do?
    Prof. Ripley mentioned that you should use the lme() function for
    multistrata anova, so that's one. What else? (Realising that this is a
    question with an open set of answers).

    My impression is that what I am suppose do do in SPSS under some heading
    n-way anova, ancova, one-way glm or whatever is handled in S/R by aov()

    Does this mean you can use aov() to compare two groups with different
    ns?

    Many open questions, I know, but the SPSS -> R translation is troubling
    for me.

    Please, could someone sort this out for me?

    /Fredrik

    On Fri, Mar 08, 2002 at 06:24:27AM +0000, Prof Brian D Ripley wrote:
    On Fri, 8 Mar 2002, Fredrik Karlsson wrote:

    Hi all

    I'm trying to complete a textbook example originally designed for SPSS
    in R, and I therefore need to find out how to compute an unbalanced
    ANOVA in R.

    I did a search on the mailinglist archives an found a post by Prof.
    Ripley saying one should use the lme function for (among other things)
    unbalanced ANOVAs, but I have not been able to use this object.
    My code gives me an error.. Why is that ?
    aov(lme(DELAY ~ DOSE + TRIALS,data=epinuneq))
    Error in getGroups.data.frame(dataMix, groups) :
    Invalid formula for groups
    Any ideas? How do I get an ANOVA computation that can handle uniqual
    sampe sizes in R?
    I said use lme, *not* aov and lme. Note, though, that the advice applied
    to multistrata unbalanced anova, and this appears to be a two-way layout in
    one stratum. You can use aov for that. (You can't use lme unless there are
    two or more strata.) Just be careful how you interpret the output: in SAS
    parlance aov gives you `Type I' sums of squares.

    The reason why this is more difficult in R is that R unlike SPSS does not
    guess which of the many possible interpretations you mean. We would need
    to know a lot more about the actual statistical problem to tell you what
    would be a good analysis in R.

    Maybe you should look at a textbook designed for use with S/R not SPSS?

    --
    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
    --
    -----------------------------------------------------------------
    Fredrik Karlsson, Research Student

    Department of Philosophy and Linguistics
    Ume? University
    S-901 87 UME?
    SWEDEN
    Tel: +46 90 786 56 84 Web: http://www.ling.umu.se/~fredrik/
    Fax: +46 90 786 63 77 Email: fredrik at ling.umu.se
    PGP-fingerprint:2DD5 54A1 4555 6D00 F386 C269 C430 0C0F 1A53 49B9
    -----------------------------------------------------------------
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Ripley at Mar 8, 2002 at 1:59 pm

    On Fri, 8 Mar 2002, Fredrik Karlsson wrote:

    Thank you Professor Ripley for the quick and informative response.

    Being unable to choose a different textbook (even though I must admit
    that this SPSS obsession is starting to annoy me).
    You could read a textbook on S/R which would explain what aov does. As I
    understand it John Fox's car package is designed (amongst other things) to
    make R easier for diehard SPSS users, so you ought to find that useful.
    I solved the problem though.

    I changed the subject for this post in order to change the topic into
    a more general one:

    What does aov() do and what does it NOT do?
    Prof. Ripley mentioned that you should use the lme() function for
    multistrata anova, so that's one. What else? (Realising that this is a
    question with an open set of answers).
    No, for *unbalanced* multistrata anova (and that's the second time you
    have quoted me out of context: please be more careful!). For balanced
    desigms, aov() is the preferred tool. It's also general for unbalanced
    fixed-effects models, but for some lm will be able to interpret.
    My impression is that what I am suppose do do in SPSS under some heading
    n-way anova, ancova, one-way glm or whatever is handled in S/R by aov()

    Does this mean you can use aov() to compare two groups with different
    ns?
    You can, but that's the job of t.test.
    Many open questions, I know, but the SPSS -> R translation is troubling
    for me.
    It's troubling for us. SPSS is often grossly misleading in its
    terminology.

    --
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Vito muggeo at Mar 8, 2002 at 8:46 am
    The lme() function doesn't need aov(). So you would type:

    lme(DELAY ~ DOSE + TRIALS,data=epinuneq)

    however see ?lme o some book about mixed models: you need to specify the
    random part and "clustering" variable (e.g. id-subject in a repeated
    measurement design). Something like

    lme(DELAY ~ DOSE + TRIALS, random=~1|your_cluster_variable, data=epinuneq)

    best,
    vito

    After all, I don't think that simple "unbalanced ANOVA" and mixed models are
    the same!


    ----- Original Message -----
    From: "Fredrik Karlsson" <fredrik.karlsson@ling.umu.se>
    To: "r-help-request Mailing List" <r-help@r-project.org>
    Sent: Friday, March 08, 2002 6:56 AM
    Subject: [R] Unbalanced ANOVA in R?

    Hi all

    I'm trying to complete a textbook example originally designed for SPSS
    in R, and I therefore need to find out how to compute an unbalanced
    ANOVA in R.

    I did a search on the mailinglist archives an found a post by Prof.
    Ripley saying one should use the lme function for (among other things)
    unbalanced ANOVAs, but I have not been able to use this object.
    My code gives me an error.. Why is that ?
    aov(lme(DELAY ~ DOSE + TRIALS,data=epinuneq))
    Error in getGroups.data.frame(dataMix, groups) :
    Invalid formula for groups
    Any ideas? How do I get an ANOVA computation that can handle uniqual
    sampe sizes in R?

    /Fredrik

    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.-
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • John Fox at Mar 8, 2002 at 1:05 pm
    Dear Fredrik,
    At 06:56 AM 3/8/2002 +0100, Fredrik Karlsson wrote:
    Hi all

    I'm trying to complete a textbook example originally designed for SPSS
    in R, and I therefore need to find out how to compute an unbalanced
    ANOVA in R.

    I did a search on the mailinglist archives an found a post by Prof.
    Ripley saying one should use the lme function for (among other things)
    unbalanced ANOVAs, but I have not been able to use this object.
    My code gives me an error.. Why is that ?
    aov(lme(DELAY ~ DOSE + TRIALS,data=epinuneq))
    Error in getGroups.data.frame(dataMix, groups) :
    Invalid formula for groups
    Any ideas? How do I get an ANOVA computation that can handle uniqual
    sampe sizes in R?
    The lme function is designed for linear mixed models, that is, models
    including both fixed and random effects. It's hard to tell from the
    information that you provide whether a mixed model is appropriate for your
    data -- in particular, is TRIALS a repeated-measures factor? If you indeed
    need to fit a mixed model, then you haven't specified it correctly. See the
    help page for lme for details.

    On the other hand, if you just want to fit a fixed-effects Anova with no
    interactions, then you can use the aov or lm functions. Again, see
    help(aov) and help(lm). The summary method for aov and the anova method for
    both aov and lm objects will give you sequential ("type I") sums of
    squares. The Anova function in the car package can compute "Type II" and
    "III" sums of squares for lm objects. If you use the latter, be careful
    with the contrast coding.

    I hope that this helps,
    John

    -----------------------------------------------------
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedMar 8, '02 at 5:56a
activeMar 8, '02 at 1:59p
posts6
users4
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase