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.

Examples

# Basic example
nice_contrasts(
  data = mtcars,
  response = "mpg",
  group = "cyl",
  bootstraps = 200
)
#> Warning: extreme order statistics used as endpoints
#> Warning: extreme order statistics used as endpoints
#> 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.6988371
#> 2                mpg      6 - 8 29 3.111825 4.152209e-03 1.440495 0.7234873
#> 3                mpg      4 - 6 29 4.441099 1.194696e-04 2.147244 1.2048270
#>   CI_upper
#> 1 4.240098
#> 2 2.033398
#> 3 2.985783
# \donttest{
nice_contrasts(
  data = mtcars,
  response = "disp",
  group = "gear"
)
#>   Dependent Variable Comparison df         t            p          d
#> 1               disp      3 - 5 29  2.916870 6.759287e-03  1.5062653
#> 2               disp      4 - 5 29 -1.816053 7.971420e-02 -0.9666682
#> 3               disp      3 - 4 29  6.385087 5.569503e-07  2.4729335
#>      CI_lower  CI_upper
#> 1 -0.07531778 3.0286653
#> 2 -2.40005951 0.1704979
#> 3  1.43005846 3.2969116

# 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.7282870
#> 2                mpg      6 - 8 29   3.111825 4.152209e-03  1.440495  0.8105144
#> 3                mpg      4 - 6 29   4.441099 1.194696e-04  2.147244  1.3910077
#> 4               disp      4 - 8 29 -11.920787 1.064054e-12 -4.803022 -5.9009049
#> 5               disp      6 - 8 29  -7.104461 8.117219e-08 -3.288726 -4.2949785
#> 6               disp      4 - 6 29  -3.131986 3.945539e-03 -1.514296 -2.2455540
#> 7                 hp      4 - 8 29  -8.285112 3.915144e-09 -3.338167 -4.3108394
#> 8                 hp      6 - 8 29  -4.952403 2.895434e-05 -2.292517 -3.1971068
#> 9                 hp      4 - 6 29  -2.162695 3.894886e-02 -1.045650 -1.7226350
#>     CI_upper
#> 1  4.5623364
#> 2  2.0099215
#> 3  3.1485333
#> 4 -3.9256238
#> 5 -2.3059838
#> 6 -0.8669668
#> 7 -2.3372841
#> 8 -1.3727204
#> 9 -0.4540835

# 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.7430070
#> 2                mpg      6 - 8 27 -0.6550186 0.51799786 1.440495 0.7398763
#> 3                mpg      4 - 6 27  2.3955766 0.02379338 2.147244 1.3403800
#>   CI_upper
#> 1 4.454113
#> 2 1.985087
#> 3 3.090245
# }