Debian Codegraph @

man/augment.fixest.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/fixest.R
3 \name{augment.fixest}
4 \alias{augment.fixest}
5 \title{Augment data with information from a(n) fixest object}
6 \usage{
7 \method{augment}{fixest}(
8 x,
9 data = NULL,
10 newdata = NULL,
11 type.predict = c("link", "response"),
12 type.residuals = c("response", "deviance", "pearson", "working"),
13 ...
14 )
15 }
16 \arguments{
17 \item{x}{A \code{fixest} object returned from any of the \code{fixest} estimators}
18
19 \item{data}{A \link[base:data.frame]{base::data.frame} or \code{\link[tibble:tibble]{tibble::tibble()}} containing the original
20 data that was used to produce the object \code{x}. Defaults to
21 \code{stats::model.frame(x)} so that \code{augment(my_fit)} returns the augmented
22 original data. \strong{Do not} pass new data to the \code{data} argument.
23 Augment will report information such as influence and cooks distance for
24 data passed to the \code{data} argument. These measures are only defined for
25 the original training data.}
26
27 \item{newdata}{A \code{\link[base:data.frame]{base::data.frame()}} or \code{\link[tibble:tibble]{tibble::tibble()}} containing all
28 the original predictors used to create \code{x}. Defaults to \code{NULL}, indicating
29 that nothing has been passed to \code{newdata}. If \code{newdata} is specified,
30 the \code{data} argument will be ignored.}
31
32 \item{type.predict}{Passed to \code{\link[fixest:predict.fixest]{predict.fixest}}
33 \code{type} argument. Defaults to \code{"link"} (like \code{predict.glm}).}
34
35 \item{type.residuals}{Passed to \code{\link[fixest:resid.fixest]{predict.fixest}}
36 \code{type} argument. Defaults to \code{"response"} (like \code{residuals.lm}, but unlike
37 \code{residuals.glm}).}
38
39 \item{...}{Additional arguments passed to \code{summary} and \code{confint}. Important
40 arguments are \code{se} and \code{cluster}. Other arguments are \code{dof}, \code{exact_dof},
41 \code{forceCovariance}, and \code{keepBounded}.
42 See \code{\link[fixest:summary.fixest]{summary.fixest}}.}
43 }
44 \description{
45 Augment accepts a model object and a dataset and adds
46 information about each observation in the dataset. Most commonly, this
47 includes predicted values in the \code{.fitted} column, residuals in the
48 \code{.resid} column, and standard errors for the fitted values in a \code{.se.fit}
49 column. New columns always begin with a \code{.} prefix to avoid overwriting
50 columns in the original dataset.
51
52 Users may pass data to augment via either the \code{data} argument or the
53 \code{newdata} argument. If the user passes data to the \code{data} argument,
54 it \strong{must} be exactly the data that was used to fit the model
55 object. Pass datasets to \code{newdata} to augment data that was not used
56 during model fitting. This still requires that at least all predictor
57 variable columns used to fit the model are present. If the original outcome
58 variable used to fit the model is not included in \code{newdata}, then no
59 \code{.resid} column will be included in the output.
60
61 Augment will often behave differently depending on whether \code{data} or
62 \code{newdata} is given. This is because there is often information
63 associated with training observations (such as influences or related)
64 measures that is not meaningfully defined for new observations.
65
66 For convenience, many augment methods provide default \code{data} arguments,
67 so that \code{augment(fit)} will return the augmented training data. In these
68 cases, augment tries to reconstruct the original data based on the model
69 object with varying degrees of success.
70
71 The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the
72 \strong{same number of rows} as the passed dataset. This means that the passed
73 data must be coercible to a tibble. If a predictor enters the model as part
74 of a matrix of covariates, such as when the model formula uses
75 \code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented
76 as a matrix column.
77
78 We are in the process of defining behaviors for models fit with various
79 \code{na.action} arguments, but make no guarantees about behavior when data is
80 missing at this time.
81 }
82 \note{
83 Important note: \code{fixest} models do not include a copy of the input
84 data, so you must provide it manually.
85
86 augment.fixest only works for \code{\link[fixest:feols]{fixest::feols()}}, \code{\link[fixest:feglm]{fixest::feglm()}}, and
87 \code{\link[fixest:femlm]{fixest::femlm()}} models. It does not work with results from
88 \code{\link[fixest:femlm]{fixest::fenegbin()}}, \code{\link[fixest:feNmlm]{fixest::feNmlm()}}, or \code{\link[fixest:feglm]{fixest::fepois()}}.
89 }
90 \examples{
91 \dontshow{if (rlang::is_installed("fixest") & !broom:::is_cran_check()) withAutoprint(\{ # examplesIf}
92
93 # load libraries for models and data
94 library(fixest)
95
96 gravity <-
97 feols(
98 log(Euros) ~ log(dist_km) | Origin + Destination + Product + Year, trade
99 )
100
101 tidy(gravity)
102 glance(gravity)
103 augment(gravity, trade)
104
105 # to get robust or clustered SEs, users can either:
106
107 # 1) specify the arguments directly in the `tidy()` call
108
109 tidy(gravity, conf.int = TRUE, cluster = c("Product", "Year"))
110
111 tidy(gravity, conf.int = TRUE, se = "threeway")
112
113 # 2) or, feed tidy() a summary.fixest object that has already accepted
114 # these arguments
115
116 gravity_summ <- summary(gravity, cluster = c("Product", "Year"))
117
118 tidy(gravity_summ, conf.int = TRUE)
119
120 # approach (1) is preferred.
121 \dontshow{\}) # examplesIf}
122 }
123 \seealso{
124 \code{\link[=augment]{augment()}}, \code{\link[fixest:feglm]{fixest::feglm()}}, \code{\link[fixest:femlm]{fixest::femlm()}}, \code{\link[fixest:feols]{fixest::feols()}}
125
126 Other fixest tidiers:
127 \code{\link{tidy.fixest}()}
128 }
129 \concept{fixest tidiers}
130 \value{
131 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
132 \item{.fitted}{Fitted or predicted value.}
133 \item{.resid}{The difference between observed and fitted values.}
134
135 }