Debian Codegraph @

man/glance.summary.lm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/stats-summary-lm.R
3 \name{glance.summary.lm}
4 \alias{glance.summary.lm}
5 \title{Glance at a(n) summary.lm object}
6 \usage{
7 \method{glance}{summary.lm}(x, ...)
8 }
9 \arguments{
10 \item{x}{An \code{lm} object created by \code{\link[stats:lm]{stats::lm()}}.}
11
12 \item{...}{Additional arguments. Not used. Needed to match generic
13 signature only. \strong{Cautionary note:} Misspelled arguments will be
14 absorbed in \code{...}, where they will be ignored. If the misspelled
15 argument has a default value, the default value will be used.
16 For example, if you pass \code{conf.lvel = 0.9}, all computation will
17 proceed using \code{conf.level = 0.95}. Two exceptions here are:
18 \itemize{
19 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
20 it will be ignored.
21 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
22 will be ignored.
23 }}
24 }
25 \description{
26 Glance accepts a model object and returns a \code{\link[tibble:tibble]{tibble::tibble()}}
27 with exactly one row of model summaries. The summaries are typically
28 goodness of fit measures, p-values for hypothesis tests on residuals,
29 or model convergence information.
30
31 Glance never returns information from the original call to the modeling
32 function. This includes the name of the modeling function or any
33 arguments passed to the modeling function.
34
35 Glance does not calculate summary measures. Rather, it farms out these
36 computations to appropriate methods and gathers the results together.
37 Sometimes a goodness of fit measure will be undefined. In these cases
38 the measure will be reported as \code{NA}.
39
40 Glance returns the same number of columns regardless of whether the
41 model matrix is rank-deficient or not. If so, entries in columns
42 that no longer have a well-defined value are filled in with an \code{NA}
43 of the appropriate type.
44 }
45 \details{
46 The \code{glance.summary.lm()} method is a potentially useful alternative
47 to \code{\link[=glance.lm]{glance.lm()}}. For instance, if users have already converted large \code{lm}
48 objects into their leaner \code{summary.lm} equivalents to conserve memory. Note,
49 however, that this method does not return all of the columns of the
50 non-summary method (e.g. AIC and BIC will be missing.)
51 }
52 \examples{
53 \dontshow{if (rlang::is_installed("ggplot2")) withAutoprint(\{ # examplesIf}
54
55 library(ggplot2)
56 library(dplyr)
57
58 mod <- lm(mpg ~ wt + qsec, data = mtcars)
59
60 tidy(mod)
61 glance(mod)
62
63 # coefficient plot
64 d <- tidy(mod, conf.int = TRUE)
65
66 ggplot(d, aes(estimate, term, xmin = conf.low, xmax = conf.high, height = 0)) +
67 geom_point() +
68 geom_vline(xintercept = 0, lty = 4) +
69 geom_errorbarh()
70
71 # aside: There are tidy() and glance() methods for lm.summary objects too.
72 # this can be useful when you want to conserve memory by converting large lm
73 # objects into their leaner summary.lm equivalents.
74 s <- summary(mod)
75 tidy(s, conf.int = TRUE)
76 glance(s)
77
78 augment(mod)
79 augment(mod, mtcars, interval = "confidence")
80
81 # predict on new data
82 newdata <- mtcars |>
83 head(6) |>
84 mutate(wt = wt + 1)
85 augment(mod, newdata = newdata)
86
87 # ggplot2 example where we also construct 95\% prediction interval
88
89 # simpler bivariate model since we're plotting in 2D
90 mod2 <- lm(mpg ~ wt, data = mtcars)
91
92 au <- augment(mod2, newdata = newdata, interval = "prediction")
93
94 ggplot(au, aes(wt, mpg)) +
95 geom_point() +
96 geom_line(aes(y = .fitted)) +
97 geom_ribbon(aes(ymin = .lower, ymax = .upper), col = NA, alpha = 0.3)
98
99 # predict on new data without outcome variable. Output does not include .resid
100 newdata <- newdata |>
101 select(-mpg)
102
103 augment(mod, newdata = newdata)
104
105 au <- augment(mod, data = mtcars)
106
107 ggplot(au, aes(.hat, .std.resid)) +
108 geom_vline(size = 2, colour = "white", xintercept = 0) +
109 geom_hline(size = 2, colour = "white", yintercept = 0) +
110 geom_point() +
111 geom_smooth(se = FALSE)
112
113 plot(mod, which = 6)
114
115 ggplot(au, aes(.hat, .cooksd)) +
116 geom_vline(xintercept = 0, colour = NA) +
117 geom_abline(slope = seq(0, 3, by = 0.5), colour = "white") +
118 geom_smooth(se = FALSE) +
119 geom_point()
120
121 # column-wise models
122 a <- matrix(rnorm(20), nrow = 10)
123 b <- a + rnorm(length(a))
124 result <- lm(b ~ a)
125
126 tidy(result)
127 \dontshow{\}) # examplesIf}
128 }
129 \seealso{
130 \code{\link[=glance]{glance()}}, \code{\link[=glance.summary.lm]{glance.summary.lm()}}
131
132 Other lm tidiers:
133 \code{\link{augment.glm}()},
134 \code{\link{augment.lm}()},
135 \code{\link{glance.glm}()},
136 \code{\link{glance.lm}()},
137 \code{\link{glance.svyglm}()},
138 \code{\link{tidy.glm}()},
139 \code{\link{tidy.lm}()},
140 \code{\link{tidy.lm.beta}()},
141 \code{\link{tidy.mlm}()},
142 \code{\link{tidy.summary.lm}()}
143 }
144 \concept{lm tidiers}
145 \value{
146 A \code{\link[tibble:tibble]{tibble::tibble()}} with exactly one row and columns:
147 \item{adj.r.squared}{Adjusted R squared statistic, which is like the R squared statistic except taking degrees of freedom into account.}
148 \item{df.residual}{Residual degrees of freedom.}
149 \item{nobs}{Number of observations used.}
150 \item{p.value}{P-value corresponding to the test statistic.}
151 \item{r.squared}{R squared statistic, or the percent of variation explained by the model. Also known as the coefficient of determination.}
152 \item{sigma}{Estimated standard error of the residuals.}
153 \item{statistic}{Test statistic.}
154 \item{df}{The degrees for freedom from the numerator of the overall
155 F-statistic. This is new in broom 0.7.0. Previously, this reported
156 the rank of the design matrix, which is one more than the numerator
157 degrees of freedom of the overall F-statistic.}
158
159 }