posthoc_Levelwise: Level-wise post-hoc comparisons from a linear or linear mixed...

View source: R/posthoc_Levelwise.R

posthoc_LevelwiseR Documentation

Level-wise post-hoc comparisons from a linear or linear mixed effects model.

Description

This function is a wrapper based on emmeans, and needs a ordinary linear model produced by simple_model or a mixed effects model produced by mixed_model or mixed_model_slopes (or generated directly with lm, lme4 or lmerTest calls). It also needs to know the fixed factor(s), which should match those in the model and data table.

Usage

posthoc_Levelwise(Model, Fixed_Factor, P_Adj = "fdr", Factor, ...)

Arguments

Model

a model object fit using simple_model or mixed_model or related.

Fixed_Factor

one or more categorical variables, provided as a vector (see Examples), whose levels you wish to compare pairwise. Names of Fixed_Factor should match Fixed_Factor used to fit the model. When more than one factor is provided e.g. Fixed_factor = c("A", "B"), this function passes this on as specs = A|B (note the vertical | between the two Fixed_Factor) to emmeans to produce comparisons between each level A with each other listed separately at each level of B.

P_Adj

method for correcting P values for multiple comparisons. Default is set to false discovery rate ("fdr"), can be changed to "none", "tukey", "bonferroni", "sidak". See Interaction analysis in emmeans in the manual for emmeans.

Factor

old argument name for Fixed_Factor; retained for backward compatibility.

...

additional arguments for emmeans such as lmer.df or others. See help for sophisticated models in emmeans.

Details

The function will generate level-wise comparisons (as described in Comparisons and contrasts in emmeans), i.e. comparison between of every level of one factor separately at each level of the other factor. By default, P values are corrected by the FDR method (which can be changed). If the model was fit by transforming the quantitative response variable using "log", "logit", "sqrt" etc., results will still be on the original scale, i.e. type = "response" is the default; data will be back-transformed (check results to confirm this), and for log or logit see Transformations and link functions in emmeans, ratios will be compared. The first part of the emmeans results has the estimated marginal means, SE and CI ($emmeans), which are generated from the fitted model, and not the original data table. The second part has the results of the comparisons ($contrasts).

Value

returns an "emm_list" object containing contrasts and emmeans through emmeans.

Examples

#make a linear model first
CholMod <- mixed_model(data = data_cholesterol, 
Y_value =  "Cholesterol", 
Fixed_Factor = c("Hospital", "Treatment"),
Random_Factor =  "Subject") 

#note quotes used only for fixed Fixed_Factor
#to get comparisons between different hospitals separately for each level of Treatment
posthoc_Levelwise(Model = CholMod, 
Fixed_Factor = c("Hospital", "Treatment"))

#get comparisons between treatments separately at each hospital
posthoc_Levelwise(Model = CholMod, 
Fixed_Factor = c("Treatment", "Hospital"))


grafify documentation built on May 29, 2024, 3:49 a.m.