Augment accepts a model object and a dataset and adds information about each observation in the dataset. Most commonly, this includes predicted values in the .fitted column, residuals in the .resid column, and standard errors for the fitted values in a .se.fit column. New columns always begin with a . prefix to avoid overwriting columns in the original dataset.

Users may pass data to augment via either the data argument or the newdata argument. If the user passes data to the data argument, it must be exactly the data that was used to fit the model object. Pass datasets to newdata to augment data that was not used during model fitting. This still requires that all columns used to fit the model are present.

Augment will often behavior different depending on whether data or newdata is specified. This is because there is often information associated with training observations (such as influences or related) measures that is not meaningfully defined for new observations.

For convenience, many augment methods provide default data arguments, so that augment(fit) will return the augmented training data. In these cases augment tries to reconstruct the original data based on the model object, with some varying degrees of success.

The augmented dataset is always returned as a tibble::tibble with the same number of rows as the passed dataset. This means that the passed data must be coercible to a tibble. At this time, tibbles do not support matrix-columns. This means you should not specify a matrix of covariates in a model formula during the original model fitting process, and that splines::ns(), stats::poly() and survival::Surv() objects are not supported in input data. If you encounter errors, try explicitly passing a tibble, or fitting the original model on data in a tibble.

We are in the process of defining behaviors for models fit with various na.action arguments, but make no guarantees about behavior when data is missing at this time.

# S3 method for felm
augment(x, data = model.frame(x), ...)

Arguments

x

A felm object returned from lfe::felm().

data

A data.frame() or tibble::tibble() containing the original data that was used to produce the object x. Defaults to stats::model.frame(x) so that augment(my_fit) returns the augmented original data. Do not pass new data to the data argument. Augment will report information such as influence and cooks distance for data passed to the data argument. These measures are only defined for the original training data.

...

Additional arguments. Not used. Needed to match generic signature only. Cautionary note: Misspelled arguments will be absorbed in ..., where they will be ignored. If the misspelled argument has a default value, the default value will be used. For example, if you pass conf.lvel = 0.9, all computation will proceed using conf.level = 0.95. Additionally, if you pass newdata = my_tibble to an augment() method that does not accept a newdata argument, it will use the default value for the data argument.

See also

augment(), lfe::felm()

Other felm tidiers: tidy.felm()

Value

A tibble::tibble() with columns:

.fitted

Fitted or predicted value.

.resid

The difference between fitted and observed values.

Examples

library(lfe)
#> Loading required package: Matrix
#> #> Attaching package: ‘Matrix’
#> The following objects are masked from ‘package:tidyr’: #> #> expand, pack, unpack
N=1e2 DT <- data.frame( id = sample(5, N, TRUE), v1 = sample(5, N, TRUE), v2 = sample(1e6, N, TRUE), v3 = sample(round(runif(100,max=100),4), N, TRUE), v4 = sample(round(runif(100,max=100),4), N, TRUE) ) result_felm <- felm(v2~v3, DT) tidy(result_felm)
#> # A tibble: 2 x 5 #> term estimate std.error statistic p.value #> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 (Intercept) 367902. 53533. 6.87 5.89e-10 #> 2 v3 1681. 930. 1.81 7.38e- 2
augment(result_felm)
#> # A tibble: 100 x 4 #> v2 v3 .fitted[,"v2"] .resid[,"v2"] #> <int> <dbl> <dbl> <dbl> #> 1 954279 92.8 523955. 430324. #> 2 163605 19.2 400129. -236524. #> 3 156404 95.3 528149. -371745. #> 4 477648 87.5 514997. -37349. #> 5 45239 95.0 527649. -482410. #> 6 578305 53.2 457298. 121007. #> 7 264022 19.3 400305. -136283. #> 8 148408 33.6 424354. -275946. #> 9 360434 0.404 368582. -8148. #> 10 884671 91.9 522427. 362244. #> # … with 90 more rows
result_felm <- felm(v2~v3|id+v1, DT) tidy(result_felm, fe = TRUE)
#> # A tibble: 11 x 7 #> term estimate std.error statistic p.value N comp #> <chr> <dbl> <dbl> <dbl> <dbl> <int> <dbl> #> 1 v3 1514. 923. 1.64 0.104 NA NA #> 2 id.1 439835. 68644. 6.41 0.00000237 21 1 #> 3 id.2 264971. 74941. 3.54 0.00208 20 1 #> 4 id.3 557776. 73529. 7.59 0.000000366 19 1 #> 5 id.4 375976. 71351. 5.27 0.0000240 23 1 #> 6 id.5 411353. 81937. 5.02 0.000105 17 1 #> 7 v1.1 -99914. 71209. -1.40 1.82 16 1 #> 8 v1.2 -81178. 79232. -1.02 1.68 15 1 #> 9 v1.3 0 0 NaN NaN 31 1 #> 10 v1.4 -10660. 90314. -0.118 1.09 15 1 #> 11 v1.5 -7811. 66144. -0.118 1.09 23 1
tidy(result_felm, robust = TRUE)
#> # A tibble: 1 x 5 #> term estimate std.error statistic p.value #> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 v3 1514. 959. 1.58 0.118
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted[,"v2"] .resid[,"v2"] #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 954279 92.8 4 3 516568. 437711. #> 2 163605 19.2 4 3 405009. -241404. #> 3 156404 95.3 4 4 509687. -353283. #> 4 477648 87.5 1 2 491179. -13531. #> 5 45239 95.0 4 1 419982. -374743. #> 6 578305 53.2 2 1 245597. 332708. #> 7 264022 19.3 4 3 405168. -141146. #> 8 148408 33.6 1 3 490694. -342286. #> 9 360434 0.404 3 4 547728. -187294. #> 10 884671 91.9 1 5 571240. 313431. #> # … with 90 more rows
v1 <- DT$v1 v2 <- DT$v2 v3 <- DT$v3 id <- DT$id result_felm <- felm(v2~v3|id+v1) tidy(result_felm)
#> # A tibble: 1 x 5 #> term estimate std.error statistic p.value #> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 v3 1514. 923. 1.64 0.104
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted[,"v2"] .resid[,"v2"] #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 954279 92.8 4 3 516568. 437711. #> 2 163605 19.2 4 3 405009. -241404. #> 3 156404 95.3 4 4 509687. -353283. #> 4 477648 87.5 1 2 491179. -13531. #> 5 45239 95.0 4 1 419982. -374743. #> 6 578305 53.2 2 1 245597. 332708. #> 7 264022 19.3 4 3 405168. -141146. #> 8 148408 33.6 1 3 490694. -342286. #> 9 360434 0.404 3 4 547728. -187294. #> 10 884671 91.9 1 5 571240. 313431. #> # … with 90 more rows
glance(result_felm)
#> # A tibble: 1 x 8 #> r.squared adj.r.squared sigma statistic p.value df df.residual nobs #> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> <int> #> 1 0.155 0.0702 262924. 1.83 0.0734 90 90 100