Hi James, You can change the order of levels like this: levels(viagraData$dose)<-c("placebo","low dose","high dose") Although I don't know the exact names of the variable and its levels. Jim On Fri, Jun 5, 2015 at 7:19 AM, Richard M. Heiberger <rmh at temple.edu> wrote:> This example is based on ?glht > >> data(warpbreaks) >> glht(amod, linfct = mcp(tension = "Dunnett")) > > General Linear Hypotheses > > Multiple Comparisons of Means: Dunnett Contrasts > > > Linear Hypotheses: > Estimate > M - L == 0 -10.0 > H - L == 0 -14.7 >> levels(warpbreaks$tension) > [1] "L" "M" "H" >> warpbreaks$tension <- factor(warpbreaks$tension, levels=c("H","M","L")) >> amod <- aov(breaks ~ tension, data = warpbreaks) >> glht(amod, linfct = mcp(tension = "Dunnett")) > > General Linear Hypotheses > > Multiple Comparisons of Means: Dunnett Contrasts > > > Linear Hypotheses: > Estimate > M - H == 0 4.72 > L - H == 0 14.72 > > > Changing the order of the levels is easy. Rearranging the data itself > is not necessary. > > Rich > > On Thu, Jun 4, 2015 at 3:42 PM, James F. Henson > <james_henson at suagcenter.com> wrote: >> Greetings >> >> Below is my code. >> >> library("multcomp") >> viaModel1 <- aov(libido ~ dose, data=viagraData) >> dunnettModel <- glht(viaModel1 , linfct = mcp(dose = "Dunnett"), base = "placebo") >> >> The code base="placebo" is ignored. All treatments are compared to the first treatment in the order, which is "high dose". It is possible to rearrange the order so that "placebo' is first, but this is inconvenient. >> >> Thanks, >> James F. Henson >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Sorry, Jim that doesn't do the right thing.> tmp <- factor(c("mm", "cm", "dm", "m", "km")) > levels(tmp)[1] "cm" "dm" "km" "m" "mm"> tmp[1] mm cm dm m km Levels: cm dm km m mm> levels(tmp) <- c("mm", "cm", "dm", "m", "km") > tmp[1] km mm cm m dm Levels: mm cm dm m km> ## back to the begining > tmp <- factor(c("mm", "cm", "dm", "m", "km")) > tmp[1] mm cm dm m km Levels: cm dm km m mm> tmp <- factor(tmp, levels=unique(tmp)) > tmp[1] mm cm dm m km Levels: mm cm dm m km>Rich On Thu, Jun 4, 2015 at 7:08 PM, Jim Lemon <drjimlemon at gmail.com> wrote:> Hi James, > You can change the order of levels like this: > > levels(viagraData$dose)<-c("placebo","low dose","high dose") > > Although I don't know the exact names of the variable and its levels. > > Jim > > On Fri, Jun 5, 2015 at 7:19 AM, Richard M. Heiberger <rmh at temple.edu> wrote: >> This example is based on ?glht >> >>> data(warpbreaks) >>> glht(amod, linfct = mcp(tension = "Dunnett")) >> >> General Linear Hypotheses >> >> Multiple Comparisons of Means: Dunnett Contrasts >> >> >> Linear Hypotheses: >> Estimate >> M - L == 0 -10.0 >> H - L == 0 -14.7 >>> levels(warpbreaks$tension) >> [1] "L" "M" "H" >>> warpbreaks$tension <- factor(warpbreaks$tension, levels=c("H","M","L")) >>> amod <- aov(breaks ~ tension, data = warpbreaks) >>> glht(amod, linfct = mcp(tension = "Dunnett")) >> >> General Linear Hypotheses >> >> Multiple Comparisons of Means: Dunnett Contrasts >> >> >> Linear Hypotheses: >> Estimate >> M - H == 0 4.72 >> L - H == 0 14.72 >> >> >> Changing the order of the levels is easy. Rearranging the data itself >> is not necessary. >> >> Rich >> >> On Thu, Jun 4, 2015 at 3:42 PM, James F. Henson >> <james_henson at suagcenter.com> wrote: >>> Greetings >>> >>> Below is my code. >>> >>> library("multcomp") >>> viaModel1 <- aov(libido ~ dose, data=viagraData) >>> dunnettModel <- glht(viaModel1 , linfct = mcp(dose = "Dunnett"), base = "placebo") >>> >>> The code base="placebo" is ignored. All treatments are compared to the first treatment in the order, which is "high dose". It is possible to rearrange the order so that "placebo' is first, but this is inconvenient. >>> >>> Thanks, >>> James F. Henson >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 05/06/15 11:08, Jim Lemon wrote:> Hi James, > You can change the order of levels like this: > > levels(viagraData$dose)<-c("placebo","low dose","high dose")<SNIP> As Richard Heiberger has pointed out, this is wrong. What *does* work is: viagraData$dose)<-factor(viagraData$dose, levels=c("placebo","low dose","high dose") This is a trap into which many a Young Player (including my very good self) has fallen. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Hello, everyone, aside from Rolf's hint (and Richard's warning!) you could also consider relevel(): viagraData$dose <- relevel( viagraData$dose, ref = "placebo") Hth -- Gerrit On Fri, 5 Jun 2015, Rolf Turner wrote:> On 05/06/15 11:08, Jim Lemon wrote: >> Hi James, >> You can change the order of levels like this: >> >> levels(viagraData$dose)<-c("placebo","low dose","high dose") > > <SNIP> > > As Richard Heiberger has pointed out, this is wrong. > > What *does* work is: > > viagraData$dose)<-factor(viagraData$dose, > levels=c("placebo","low dose","high dose") > > This is a trap into which many a Young Player (including my very good self) > has fallen. > > cheers, > > Rolf Turner > > > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.