View source: R/hypothesis_test.R

hypothesis_test | R Documentation |

Function to test differences of adjusted predictions for statistical significance. This is usually called contrasts or (pairwise) comparisons.

hypothesis_test(model, ...) ## Default S3 method: hypothesis_test( model, terms = NULL, test = "pairwise", equivalence = NULL, p_adjust = NULL, df = NULL, ci.lvl = 0.95, verbose = TRUE, ... ) ## S3 method for class 'ggeffects' hypothesis_test( model, test = "pairwise", equivalence = NULL, p_adjust = NULL, df = NULL, verbose = TRUE, ... )

`model` |
A fitted model object, or an object of class |

`...` |
Arguments passed down to |

`terms` |
Character vector with the names of the focal terms from |

`test` |
Hypothesis to test. By default, pairwise-comparisons are
conducted. See section |

`equivalence` |
ROPE's lower and higher bounds. Should be |

`p_adjust` |
Character vector, if not |

`df` |
Degrees of freedom that will be used to compute the p-values and
confidence intervals. If |

`ci.lvl` |
Numeric, the level of the confidence intervals. |

`verbose` |
Toggle messages and warnings. |

A data frame containing predictions (e.g. for `test = NULL`

),
contrasts or pairwise comparisons of adjusted predictions or estimated
marginal means.

There are many ways to test contrasts or pairwise comparisons. A detailed introduction with many (visual) examples is shown in this vignette.

Note that p-value adjustment for methods supported by `p.adjust()`

(see also
`p.adjust.methods`

), each row is considered as one set of comparisons, no
matter which `test`

was specified. That is, for instance, when `hypothesis_test()`

returns eight rows of predictions (when `test = NULL`

), and `p_adjust = "bonferroni"`

,
the p-values are adjusted in the same way as if we had a test of pairwise
comparisons (`test = "pairwise"`

) where eight rows of comparisons are
returned. For methods `"tukey"`

or `"sidak"`

, a rank adjustment is done
based on the number of combinations of levels from the focal predictors
in `terms`

. Thus, the latter two methods may be useful for certain tests
only, in particular pairwise comparisons.

There is also an `equivalence_test()`

method in the **parameters**
package (`parameters::equivalence_test.lm()`

), which can be used to
test contrasts or comparisons for practical equivalence. This method also
has a `plot()`

method, hence it is possible to do something like:

library(parameters) ggpredict(model, focal_terms) |> equivalence_test() |> plot()

## Not run: if (requireNamespace("marginaleffects") && interactive()) { data(efc) efc$c172code <- as.factor(efc$c172code) efc$c161sex <- as.factor(efc$c161sex) levels(efc$c161sex) <- c("male", "female") m <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc) # direct computation of comparisons hypothesis_test(m, "c172code") # passing a `ggeffects` object pred <- ggpredict(m, "c172code") hypothesis_test(pred) # test for slope hypothesis_test(m, "c12hour") # interaction - contrasts by groups m <- lm(barthtot ~ c12hour + c161sex * c172code + neg_c_7, data = efc) hypothesis_test(m, c("c161sex", "c172code"), test = NULL) # interaction - pairwise comparisons by groups hypothesis_test(m, c("c161sex", "c172code")) # p-value adjustment hypothesis_test(m, c("c161sex", "c172code"), p_adjust = "tukey") # specific comparisons hypothesis_test(m, c("c161sex", "c172code"), test = "b2 = b1") # interaction - slope by groups m <- lm(barthtot ~ c12hour + neg_c_7 * c172code + c161sex, data = efc) hypothesis_test(m, c("neg_c_7", "c172code")) } ## End(Not run)

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.