Skip to content

Instantly share code, notes, and snippets.

@ito4303
Created December 22, 2022 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ito4303/661f7eb33b28cd96272a30a3eed5aa5e to your computer and use it in GitHub Desktop.
Save ito4303/661f7eb33b28cd96272a30a3eed5aa5e to your computer and use it in GitHub Desktop.
An example to use glht function in the multcomp package
---
title: "R Notebook"
output: html_notebook
---
## An example to use glht function in the multcomp package
```{r setup}
library(multcomp)
library(palmerpenguins)
```
### View data
plot bill_length_mm vs. species
```{r}
png("plot01.png", width = 480, height = 480, pointsize = 14)
boxplot(bill_length_mm ~ species, data = penguins)
dev.off()
```
### Multiple comparison
```{r}
bill_l.glht <- lm(bill_length_mm ~ species, data = penguins) |>
glht(linfct = mcp("species" = "Tukey"))
summary(bill_l.glht)
```
### Plot the results
```{r}
png("plot02.png", width = 480, height = 520, pointsize = 14)
par(mai = c(1, 1, 1.25, 1))
cld(bill_l.glht ) |>
plot()
dev.off()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment