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 ivreg
augment(x, data = model.frame(x), newdata = NULL, ...)

Arguments

x

An ivreg object created by a call to AER::ivreg().

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.

newdata

A data.frame() or tibble::tibble() containing all the original predictors used to create x. Defaults to NULL, indicating that nothing has been passed to newdata. If newdata is specified, the data argument will be ignored.

...

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

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(AER)
#> Loading required package: car
#> Loading required package: carData
#> #> Attaching package: ‘car’
#> The following object is masked from ‘package:dplyr’: #> #> recode
#> Loading required package: lmtest
#> Loading required package: zoo
#> #> Attaching package: ‘zoo’
#> The following objects are masked from ‘package:base’: #> #> as.Date, as.Date.numeric
#> #> Attaching package: ‘lmtest’
#> The following object is masked from ‘package:lfe’: #> #> waldtest
#> Loading required package: sandwich
data("CigarettesSW", package = "AER") ivr <- ivreg( log(packs) ~ income | population, data = CigarettesSW, subset = year == "1995" ) summary(ivr)
#> #> Call: #> ivreg(formula = log(packs) ~ income | population, data = CigarettesSW, #> subset = year == "1995") #> #> Residuals: #> Min 1Q Median 3Q Max #> -0.69305 -0.12941 -0.02257 0.11723 0.58184 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 4.612e+00 4.454e-02 103.549 <2e-16 *** #> income -5.705e-10 2.334e-10 -2.445 0.0184 * #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 0.2293 on 46 degrees of freedom #> Multiple R-Squared: 0.1308, Adjusted R-squared: 0.1119 #> Wald test: 5.976 on 1 and 46 DF, p-value: 0.01839 #>
tidy(ivr)
#> # A tibble: 2 x 5 #> term estimate std.error statistic p.value #> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 (Intercept) 4.61e+ 0 4.45e- 2 104. 3.74e-56 #> 2 income -5.71e-10 2.33e-10 -2.44 1.84e- 2
tidy(ivr, conf.int = TRUE)
#> # A tibble: 2 x 7 #> term estimate std.error statistic p.value conf.low conf.high #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 (Intercept) 4.61e+ 0 4.45e- 2 104. 3.74e-56 4.52e+0 4.70e+ 0 #> 2 income -5.71e-10 2.33e-10 -2.44 1.84e- 2 -1.03e-9 -1.13e-10
tidy(ivr, conf.int = TRUE, exponentiate = TRUE)
#> Warning: Exponentiating coefficients, but model did not use a log or logit link function.
#> # A tibble: 2 x 7 #> term estimate std.error statistic p.value conf.low conf.high #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 (Intercept) 101. 4.45e- 2 104. 3.74e-56 92.2 110. #> 2 income 1.000 2.33e-10 -2.44 1.84e- 2 1.000 1.000
augment(ivr)
#> # A tibble: 48 x 6 #> .rownames log.packs. income population .fitted .resid #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 49 4.62 83903280 4262731 4.56 0.0522 #> 2 50 4.71 45995496 2480121 4.59 0.124 #> 3 51 4.28 88870496 4306908 4.56 -0.285 #> 4 52 4.04 771470144 31493524 4.17 -0.131 #> 5 53 4.41 92946544 3738061 4.56 -0.145 #> 6 54 4.38 104315120 3265293 4.55 -0.177 #> 7 55 4.82 18237436 718265 4.60 0.223 #> 8 56 4.53 333525344 14185403 4.42 0.112 #> 9 57 4.58 159800448 7188538 4.52 0.0591 #> 10 58 4.53 60170928 2840860 4.58 -0.0512 #> # ... with 38 more rows
augment(ivr, data = CigarettesSW)
#> # A tibble: 96 x 11 #> state year cpi population packs income tax price taxs .fitted .resid #> * <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 AL 1985 1.08 3973000 116. 4.60e7 32.5 102. 33.3 4.56 0.0522 #> 2 AR 1985 1.08 2327000 129. 2.62e7 37 101. 37 4.59 0.124 #> 3 AZ 1985 1.08 3184000 105. 4.40e7 31 109. 36.2 4.56 -0.285 #> 4 CA 1985 1.08 26444000 100. 4.47e8 26 108. 32.1 4.17 -0.131 #> 5 CO 1985 1.08 3209000 113. 4.95e7 31 94.3 31 4.56 -0.145 #> 6 CT 1985 1.08 3201000 109. 6.01e7 42 128. 51.5 4.55 -0.177 #> 7 DE 1985 1.08 618000 144. 9.93e6 30 102. 30 4.60 0.223 #> 8 FL 1985 1.08 11352000 122. 1.67e8 37 115. 42.5 4.42 0.112 #> 9 GA 1985 1.08 5963000 127. 7.84e7 28 97.0 28.8 4.52 0.0591 #> 10 IA 1985 1.08 2830000 114. 3.79e7 34 102. 37.9 4.58 -0.0512 #> # ... with 86 more rows
augment(ivr, newdata = CigarettesSW)
#> # A tibble: 96 x 10 #> state year cpi population packs income tax price taxs .fitted #> * <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 AL 1985 1.08 3973000 116. 46014968 32.5 102. 33.3 4.59 #> 2 AR 1985 1.08 2327000 129. 26210736 37 101. 37 4.60 #> 3 AZ 1985 1.08 3184000 105. 43956936 31 109. 36.2 4.59 #> 4 CA 1985 1.08 26444000 100. 447102816 26 108. 32.1 4.36 #> 5 CO 1985 1.08 3209000 113. 49466672 31 94.3 31 4.58 #> 6 CT 1985 1.08 3201000 109. 60063368 42 128. 51.5 4.58 #> 7 DE 1985 1.08 618000 144. 9927301 30 102. 30 4.61 #> 8 FL 1985 1.08 11352000 122. 166919248 37 115. 42.5 4.52 #> 9 GA 1985 1.08 5963000 127. 78364336 28 97.0 28.8 4.57 #> 10 IA 1985 1.08 2830000 114. 37902896 34 102. 37.9 4.59 #> # ... with 86 more rows
glance(ivr)
#> # 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.131 0.112 0.229 5.98 0.0184 2 46