After adjust_batch has performed adjustment for batch effects, diagnose_models provides an overview of parameters and adjustment models. Information is only available about the most recent run of adjust_batch on a dataset.

diagnose_models(data)

Arguments

data

Batch-adjusted dataset (in which adjust_batch has stored information on batch adjustment in the attribute .batchtma)

Value

List:

  • adjust_method Method used for batch adjustment (see adjust_batch).

  • markers Variables of biomarkers for adjustment

  • suffix Suffix appended to variable names

  • batchvar Variable indicating batch

  • confounders Confounders, i.e. determinants of biomarker levels that differ between batches. Returned only if used by the model.

  • adjust_parameters Tibble of parameters used to obtain adjust biomarker levels. Parameters differ between methods:

    • simple, standardize, and ipw: Estimated adjustment parameters are a tibble with one batchmean per marker and .batchvar.

    • quantreg returns a tibble with numerous values per marker and .batchvar: unadjusted (un_...) and adjusted (ad_...) estimates of the lower (..._lo) and upper quantile (..._hi) and interquantile range (..._iq), plus the lower (all_lo) and upper quantiles (all_hi) across all batches.

    • quantnorm does not explicitly estimate parameters.

  • model_fits List of model fit objects, one per biomarker. Models differ between methods:

    • standardize: Linear regression model for the biomarker with .batchvar and confounders as predictors, from which marginal predictions of batch means for each batch are obtained.

    • ipw: Logistic (2 batches) or multinomial models for assignment to a specific batch with .batchvar as the response and confounders as the predictors, used to generate stabilized inverse-probability weights that are then used in a linear regression model to estimate marginally standardized batch means.

    • quantreg: Quantile regression with the marker as the response variable and .batchvar and confounders as predictors.

    • simple and quantnorm do not fit any regression models.

Examples

# Data frame with two batches
# Batch 2 has higher values of biomarker and confounder
df <- data.frame(
  tma = rep(1:2, times = 10),
  biomarker = rep(1:2, times = 10) +
    runif(max = 5, n = 20),
  confounder = rep(0:1, times = 10) +
    runif(max = 10, n = 20)
)

# Adjust for batch effects
df2 <- adjust_batch(
  data = df,
  markers = biomarker,
  batch = tma,
  method = quantreg,
  confounders = confounder
)

# Show overview of model diagnostics:
diagnose_models(data = df2)
#> Dataset after batch effect adjustment using 'method = quantreg'
#> Variable defining batches: tma
#> Adjusted variables: biomarker_adj5
#> Confounders: confounder
#> 
#> Estimated adjustment parameters:
#> # A tibble: 2 × 10
#>   .batchvar un_lo ad_lo un_hi ad_hi all_lo all_iq un_iq ad_iq marker   
#>   <chr>     <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl> <dbl> <chr>    
#> 1 1          1.50  1.46  3.55  3.53   2.38   1.97  2.05  2.07 biomarker
#> 2 2          2.49  2.43  5.03  5.04   2.38   1.97  2.54  2.61 biomarker
#> 
#> Models for adjustment:
#> [[1]]
#> [[1]][[1]]
#> Call:
#> quantreg::rq(formula = stats::reformulate(response = "variable", 
#>     termlabels = c(".batchvar", confounders)), tau = tau, data = .x, 
#>     method = rq_method)
#> 
#> Coefficients:
#>               tau= 0.25  tau= 0.75
#> (Intercept)  1.60029605  3.5934983
#> .batchvar2   0.96422456  1.5028378
#> confounder  -0.01638814 -0.0142002
#> 
#> Degrees of freedom: 20 total; 17 residual
#> 
#> 

# Obtain first fitted regression model:
fit <- diagnose_models(data = df2)$model_fits[[1]][[1]]

# Obtain residuals for this model:
residuals(fit)
#>           tau= 0.25     tau= 0.75
#>  [1,] -1.583155e-01 -2.157420e+00
#>  [2,]  1.763460e+00 -7.769348e-01
#>  [3,]  2.730010e+00  7.236994e-01
#>  [4,]  4.321138e+00  1.775874e+00
#>  [5,]  1.672281e+00 -3.410674e-01
#>  [6,]  1.436872e-08 -2.541149e+00
#>  [7,]  4.415436e+00  2.402635e+00
#>  [8,]  2.541547e+00 -9.976020e-12
#>  [9,]  2.015017e+00 -5.399681e-12
#> [10,] -9.252370e-02 -2.647593e+00
#> [11,] -4.913702e-01 -2.494192e+00
#> [12,]  1.858953e+00 -6.890952e-01
#> [13,]  9.696468e-01 -1.036465e+00
#> [14,]  1.078123e-08 -2.552350e+00
#> [15,]  6.957586e-09 -2.006302e+00
#> [16,]  2.919301e+00  3.801052e-01
#> [17,]  3.796705e-01 -1.631441e+00
#> [18,]  1.548282e+00 -9.938685e-01
#> [19,]  1.999187e+00 -8.658851e-12
#> [20,]  1.997529e+00 -5.413704e-01