Debian Codegraph @

man/augment.felm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/lfe.R
3 \name{augment.felm}
4 \alias{augment.felm}
5 \title{Augment data with information from a(n) felm object}
6 \usage{
7 \method{augment}{felm}(x, data = model.frame(x), ...)
8 }
9 \arguments{
10 \item{x}{A \code{felm} object returned from \code{\link[lfe:felm]{lfe::felm()}}.}
11
12 \item{data}{A \link[base:data.frame]{base::data.frame} or \code{\link[tibble:tibble]{tibble::tibble()}} containing the original
13 data that was used to produce the object \code{x}. Defaults to
14 \code{stats::model.frame(x)} so that \code{augment(my_fit)} returns the augmented
15 original data. \strong{Do not} pass new data to the \code{data} argument.
16 Augment will report information such as influence and cooks distance for
17 data passed to the \code{data} argument. These measures are only defined for
18 the original training data.}
19
20 \item{...}{Additional arguments. Not used. Needed to match generic
21 signature only. \strong{Cautionary note:} Misspelled arguments will be
22 absorbed in \code{...}, where they will be ignored. If the misspelled
23 argument has a default value, the default value will be used.
24 For example, if you pass \code{conf.lvel = 0.9}, all computation will
25 proceed using \code{conf.level = 0.95}. Two exceptions here are:
26 \itemize{
27 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
28 it will be ignored.
29 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
30 will be ignored.
31 }}
32 }
33 \description{
34 Augment accepts a model object and a dataset and adds
35 information about each observation in the dataset. Most commonly, this
36 includes predicted values in the \code{.fitted} column, residuals in the
37 \code{.resid} column, and standard errors for the fitted values in a \code{.se.fit}
38 column. New columns always begin with a \code{.} prefix to avoid overwriting
39 columns in the original dataset.
40
41 Users may pass data to augment via either the \code{data} argument or the
42 \code{newdata} argument. If the user passes data to the \code{data} argument,
43 it \strong{must} be exactly the data that was used to fit the model
44 object. Pass datasets to \code{newdata} to augment data that was not used
45 during model fitting. This still requires that at least all predictor
46 variable columns used to fit the model are present. If the original outcome
47 variable used to fit the model is not included in \code{newdata}, then no
48 \code{.resid} column will be included in the output.
49
50 Augment will often behave differently depending on whether \code{data} or
51 \code{newdata} is given. This is because there is often information
52 associated with training observations (such as influences or related)
53 measures that is not meaningfully defined for new observations.
54
55 For convenience, many augment methods provide default \code{data} arguments,
56 so that \code{augment(fit)} will return the augmented training data. In these
57 cases, augment tries to reconstruct the original data based on the model
58 object with varying degrees of success.
59
60 The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the
61 \strong{same number of rows} as the passed dataset. This means that the passed
62 data must be coercible to a tibble. If a predictor enters the model as part
63 of a matrix of covariates, such as when the model formula uses
64 \code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented
65 as a matrix column.
66
67 We are in the process of defining behaviors for models fit with various
68 \code{na.action} arguments, but make no guarantees about behavior when data is
69 missing at this time.
70 }
71 \examples{
72 \dontshow{if (rlang::is_installed("lfe")) withAutoprint(\{ # examplesIf}
73
74 # load libraries for models and data
75 library(lfe)
76
77 # use built-in `airquality` dataset
78 head(airquality)
79
80 # no FEs; same as lm()
81 est0 <- felm(Ozone ~ Temp + Wind + Solar.R, airquality)
82
83 # summarize model fit with tidiers
84 tidy(est0)
85 augment(est0)
86
87 # add month fixed effects
88 est1 <- felm(Ozone ~ Temp + Wind + Solar.R | Month, airquality)
89
90 # summarize model fit with tidiers
91 tidy(est1)
92 tidy(est1, fe = TRUE)
93 augment(est1)
94 glance(est1)
95
96 # the "se.type" argument can be used to switch out different standard errors
97 # types on the fly. In turn, this can be useful exploring the effect of
98 # different error structures on model inference.
99 tidy(est1, se.type = "iid")
100 tidy(est1, se.type = "robust")
101
102 # add clustered SEs (also by month)
103 est2 <- felm(Ozone ~ Temp + Wind + Solar.R | Month | 0 | Month, airquality)
104
105 # summarize model fit with tidiers
106 tidy(est2, conf.int = TRUE)
107 tidy(est2, conf.int = TRUE, se.type = "cluster")
108 tidy(est2, conf.int = TRUE, se.type = "robust")
109 tidy(est2, conf.int = TRUE, se.type = "iid")
110 \dontshow{\}) # examplesIf}
111 }
112 \seealso{
113 \code{\link[=augment]{augment()}}, \code{\link[lfe:felm]{lfe::felm()}}
114
115 Other felm tidiers:
116 \code{\link{tidy.felm}()}
117 }
118 \concept{felm tidiers}
119 \value{
120 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
121 \item{.fitted}{Fitted or predicted value.}
122 \item{.resid}{The difference between observed and fitted values.}
123
124 }