Skip to contents

To analyse the posterior distribution of the differences in the slopes of the regression lines, one needs to create a prediction dataset to use in the `add_linpred_draws` from the package `tidybayes`. Here the dataset is created in a format that will be accepted by `add_linpred_draws` if your model has a format such as `days*treatment` as a global effect in the formula.

Usage

get_df_predict(
  df,
  column_days = "days_after_treatment",
  column_conditions = "treatment",
  spline_degree = NULL,
  spline_knots = NULL
)

Arguments

df

Dataframe in the long format.

column_days

Name of the column where days are indicated

column_conditions

Name of the column where conditions are indicated

spline_degree

Degree of spline if spline was used in the modeling

spline_knots

A vector with the knots of the spline if spline was used in the modeling

Value

A dataframe with format ready to predict new values

Examples

library(splines)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

# use the available dataset packaged
df <- t110_ivis_long %>%
    dplyr::filter(days_after_treatment < 37) %>%
    dplyr::filter(treatment %in% c("ctrl", "e2")) %>%
    dplyr::mutate(treatment = droplevels.factor(treatment)) %>%
    dplyr::filter(id %in% c(
        "t110_m01_gxx_cxx_ctrl", "t110_m02_gxx_cxx_ctrl",
        "t110_m01_gxx_cxx_e2", "t110_m02_gxx_cxx_e2"
    ))

df_predict <- get_df_predict(df)

# with splines
spline_knots <- c(15)
spline_degree <- 2
df_splines <- df %>% dplyr::mutate(
    B = splines::bs(
        df$days_after_treatment,
        knots = spline_knots,
        degree = spline_degree,
        intercept = FALSE
    )
)

df_predict <- get_df_predict(
    df_splines,
    spline_degree = spline_degree,
    spline_knots = spline_knots
)