Skip to contents

Augmented data from grouped analysis of any function that has data argument in its function call.

Usage

grouped_augment(data, grouping.vars, ..f, ..., augment.args = list())

Arguments

data

Dataframe (or tibble) from which variables are to be taken.

grouping.vars

Grouping variables.

..f

A function, or function name as a string.

...

<dynamic> Arguments for .fn.

augment.args

A list of arguments to be used in the relevant S3 method.

Value

A tibble::tibble() with information about data points.

See also

Examples

set.seed(123)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

# linear mixed effects model
grouped_augment(
  data = mutate(MASS::Aids2, interval = death - diag),
  grouping.vars = sex,
  ..f = lme4::lmer,
  formula = interval ~ age + (1 | status),
  control = lme4::lmerControl(optimizer = "bobyqa")
)
#> # A tibble: 2,843 × 15
#>    sex   interval   age status .fitted  .resid   .hat    .cooksd .fixed   .mu
#>    <fct>    <int> <int> <fct>    <dbl>   <dbl>  <dbl>      <dbl>  <dbl> <dbl>
#>  1 F          543    30 A         604.  -61.5  0.0261 0.000301     493.  604.
#>  2 F          138    44 D         321. -183.   0.0181 0.00182      432.  321.
#>  3 F            1    25 D         403. -402.   0.0289 0.0144       515.  403.
#>  4 F           43    55 D         273. -230.   0.0249 0.00402      385.  273.
#>  5 F          215    70 D         208.    6.90 0.0495 0.00000756   319.  208.
#>  6 F          260    17 D         438. -178.   0.0420 0.00421      549.  438.
#>  7 F          511    57 D         265.  246.   0.0271 0.00505      376.  265.
#>  8 F           92    71 D         204. -112.   0.0517 0.00208      315.  204.
#>  9 F          494    47 D         308.  186.   0.0190 0.00198      419.  308.
#> 10 F           49    67 D         221. -172.   0.0431 0.00404      333.  221.
#> # … with 2,833 more rows, and 5 more variables: .offset <dbl>, .sqrtXwt <dbl>,
#> #   .sqrtrwt <dbl>, .weights <dbl>, .wtres <dbl>