Skip to contents

Augments the data used for an IPD method/model fit with additional information about each observation.

Usage

# S3 method for class 'ipd'
augment(x, data = x$data_u, ...)

Arguments

x

An object of class ipd.

data

The data.frame used to fit the model. Default is x$data.

...

Additional arguments to be passed to the augment function.

Value

A data.frame containing the original data along with fitted values and residuals.

Examples


#-- Generate Example Data

set.seed(2023)

dat <- simdat(n = c(300, 300, 300), effect = 1, sigma_Y = 1)

head(dat)
#>            X1          X2         X3         X4          Y  f      set
#> 1 -0.08378436  1.42014307 -0.1615291 -0.2004525 -0.2871755 NA training
#> 2 -0.98294375 -1.30333434 -1.0273652 -1.6867582  0.3242501 NA training
#> 3 -1.87506732  0.05942012 -1.0964411 -0.0696362 -2.2601440 NA training
#> 4 -0.18614466 -1.30651333 -0.2979100  1.4198123  1.1182872 NA training
#> 5 -0.63348570  0.32404466 -1.0075244 -0.4614362 -1.5729777 NA training
#> 6  1.09079746  0.11532808 -0.6296308 -0.4045431  0.1953583 NA training

formula <- Y - f ~ X1

#-- Fit IPD

fit <- ipd(formula, method = "postpi_analytic", model = "ols",

  data = dat, label = "set")

#-- Augment Data

augmented_df <- augment(fit)

head(augmented_df)
#>             X1           X2         X3         X4          Y          f
#> 601 -0.7837177  0.178006616 -0.1616781  0.4338174 -1.7279970 -0.1634519
#> 602  1.0889885  0.001981481 -0.6106287  1.0488701 -1.1479536  1.2560099
#> 603  0.4113556 -1.816228693  0.3559724  0.7508637  0.7975626  1.3954652
#> 604 -0.5649962  0.146649326 -0.2847619  1.1671536 -1.5503196 -0.1018075
#> 605  2.4380768 -0.137673699  2.1158117  0.8717130  7.3772118  4.9138749
#> 606  0.9143936 -1.111515668 -0.4280861 -0.6254231  2.3323484  1.3288926
#>           set    .fitted     .resid
#> 601 unlabeled 0.01990047 -1.7478975
#> 602 unlabeled 1.86134104 -3.0092947
#> 603 unlabeled 1.19502145 -0.3974588
#> 604 unlabeled 0.23497037 -1.7852899
#> 605 unlabeled 3.18790564  4.1893061
#> 606 unlabeled 1.68966105  0.6426873