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 = NULL, ...)

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 / predicted value.

.resid

Residuals of fitted values. TODO -- document when present. Residuals on which data set?

Examples

library(lfe)
#> Loading required package: Matrix
#> #> Attaching package: ‘Matrix’
#> The following object is masked from ‘package:tidyr’: #> #> expand
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) 511929. 65677. 7.79 6.94e-12 #> 2 v3 -0.927 1078. -0.000860 9.99e- 1
augment(result_felm)
#> # A tibble: 100 x 4 #> v2 v3 .fitted .resid #> <int> <dbl> <dbl> <dbl> #> 1 4657 41.4 511891. -507234. #> 2 889156 37.6 511894. 377262. #> 3 710453 16.9 511913. 198540. #> 4 70013 18.6 511912. -441899. #> 5 738684 42.3 511890. 226794. #> 6 69175 54.5 511878. -442703. #> 7 629440 69.8 511864. 117576. #> 8 911585 57.5 511876. 399709. #> 9 516552 54.3 511879. 4673. #> 10 299253 99.8 511836. -212583. #> # ... 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 274. 1098. 0.250 0.804 NA NA #> 2 id.1 670015. 94868. 7.06 0.00000138 18 1 #> 3 id.2 590169. 99030. 5.96 0.00000648 21 1 #> 4 id.3 683641. 96664. 7.07 0.000000429 22 1 #> 5 id.4 663347. 103189. 6.43 0.00000834 16 1 #> 6 id.5 606642. 87235. 6.95 0.000000435 23 1 #> 7 v1.1 0 0 NaN NaN 24 1 #> 8 v1.2 -324799. 79411. -4.09 2.00 18 1 #> 9 v1.3 -112338. 77061. -1.46 1.84 21 1 #> 10 v1.4 -202119. 74833. -2.70 1.99 20 1 #> 11 v1.5 -125154. 79593. -1.57 1.87 17 1
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted .resid #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 4657 41.4 5 5 492831. -488174. #> 2 889156 37.6 4 1 673656. 215500. #> 3 710453 16.9 3 5 563106. 147347. #> 4 70013 18.6 5 3 499409. -429396. #> 5 738684 42.3 2 4 399636. 339048. #> 6 69175 54.5 5 2 296778. -227603. #> 7 629440 69.8 1 4 487016. 142424. #> 8 911585 57.5 3 3 587052. 324533. #> 9 516552 54.3 3 5 573354. -56802. #> 10 299253 99.8 3 4 508857. -209604. #> # ... 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 274. 1098. 0.250 0.804
augment(result_felm)
#> # A tibble: 100 x 6 #> v2 v3 id v1 .fitted .resid #> <int> <dbl> <int> <int> <dbl> <dbl> #> 1 4657 41.4 5 5 492831. -488174. #> 2 889156 37.6 4 1 673656. 215500. #> 3 710453 16.9 3 5 563106. 147347. #> 4 70013 18.6 5 3 499409. -429396. #> 5 738684 42.3 2 4 399636. 339048. #> 6 69175 54.5 5 2 296778. -227603. #> 7 629440 69.8 1 4 487016. 142424. #> 8 911585 57.5 3 3 587052. 324533. #> 9 516552 54.3 3 5 573354. -56802. #> 10 299253 99.8 3 4 508857. -209604. #> # ... with 90 more rows
glance(result_felm)
#> # A tibble: 1 x 7 #> r.squared adj.r.squared sigma statistic p.value df df.residual #> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int> #> 1 0.178 0.0963 270017. 2.17 0.0312 90 90