Skip to contents

Easily compute planned contrast analyses (pairwise comparisons similar to t-tests but more powerful when more than 2 groups), and format in publication-ready format. Supports only three groups for the moment. In this particular case, the confidence intervals are bootstraped on chosen effect size (default to Cohen's d).

Usage

nice_contrasts(
  response,
  group,
  covariates = NULL,
  data,
  effect.type = "cohens.d",
  bootstraps = 2000,
  ...
)

Arguments

response

The dependent variable.

group

The group for the comparison.

covariates

The desired covariates in the model.

data

The data frame.

effect.type

What effect size type to use. One of "cohens.d" (default), "akp.robust.d", "unstandardized", "hedges.g", "cohens.d.sigma", or "r".

bootstraps

The number of bootstraps to use for the confidence interval

...

Arguments passed to bootES::bootES.

Value

A dataframe, with the selected dependent variable(s), comparisons of interest, degrees of freedom, t-values, p-values, robust Cohen's d (dR), and the lower and upper 95% confidence intervals of the effect size (i.e., dR).

Details

Statistical power is lower with the standard t test compared than it is with the planned contrast version for two reasons: a) the sample size is smaller with the t test, because only the cases in the two groups are selected; and b) in the planned contrast the error term is smaller than it is with the standard t test because it is based on all the cases (source).

The effect size and confidence interval are calculated via bootES::bootES.

For the easystats equivalent, see: modelbased::estimate_contrasts().

Examples

# Basic example
nice_contrasts(
  data = mtcars,
  response = "mpg",
  group = "cyl",
  bootstraps = 200
)
#> Warning: extreme order statistics used as endpoints
#>   Dependent Variable Comparison df        t            p        d  CI_lower
#> 1                mpg      4 - 8 29 8.904534 8.568209e-10 3.587739 2.6170603
#> 2                mpg      6 - 8 29 3.111825 4.152209e-03 1.440495 0.7846083
#> 3                mpg      4 - 6 29 4.441099 1.194696e-04 2.147244 1.3637508
#>   CI_upper
#> 1 4.480989
#> 2 2.098532
#> 3 3.065156
# \donttest{
nice_contrasts(
  data = mtcars,
  response = "disp",
  group = "gear"
)
#>   Dependent Variable Comparison df         t            p          d   CI_lower
#> 1               disp      3 - 5 29  2.916870 6.759287e-03  1.5062653 -0.1232237
#> 2               disp      4 - 5 29 -1.816053 7.971420e-02 -0.9666682 -2.2905942
#> 3               disp      3 - 4 29  6.385087 5.569503e-07  2.4729335  1.3680617
#>    CI_upper
#> 1 3.0910469
#> 2 0.1865743
#> 3 3.2884629

# Multiple dependent variables
nice_contrasts(
  data = mtcars,
  response = c("mpg", "disp", "hp"),
  group = "cyl"
)
#>   Dependent Variable Comparison df          t            p         d   CI_lower
#> 1                mpg      4 - 8 29   8.904534 8.568209e-10  3.587739  2.6834278
#> 2                mpg      6 - 8 29   3.111825 4.152209e-03  1.440495  0.8007661
#> 3                mpg      4 - 6 29   4.441099 1.194696e-04  2.147244  1.4106856
#> 4               disp      4 - 8 29 -11.920787 1.064054e-12 -4.803022 -5.7635634
#> 5               disp      6 - 8 29  -7.104461 8.117219e-08 -3.288726 -4.3221240
#> 6               disp      4 - 6 29  -3.131986 3.945539e-03 -1.514296 -2.2317520
#> 7                 hp      4 - 8 29  -8.285112 3.915144e-09 -3.338167 -4.2961984
#> 8                 hp      6 - 8 29  -4.952403 2.895434e-05 -2.292517 -3.1803660
#> 9                 hp      4 - 6 29  -2.162695 3.894886e-02 -1.045650 -1.6830577
#>     CI_upper
#> 1  4.5494177
#> 2  2.0020817
#> 3  3.0968329
#> 4 -3.8558702
#> 5 -2.2777025
#> 6 -0.9210477
#> 7 -2.3388883
#> 8 -1.3040170
#> 9 -0.3922928

# Adding covariates
nice_contrasts(
  data = mtcars,
  response = "mpg",
  group = "cyl",
  covariates = c("disp", "hp")
)
#>   Dependent Variable Comparison df          t          p        d  CI_lower
#> 1                mpg      4 - 8 27  0.7506447 0.45935889 3.587739 2.6442455
#> 2                mpg      6 - 8 27 -0.6550186 0.51799786 1.440495 0.8311059
#> 3                mpg      4 - 6 27  2.3955766 0.02379338 2.147244 1.3657347
#>   CI_upper
#> 1 4.458875
#> 2 2.003721
#> 3 3.072860
# }