Issue
I want to format the results of a GLHT from multcomp package as a table in a Rmarkdown file, the output being a HTML.
library(multcomp)
post_hoc <- glht(tick_oneway, linfct = mcp(Habitat = "Tukey"))
summary(post_hoc)
I'm getting an error that Rmarkdown doesn't know what to do with the summary if I apply pander or kable or as_flextable.
## Warning in pander.default(summary(post_hoc)): No pander.method for
## "summary.glht", reverting to default.No pander.method for "glht", reverting to
## default.
I tried using kable, pander and flextable yet they all failed. I'm most likely doing something in order to display them in a Rmarkdown HTML document.
Does anyone know how can shape the output of summary so that the input is accepted?
Solution
You could use tidy()
from the {broom}
package, e.g.
---
output: html_document
---
```{r message=FALSE, warning=FALSE}
library(multcomp)
# example from the package
lmod <- lm(Fertility ~ ., data = swiss)
K <- diag(length(coef(lmod)))[-1,]
rownames(K) <- names(coef(lmod))[-1]
### set up general linear hypothesis
post_hoc <- glht(lmod, linfct = K)
post_hoc |>
broom::tidy() |>
dplyr::mutate(signif = gtools::stars.pval(adj.p.value)) |>
kableExtra::kbl(digits = 2) |>
kableExtra::kable_styling()
```
Answered By - Julian
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.