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.87  1.49  4.85  4.35   3.35   1.88  2.97  2.86 biomarker
#> 2 2          3.68  3.53  5.83  6.29   3.35   1.88  2.15  2.75 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.8919065 3.4701396
#> .batchvar2   2.0441906 1.9339369
#> confounder  -0.0660176 0.1454196
#> 
#> 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.814739e-02 -2.857102e+00
#>  [2,]  2.084357e+00 -2.106269e-09
#>  [3,]  3.582158e+00  1.331646e-10
#>  [4,]  3.441615e+00  6.151927e-01
#>  [5,]  4.320232e+00  1.590505e+00
#>  [6,]  2.597574e-01 -2.008717e+00
#>  [7,]  1.708928e+00 -8.138002e-01
#>  [8,] -4.860803e-02 -2.513537e+00
#>  [9,] -1.885404e-06 -1.637566e+00
#> [10,]  1.095422e+00 -1.569265e+00
#> [11,]  1.833768e+00 -5.691366e-01
#> [12,]  2.039710e+00  3.178683e-01
#> [13,]  3.778523e-01 -1.997437e+00
#> [14,]  2.066548e+00 -7.967326e-01
#> [15,] -5.774492e-12 -3.390426e+00
#> [16,]  1.549966e-01 -2.338051e+00
#> [17,]  3.582609e+00  8.881627e-01
#> [18,] -1.044619e-01 -3.053849e+00
#> [19,]  2.130869e+00 -1.061826e-10
#> [20,] -3.335110e-13 -2.292690e+00