Skip to contents

Predict concentrations from standards fit

Usage

qp_calc_conc(x, ignore_outliers = TRUE, group_cols = c("sample_type", "index"))

Arguments

x

A list. See details.

ignore_outliers

Boolean. Should outliers be considered when calculating the mean? See details.

group_cols

Character vector. Columns to group by before taking the mean.

Value

Returns a list with the input fit and data.frame, with additional columns:

  • .pred: The predicted value from the provided model

  • .pred_conc: .pred, transformed by conc_transform

  • .pred_conc_mean: The mean of .pred_conc, sans samples where column .is_outlier == TRUE

Details

The supplied list should contain two items - fit, generated by qp_fit, and qp, a data.frame. qp should contain the following:

  • Columns used in fit. Usually, this is .log2_abs

  • Any columns in group_cols

  • If ignore_outliers = TRUE, .is_outlier will be used if supplied, or created if not.

Examples


data <- system.file("extdata", "absorbances.txt", package = "qp")
calculated <- qp(data, replicate_orientation = "h")
#> Please wait. This will take ~10 seconds.

# Making a minimal object:
calculated$qp <- calculated$qp |>
  dplyr::select(
    .log2_abs, sample_type, index, .is_outlier
  )

calculated
#> $fit
#> 
#> Call:
#> stats::lm(formula = .log2_conc ~ .log2_abs, data = fit_data)
#> 
#> Coefficients:
#> (Intercept)    .log2_abs  
#>       3.358        1.141  
#> 
#> 
#> $qp
#> # A tibble: 36 × 4
#>    .log2_abs sample_type index .is_outlier
#>        <dbl> <fct>       <dbl> <lgl>      
#>  1     -3.87 standard        1 FALSE      
#>  2     -3.80 standard        1 FALSE      
#>  3     -3.84 standard        1 FALSE      
#>  4     -3.60 standard        2 TRUE       
#>  5     -3.59 standard        2 FALSE      
#>  6     -3.58 standard        2 FALSE      
#>  7     -3.29 standard        3 FALSE      
#>  8     -3.32 standard        3 TRUE       
#>  9     -3.30 standard        3 FALSE      
#> 10     -2.92 standard        4 FALSE      
#> # ℹ 26 more rows
#> 

qp_calc_conc(calculated)
#> $fit
#> 
#> Call:
#> stats::lm(formula = .log2_conc ~ .log2_abs, data = fit_data)
#> 
#> Coefficients:
#> (Intercept)    .log2_abs  
#>       3.358        1.141  
#> 
#> 
#> $qp
#> # A tibble: 36 × 7
#>    .log2_abs sample_type index .is_outlier   .pred .pred_conc .pred_conc_mean
#>        <dbl> <fct>       <dbl> <lgl>         <dbl>      <dbl>           <dbl>
#>  1     -3.87 standard        1 FALSE       -1.05     -0.0177         -0.00623
#>  2     -3.80 standard        1 FALSE       -0.979     0.00719        -0.00623
#>  3     -3.84 standard        1 FALSE       -1.02     -0.00811        -0.00623
#>  4     -3.60 standard        2 TRUE        -0.748     0.0952          0.102  
#>  5     -3.59 standard        2 FALSE       -0.735     0.101           0.102  
#>  6     -3.58 standard        2 FALSE       -0.729     0.103           0.102  
#>  7     -3.29 standard        3 FALSE       -0.394     0.261           0.258  
#>  8     -3.32 standard        3 TRUE        -0.425     0.245           0.258  
#>  9     -3.30 standard        3 FALSE       -0.404     0.256           0.258  
#> 10     -2.92 standard        4 FALSE        0.0275    0.519           0.520  
#> # ℹ 26 more rows
#>