Skip to contents

Fit an lm using standards absorbances

Usage

qp_fit(x)

# S3 method for data.frame
qp_fit(x)

# S3 method for list
qp_fit(x)

Arguments

x

A data.frame or list containing a data.frame under the name qp. See details.

Value

A list containing:

  • fit, an lm object fit with the formula .log2_conc ~ .log2_abs, fit using non-outlier standards

  • qp, the input data

Details

The supplied data.frame must have the following columns:

  • sample_type. Character. If not 'standard', assumed to be a sample

  • .is_outlier. Boolean. If TRUE, assumed to be outlier and removed from fitting. If FALSE or NA, used for fitting. If unsupplied, will create one with all values set to NA.

  • .conc. Numeric. Known concentration of standard.

  • .log2_abs. Numeric. The log2 of the absorbances

Examples

  absorbances |>
    qp_add_std_conc() |>
    qp_fit()
#> Warning: `sample_type` contains values other than `standard` and `unknown`
#> ! These values may be ignored downstream!
#> Did not find column `.log2_abs`, calculating.
#> Did not find column `.is_outlier`
#> Running `qp_mark_outliers` with `ignore_outliers = all`
#> $fit
#> 
#> Call:
#> stats::lm(formula = .log2_conc ~ .log2_abs, data = fit_data)
#> 
#> Coefficients:
#> (Intercept)    .log2_abs  
#>       2.378        0.850  
#> 
#> 
#> $qp
#> # A tibble: 88 × 8
#>     .row  .col   .abs sample_type index .conc .log2_abs .is_outlier
#>    <int> <dbl>  <dbl> <fct>       <dbl> <dbl>     <dbl> <lgl>      
#>  1     1     1 0.0707 standard        1 0         -3.82 FALSE      
#>  2     2     1 0.0786 standard        1 0         -3.67 TRUE       
#>  3     3     1 0.0714 standard        1 0         -3.81 FALSE      
#>  4     1     2 0.0795 standard        2 0.125     -3.65 FALSE      
#>  5     2     2 0.0799 standard        2 0.125     -3.65 FALSE      
#>  6     3     2 0.0805 standard        2 0.125     -3.63 FALSE      
#>  7     1     3 0.0999 standard        3 0.25      -3.32 FALSE      
#>  8     2     3 0.0955 standard        3 0.25      -3.39 FALSE      
#>  9     3     3 0.0976 standard        3 0.25      -3.36 FALSE      
#> 10     1     4 0.151  standard        4 0.5       -2.72 TRUE       
#> # ℹ 78 more rows
#>