Debian Codegraph @

man/tidy.lsmobj.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/emmeans.R
3 \name{tidy.lsmobj}
4 \alias{tidy.lsmobj}
5 \alias{emmeans_tidiers}
6 \title{Tidy a(n) lsmobj object}
7 \usage{
8 \method{tidy}{lsmobj}(x, conf.int = FALSE, conf.level = 0.95, ...)
9 }
10 \arguments{
11 \item{x}{An \code{lsmobj} object.}
12
13 \item{conf.int}{Logical indicating whether or not to include a confidence
14 interval in the tidied output. Defaults to \code{FALSE}.}
15
16 \item{conf.level}{The confidence level to use for the confidence interval
17 if \code{conf.int = TRUE}. Must be strictly greater than 0 and less than 1.
18 Defaults to 0.95, which corresponds to a 95 percent confidence interval.}
19
20 \item{...}{Additional arguments passed to \code{\link[emmeans:summary.emmGrid]{emmeans::summary.emmGrid()}} or
21 \code{\link[lsmeans:ref.grid]{lsmeans::summary.ref.grid()}}. \strong{Cautionary note}: misspecified arguments
22 may be silently ignored!}
23 }
24 \description{
25 Tidy summarizes information about the components of a model.
26 A model component might be a single term in a regression, a single
27 hypothesis, a cluster, or a class. Exactly what tidy considers to be a
28 model component varies across models but is usually self-evident.
29 If a model has several distinct types of components, you will need to
30 specify which components to return.
31 }
32 \details{
33 Returns a data frame with one observation for each estimated marginal
34 mean, and one column for each combination of factors. When the input is a
35 contrast, each row will contain one estimated contrast.
36
37 There are a large number of arguments that can be
38 passed on to \code{\link[emmeans:summary.emmGrid]{emmeans::summary.emmGrid()}} or \code{\link[lsmeans:ref.grid]{lsmeans::summary.ref.grid()}}.
39 }
40 \examples{
41 \dontshow{if (rlang::is_installed(c("emmeans", "ggplot2"))) withAutoprint(\{ # examplesIf}
42
43 # load libraries for models and data
44 library(emmeans)
45
46 # linear model for sales of oranges per day
47 oranges_lm1 <- lm(sales1 ~ price1 + price2 + day + store, data = oranges)
48
49 # reference grid; see vignette("basics", package = "emmeans")
50 oranges_rg1 <- ref_grid(oranges_lm1)
51 td <- tidy(oranges_rg1)
52 td
53
54 # marginal averages
55 marginal <- emmeans(oranges_rg1, "day")
56 tidy(marginal)
57
58 # contrasts
59 tidy(contrast(marginal))
60 tidy(contrast(marginal, method = "pairwise"))
61
62 # plot confidence intervals
63 library(ggplot2)
64
65 ggplot(tidy(marginal, conf.int = TRUE), aes(day, estimate)) +
66 geom_point() +
67 geom_errorbar(aes(ymin = conf.low, ymax = conf.high))
68
69 # by multiple prices
70 by_price <- emmeans(oranges_lm1, "day",
71 by = "price2",
72 at = list(
73 price1 = 50, price2 = c(40, 60, 80),
74 day = c("2", "3", "4")
75 )
76 )
77
78 by_price
79
80 tidy(by_price)
81
82 ggplot(tidy(by_price, conf.int = TRUE), aes(price2, estimate, color = day)) +
83 geom_line() +
84 geom_errorbar(aes(ymin = conf.low, ymax = conf.high))
85
86 # joint_tests
87 tidy(joint_tests(oranges_lm1))
88 \dontshow{\}) # examplesIf}
89 }
90 \seealso{
91 \code{\link[=tidy]{tidy()}}, \code{\link[emmeans:ref_grid]{emmeans::ref_grid()}}, \code{\link[emmeans:emmeans]{emmeans::emmeans()}},
92 \code{\link[emmeans:contrast]{emmeans::contrast()}}
93
94 Other emmeans tidiers:
95 \code{\link{tidy.emmGrid}()},
96 \code{\link{tidy.ref.grid}()},
97 \code{\link{tidy.summary_emm}()}
98 }
99 \concept{emmeans tidiers}
100 \value{
101 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
102 \item{conf.high}{Upper bound on the confidence interval for the estimate.}
103 \item{conf.low}{Lower bound on the confidence interval for the estimate.}
104 \item{contrast}{Levels being compared.}
105 \item{df}{Degrees of freedom used by this term in the model.}
106 \item{null.value}{Value to which the estimate is compared.}
107 \item{p.value}{The two-sided p-value associated with the observed statistic.}
108 \item{std.error}{The standard error of the regression term.}
109 \item{estimate}{Expected marginal mean}
110 \item{statistic}{T-ratio statistic}
111
112 }