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.40  4.27   3.43   1.94  2.53  2.78 biomarker
#> 2 2          3.95  3.79  5.83  6.36   3.43   1.94  1.88  2.57 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.89190459 3.2425575
#> .batchvar2   2.30394908 2.0915181
#> confounder  -0.06601737 0.1694321
#> 
#> 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,]  3.053685e+00 -2.398958e-01
#>  [2,]  5.451593e-01 -1.473216e+00
#>  [3,]  2.692821e+00  2.910366e-09
#>  [4,]  1.393218e+00 -7.709020e-01
#>  [5,] -1.814681e-02 -2.772697e+00
#>  [6,]  1.824600e+00 -7.421619e-12
#>  [7,]  3.582158e+00  5.384138e-12
#>  [8,]  3.181857e+00  5.309177e-01
#>  [9,]  4.320233e+00  1.687314e+00
#> [10,]  3.324466e-09 -2.029627e+00
#> [11,]  1.708929e+00 -6.934826e-01
#> [12,] -3.083656e-01 -2.556758e+00
#> [13,] -8.219481e-10 -1.416722e+00
#> [14,]  8.356639e-01 -1.635172e+00
#> [15,]  1.833769e+00 -4.352109e-01
#> [16,]  1.779953e+00  3.590384e-01
#> [17,]  3.778534e-01 -1.860376e+00
#> [18,]  1.806790e+00 -8.851936e-01
#> [19,] -2.746736e-08 -3.368652e+00
#> [20,] -1.047611e-01 -2.384465e+00