
Fit a standard curve to known mfi and dilution values.
Source:R/MFItoRAU.R
dot-fit_standard_curve.RdWe wish to convert the standard curve samples to a five parameter logistic curve. This function takes those values and calls optim to determine the fit.
Examples
# This function is typically called within data-processing workflows.
# Workflow-style example (not run on CRAN)
# \donttest{
# This block demonstrates how .fit_standard_curve() is typically used
# inside the MFItoRAU_Adj-conversion pipeline.
# Step 1 — Prepare master file (normally from readSeroData)
master_file <- data.frame(
Location = c("A1","A2","A3"),
Sample = c("S1","S2","S3"),
Plate = c("Plate1","Plate1","Plate1"),
Ag1 = c(12000, 8000, 4000),
Ag2 = c(9000, 5000, 2500)
)
# Convert antigen columns to numeric
L <- master_file |>
dplyr::mutate(dplyr::across(-c(Location, Sample, Plate), as.numeric))
# Fake plate layout (normally from readPlateLayout)
layout <- list(Plate1 = data.frame(Location = c("A1","A2","A3"), WellType = "STD"))
# Step 2 — Load reference standard curve MFI values (dummy data)
refs <- data.frame(
std_plate = rep("StdPlate1", 5),
antigen = rep("Ag1", 5),
dilution = c(1, 1/2, 1/4, 1/8, 1/16),
eth_mfi = c(14000, 7000, 3500, 1800, 900),
png_mfi = c(15000, 7600, 3800, 1900, 950)
)
# Step 3 — Define optimisation settings
control <- list(
maxit = 10000,
abstol = 1e-8,
reltol = 1e-6
)
# Step 4 — Fit ETH and PNG curves per standard-plate × antigen
ref_fit <- refs |>
dplyr::group_by(.data$std_plate, .data$antigen) |>
tidyr::nest() |>
dplyr::mutate(
eth_fit = purrr::map(data, ~ .fit_standard_curve(.x$eth_mfi, .x$dilution, control)),
png_fit = purrr::map(data, ~ .fit_standard_curve(.x$png_mfi, .x$dilution, control))
)
ref_fit
#> # A tibble: 1 × 5
#> # Groups: std_plate, antigen [1]
#> std_plate antigen data eth_fit png_fit
#> <chr> <chr> <list> <list> <list>
#> 1 StdPlate1 Ag1 <tibble [5 × 3]> <dbl [7]> <dbl [7]>
# }