Skip to contents

This function both

  1. draws a spline-difference plot for 2 splines,

  2. and returns a dataframe of differences at each node

Usage

spline_diff(
  gam_model,
  tract,
  group_by = "group",
  factor_a,
  factor_b,
  save_output = TRUE,
  sim.ci = FALSE,
  output_dir = getwd()
)

Arguments

gam_model

GAM object, produced by gam/bam

tract

AFQ tract name

group_by

The grouping variable used to group nodeID smoothing terms

factor_a

First group factor, string

factor_b

Second group factor, string

save_output

Boolean. If TRUE, save plot output

sim.ci

Logical: Using simultaneous confidence intervals or not (default set to FALSE). The implementation of simultaneous CIs follows Gavin Simpson's blog of December 15, 2016: http://www.fromthebottomoftheheap.net/2016/12/15/simultaneous-interval-revisited/. This interval is calculated from simulations based. Please specify a seed (e.g., set.seed(123)) for reproducible results. Note: in contrast with Gavin Simpson's code, here the Bayesian posterior covariance matrix of the parameters is uncertainty corrected (unconditional=TRUE) to reflect the uncertainty on the estimation of smoothness parameters.

output_dir

Directory in which to save plots

Value

A dataframe of spline differences at each node

Examples

if (FALSE) { # \dontrun{
df_afq <- read.csv("/path/to/afq/output.csv")

gam_fit <- fit_gam(
  df_afq,
  target = "dti_fa",
  covariates = list("group", "sex"),
  family = "gamma",
  k = 40
)

df_diff <- spline_diff(
  gam_model = gam_fit,
  tract = "OR",
  factor_b = "1",
  output_dir = "."
)} # }