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_slopes (or generated directly with
lmerTest calls). At least one of the factors should be a numeric covariate whose slopes you wish to find. It also needs to know the fixed factor(s), which should match those in the model and data table.
posthoc_Trends_vsRef( Model, Fixed_Factor, Trend_Factor, Ref_Level = 1, P_Adj = "sidak", ... )
a model object fit using
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 colon between the two Fixed_Factor) to
emmeans to produce pairwise comparisons.
a quantitative variable that interacts with a factor and whose slope (trend) is to be compared
the level within that factor to be considered the reference or control to compare other levels to (to be provided as a number - by default R orders levels alphabetically); default
Ref_Level = 1.
method for correcting P values for multiple comparisons. Default is "sidak", can be changed to "bonferroni". See Interaction analysis in emmeans in the manual for
additional arguments for
emmeans such as
lmer.df or others. See help for sophisticated models in emmeans.
returns an "emm_list" object containing slopes and their contrasts calculated through
Checkout the Interactions with covariates section in the emmeans vignette for more details. One of the independent variables should be a quantitative (e.g. time points) variable whose slope (trend) you want to find at levels of the other factor.
#create an lm model #Time2 is numeric (time points) m1 <- simple_model(data = data_2w_Tdeath, Y_value = "PI", Fixed_Factor = c("Genotype", "Time2")) posthoc_Trends_vsRef(Model = m1, Fixed_Factor = "Genotype", Trend_Factor = "Time2", Ref_Level = 2) #> $emtrends #> Genotype Time2.trend SE df lower.CL upper.CL #> WT 0.0678 0.0172 20 0.0320 0.1036 #> KO 0.0163 0.0172 20 -0.0194 0.0521 #> #> Results are averaged over the levels of: Time2 #> Confidence level used: 0.95 #> #> $contrasts #> contrast estimate SE df t.ratio p.value #> WT - KO 0.0515 0.0243 20 2.121 0.0466 #> #> Results are averaged over the levels of: Time2 #>