A wrapper around lm and anova to run a regression of a continuous variable against categorical variables. Used for determining the whether the mean of a continuous variable is statistically significant amongst different levels of a categorical variable.

auto_anova(
  data,
  ...,
  baseline = c("mean", "median", "first_level", "user_supplied"),
  user_supplied_baseline = NULL,
  sparse = FALSE,
  pval_thresh = 0.1
)

Arguments

data

a data frame

...

tidyselect specification or cols

baseline

choose from "mean", "median", "first_level", "user_supplied". what is the baseline to compare each category to? can use the mean and median of the target variable as a global baseline

user_supplied_baseline

if intercept is "user_supplied", can enter a numeric value

sparse

default FALSE; if true returns a truncated output with only significant results

pval_thresh

control significance level for sparse output filtering

Value

data frame

Details

Columns can be inputted as unquoted names or tidyselect. Continuous and categorical variables are automatically determined. If no character or factor column is present, the column with the lowest amount of unique values will be considered the categorical variable.

Description of columns in the output

target

continuous variables

predictor

categorical variables

level

levels in the categorical variables

estimate

difference between level target mean and baseline

target_mean

target mean per level

n

rows in predictor level

std.error

standard error of target in predictor level

level_p.value

p.value for t.test of whether target mean differs significantly between level and baseline

level_significance

level p.value represented by stars

predictor_p.value

p.value for significance of entire predictor given by F test

predictor_significance

predictor p.value represented by stars

conclusion

text interpretation of tests

Examples


iris %>%
auto_anova(tidyselect::everything()) -> iris_anova1


iris_anova1 %>%
print(width = Inf)
#> # A tibble: 16 × 12
#>    target       predictor level                   estimate target_mean     n
#>    <chr>        <chr>     <chr>                      <dbl>       <dbl> <int>
#>  1 Petal.Length Species   (Intercept)_GLOBAL_MEAN   3.76         3.76    150
#>  2 Petal.Length Species   setosa                   -2.30         1.46     50
#>  3 Petal.Length Species   versicolor                0.502        4.26     50
#>  4 Petal.Length Species   virginica                 1.79         5.55     50
#>  5 Petal.Width  Species   (Intercept)_GLOBAL_MEAN   1.20         1.20    150
#>  6 Petal.Width  Species   setosa                   -0.953        0.246    50
#>  7 Petal.Width  Species   versicolor                0.127        1.33     50
#>  8 Petal.Width  Species   virginica                 0.827        2.03     50
#>  9 Sepal.Length Species   (Intercept)_GLOBAL_MEAN   5.84         5.84    150
#> 10 Sepal.Length Species   setosa                   -0.837        5.01     50
#> 11 Sepal.Length Species   versicolor                0.0927       5.94     50
#> 12 Sepal.Length Species   virginica                 0.745        6.59     50
#> 13 Sepal.Width  Species   (Intercept)_GLOBAL_MEAN   3.06         3.06    150
#> 14 Sepal.Width  Species   setosa                    0.371        3.43     50
#> 15 Sepal.Width  Species   versicolor               -0.287        2.77     50
#> 16 Sepal.Width  Species   virginica                -0.0833       2.97     50
#>    std.error level_p.value level_significance predictor_p.value
#>        <dbl>         <dbl> <chr>                          <dbl>
#>  1    0.105      2.52e-109 "***"                       1.22e-40
#>  2    0.210      1.61e- 23 "***"                       1.22e-40
#>  3    0.210      1.77e-  2 "*"                         1.22e-40
#>  4    0.210      7.95e- 16 "***"                       1.22e-40
#>  5    0.0457     3.03e- 79 "***"                       6.87e-40
#>  6    0.0914     6.73e- 22 "***"                       6.87e-40
#>  7    0.0914     1.67e-  1 " "                         6.87e-40
#>  8    0.0914     2.04e- 17 "***"                       6.87e-40
#>  9    0.0564     1.18e-234 "***"                       1.25e-23
#> 10    0.113      1.20e- 12 "***"                       1.25e-23
#> 11    0.113      4.12e-  1 " "                         1.25e-23
#> 12    0.113      1.85e- 10 "***"                       1.25e-23
#> 13    0.0319     9.24e-225 "***"                       2.64e-14
#> 14    0.0639     1.66e-  8 "***"                       2.64e-14
#> 15    0.0639     9.81e-  6 "***"                       2.64e-14
#> 16    0.0639     1.93e-  1 " "                         2.64e-14
#>    predictor_significance
#>    <chr>                 
#>  1 ***                   
#>  2 ***                   
#>  3 ***                   
#>  4 ***                   
#>  5 ***                   
#>  6 ***                   
#>  7 ***                   
#>  8 ***                   
#>  9 ***                   
#> 10 ***                   
#> 11 ***                   
#> 12 ***                   
#> 13 ***                   
#> 14 ***                   
#> 15 ***                   
#> 16 ***                   
#>    conclusion                                                                   
#>    <chr>                                                                        
#>  1 the mean of Petal.Length is HIGHLY significantly different  between the leve…
#>  2 the setosa group in Species has a Petal.Length mean of 1.462 which is HIGHLY…
#>  3 the versicolor group in Species has a Petal.Length mean of 4.260 which is si…
#>  4 the virginica group in Species has a Petal.Length mean of 5.552 which is HIG…
#>  5 the mean of Petal.Width is HIGHLY significantly different  between the level…
#>  6 the setosa group in Species has a Petal.Width mean of 0.246 which is HIGHLY …
#>  7 the versicolor group in Species has a Petal.Width mean of 1.326 which is NOT…
#>  8 the virginica group in Species has a Petal.Width mean of 2.026 which is HIGH…
#>  9 the mean of Sepal.Length is HIGHLY significantly different  between the leve…
#> 10 the setosa group in Species has a Sepal.Length mean of 5.006 which is HIGHLY…
#> 11 the versicolor group in Species has a Sepal.Length mean of 5.936 which is NO…
#> 12 the virginica group in Species has a Sepal.Length mean of 6.588 which is HIG…
#> 13 the mean of Sepal.Width is HIGHLY significantly different  between the level…
#> 14 the setosa group in Species has a Sepal.Width mean of 3.428 which is HIGHLY …
#> 15 the versicolor group in Species has a Sepal.Width mean of 2.770 which is HIG…
#> 16 the virginica group in Species has a Sepal.Width mean of 2.974 which is NOT …