# import the package and load the data
library(ComBatFamQC)
library(parallel)
data(age_df)
# specify parameters
<- data.frame(age_df)
age_df <- colnames(age_df)[c(6:56)]
features <- "age"
age <- "sex"
sex <- "ICV_baseline"
icv <- as.factor(age_df[[sex]])
age_df[[sex]] # create sub_df for different features
<- lapply(seq_len(length(features)), function(i){
sub_df_list <- age_df[,c(features[i], age, sex, icv)] %>% na.omit()
sub_df colnames(sub_df) <- c(features[i], "age", "sex", "icv")
return(sub_df)
})
Post Harmonization
ComBatFamQC currently offers two types of post-harmonization downstream analysis tools: (1) interactive life span age trend visualization and (2) customized residual generation. The life span age trend visualization provides age centile fits for each brain structure, adjusted for sex and intracranial volume (ICV). The customized residual generation feature enables users to remove the effects of unwanted covariates while retaining those of interest in the harmonized data.
Interactive Life Span Age Trend
To better demonstrate how to use the function in R, we utilized a simulated dataset, age_df
, for illustration. Note that if you are implementing this in R, there are several essential steps to set up the workflow:
Generate a list of structured datasets for all brain ROIs. Each ROI dataset should contain the following four columns:
- roi.name: ROI value
- age: subject’s age information
- sex: subject’s sex information
- icv: subject’s intracranial volume
- Create age trend datasets for all ROIs.
Start an interactive session for age trend visualization.
Users can choose to generate an interactive age trend plot using the
plotly
package or a static plot using theggplot2
package.
Alternatively, users can utilize the command-line interface via post_CLI.R. The essential steps have been streamlined, significantly simplifying the workflow and making it easier to get started. The following parameters must be assigned values:
--features/-f
: position of features/rois data(column numbers)--AGE/-A
: column position of the age variable--SEX/-S
: column position of the sex variable--ICV/I
: column position of the ICV variable--Female/-F
: female indicator, the value represent female in the sex column--ploty/-p
: whether to generateplotly
interactive plots
Export Age Trend Table and GAMLSS Model
Using the command-line interface requires users to set the following parameter:
--visualization/-v
: FALSE--outdir
: Path to a directory for saving the age trend table--mout
: Path to save the GAMLSS model (in .rds format)(optional if users do not wish to save the model)
Customized Residual Generation
ComBatFamQC offers users the flexibility to create various sets of residuals by removing the effects of specific covariates. To maximize the utility of this feature, it is important to carefully choose parameters based on the type of regression and the covariates to be adjusted for.
The tool provides two methods for generating residuals: 1) creating residuals from scratch and 2) deriving residuals from an existing model. Detailed examples are provided below. We continue to use the ADNI dataset for demonstration.
Generate Residuals from Scratch
This approach requires users to refit the regression model.
Using the command-line interface to start the residual generation stage requires users to set the following parameter:
--type\-t
: “residual”--outdir
: Path to save the harmonized dataset (in .csv format)--mout
: Path to save the regression model (in .rds format)(optional if users do not wish to save the model)
Generate Residuals from Existing Model
This method requires users to supply a pre-trained model.
Using the command-line interface requires users to set the following parameter:
--exist.model
: TRUEmodel.path
: Path to the saved regression model.