Debian Codegraph @

man/glance.margins.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/margins.R
3 \name{glance.margins}
4 \alias{glance.margins}
5 \title{Glance at a(n) margins object}
6 \usage{
7 \method{glance}{margins}(x, ...)
8 }
9 \arguments{
10 \item{x}{A \code{margins} object returned from \code{\link[margins:margins]{margins::margins()}}.}
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 \examples{
46 \dontshow{if (rlang::is_installed("margins")) withAutoprint(\{ # examplesIf}
47
48 # load libraries for models and data
49 library(margins)
50
51 # example 1: logit model
52 mod_log <- glm(am ~ cyl + hp + wt, data = mtcars, family = binomial)
53
54 # get tidied "naive" model coefficients
55 tidy(mod_log)
56
57 # convert to marginal effects with margins()
58 marg_log <- margins(mod_log)
59
60 # get tidied marginal effects
61 tidy(marg_log)
62 tidy(marg_log, conf.int = TRUE)
63
64 # requires running the underlying model again. quick for this example
65 glance(marg_log)
66
67 # augmenting `margins` outputs isn't supported, but
68 # you can get the same info by running on the underlying model
69 augment(mod_log)
70
71 # example 2: threeway interaction terms
72 mod_ie <- lm(mpg ~ wt * cyl * disp, data = mtcars)
73
74 # get tidied "naive" model coefficients
75 tidy(mod_ie)
76
77 # convert to marginal effects with margins()
78 marg_ie0 <- margins(mod_ie)
79 # get tidied marginal effects
80 tidy(marg_ie0)
81 glance(marg_ie0)
82
83 # marginal effects evaluated at specific values of a variable (here: cyl)
84 marg_ie1 <- margins(mod_ie, at = list(cyl = c(4,6,8)))
85
86 # summarize model fit with tidiers
87 tidy(marg_ie1)
88
89 # marginal effects of one interaction variable (here: wt), modulated at
90 # specific values of the two other interaction variables (here: cyl and drat)
91 marg_ie2 <- margins(mod_ie,
92 variables = "wt",
93 at = list(cyl = c(4,6,8), drat = c(3, 3.5, 4)))
94
95 # summarize model fit with tidiers
96 tidy(marg_ie2)
97 \dontshow{\}) # examplesIf}
98 }
99 \value{
100 A \code{\link[tibble:tibble]{tibble::tibble()}} with exactly one row and columns:
101 \item{adj.r.squared}{Adjusted R squared statistic, which is like the R squared statistic except taking degrees of freedom into account.}
102 \item{df}{Degrees of freedom used by the model.}
103 \item{df.residual}{Residual degrees of freedom.}
104 \item{nobs}{Number of observations used.}
105 \item{p.value}{P-value corresponding to the test statistic.}
106 \item{r.squared}{R squared statistic, or the percent of variation explained by the model. Also known as the coefficient of determination.}
107 \item{sigma}{Estimated standard error of the residuals.}
108 \item{statistic}{Test statistic.}
109
110 }