Skip to contents

This function calculates the difference in slopes, or the effect sizes, given the pair of days that correspond to the extremes of the line, the pooled standard deviations from the first day that is being used to compare. The draws from the bayesian fitted model are used to calculate the effect size. The output of this function is then used to plot the effect sizes. The output can also be used to calculate probabilities depending on the research question.

Usage

get_slope_differences(
  results_estimates,
  combination_conditions,
  days,
  pooled_sds,
  column_conditions = "treatment",
  column_days = "days_after_treatment",
  column_vals = "log10tf"
)

Arguments

results_estimates

Dataframe obtained from `add_linpred_draws`

combination_conditions

Matrix with all possible pairwise combinations of the conditions in the columns

days

Vector with numeric days to calculate the the slope difference

pooled_sds

Output from `get_pooled_sds`

column_conditions

Name of the column where conditions are indicated

column_days

Name of the column where days are indicated

column_vals

Name of the measurement column to be used

Value

A dataframe with draws of differences in slopes for all possible combinations

Examples

if (FALSE) { # \dontrun{
library(tidybayes)
library(brms)
library(dplyr)
library(biogrowleR)

# the fit is the same used in the analysis workflow
fit_01 <- brms::brm(
    log10tf ~ days_after_treatment * treatment + (1 | id),
    data = t110_ivis_long,
    cores = 4,
    iter = 4000,
    prior = c(
        brms::set_prior("normal(7, 2)", class = "Intercept"),
        brms::set_prior("normal(0, 4)", class = "b")
    ),
    save_pars = save_pars(all = TRUE)
)

# new dataset to get the draws from the model
df_predict <- biogrowleR::get_df_predict(t110_ivis_long)

# draws from the model
results_estimates_global <- tidybayes::add_linpred_draws(
    object = fit_01, newdata = df_predict,
    re_formula = NA, value = "log10tf"
)

# all possible comparison one can do in this experiment
combination_treatments <- combn(
    t110_ivis_long$treatment %>% unique %>% as.vector,
    m = 2
)

# standard deviation from the beginning of the treatment
pooled_sds <- biogrowleR::get_pooled_sds(t110_ivis_long)

# get the draws of the slope differences, or in other words, the
# standard deviation
slope_differences <- biogrowleR::get_slope_differences(
    results_estimates = results_estimates_global,
    combination_conditions = combination_treatments,
    days = c(
        min(t110_ivis_long$days_after_treatment),
        max(t110_ivis_long$days_after_treatment)
    ),
    pooled_sds = pooled_sds
)
} # }