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) 456375. 52598. 8.68 8.95e-14 #> 2 v3 -138. 895. -0.154 8.78e- 1
augment(result_felm)
#> # A tibble: 100 x 4 #> v2 v3 .fitted .resid #> <int> <dbl> <dbl> <dbl> #> 1 477648 86.4 444473. 33175. #> 2 45239 98.4 442823. -397584. #> 3 578305 0.544 456300. 122005. #> 4 264022 1.47 456172. -192150. #> 5 148408 87.5 444326. -295918. #> 6 360434 52.1 449199. -88765. #> 7 884671 72.5 446383. 438288. #> 8 918694 22.4 453293. 465401. #> 9 594006 59.5 448175. 145831. #> 10 311252 25.1 452912. -141660. #> # … 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 -316. 939. -0.337 0.737 NA NA #> 2 id.1 471657. 76293. 6.18 0.00000487 20 1 #> 3 id.2 307216. 83533. 3.68 0.00140 21 1 #> 4 id.3 510383. 73460. 6.95 0.000000731 21 1 #> 5 id.4 523700. 74242. 7.05 0.000000582 21 1 #> 6 id.5 633427. 81350. 7.79 0.000000527 17 1 #> 7 v1.1 -19963. 73441. -0.272 1.21 16 1 #> 8 v1.2 -175182. 87530. -2.00 1.93 14 1 #> 9 v1.3 0 0 NaN NaN 31 1 #> 10 v1.4 73283. 88424. 0.829 0.420 15 1 #> 11 v1.5 -6962. 75438. -0.0923 1.07 24 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 -316. 937. -0.338 0.736
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted .resid #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 477648 86.4 4 1 476408. 1240. #> 2 45239 98.4 2 1 256136. -210897. #> 3 578305 0.544 4 3 523528. 54777. #> 4 264022 1.47 1 3 471192. -207170. #> 5 148408 87.5 3 4 555999. -407591. #> 6 360434 52.1 1 5 448218. -87784. #> 7 884671 72.5 5 5 603522. 281149. #> 8 918694 22.4 4 3 516624. 402070. #> 9 594006 59.5 3 5 484594. 109412. #> 10 311252 25.1 4 3 515749. -204497. #> # … 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 -316. 939. -0.337 0.737
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted .resid #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 477648 86.4 4 1 476408. 1240. #> 2 45239 98.4 2 1 256136. -210897. #> 3 578305 0.544 4 3 523528. 54777. #> 4 264022 1.47 1 3 471192. -207170. #> 5 148408 87.5 3 4 555999. -407591. #> 6 360434 52.1 1 5 448218. -87784. #> 7 884671 72.5 5 5 603522. 281149. #> 8 918694 22.4 4 3 516624. 402070. #> 9 594006 59.5 3 5 484594. 109412. #> 10 311252 25.1 4 3 515749. -204497. #> # … 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.153 0.0688 266284. 1.81 0.0767 90 90 100