Skip to content

Commit

Permalink
Finished documenting u5plex data, and got mathjax working in refit_cu…
Browse files Browse the repository at this point in the history
…rves details.
  • Loading branch information
Hefin Rhys committed Jan 9, 2024
1 parent 03d3e48 commit 7b38b3f
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 39 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ License: GPL (>= 3) + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RdMacros: mathjaxr
Suggests:
knitr,
rmarkdown,
Expand All @@ -31,8 +32,9 @@ Imports:
scales,
nplr,
utils,
S7
mathjaxr
Config/testthat/edition: 3
Depends:
R (>= 2.10)
R (>= 2.10),
S7
LazyData: true
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

S3method(print,intelliframe)
S3method(str,intelliframe)
export(extract_sheet_data)
export(get_analytes)
export(get_curve_data)
export(get_expected)
Expand All @@ -15,6 +14,7 @@ export(intelliframe)
export(plot_curves)
export(read_xmap)
export(refit_curves)
importFrom(S7,props)
importFrom(rlang,.data)
importFrom(stats,reformulate)
importFrom(stats,setNames)
Expand Down
21 changes: 21 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' 5-plex intelliframe
#'
#' Data from a single, 5-plex xMAP experiment.
#'
#' @format An intelliframe object containing 5 analytes, 80 standard samples, 20
#' control samples, and 1820 unknown samples
#' \describe{
#' \item{@metadata}{A tibble of keyword-value pairs of instrument metadata.}
#' \item{@analytes}{A tibble of analyte metadata.}
#' \item{@expected}{A tibble containing the expected concentrations of analyte
#' standards.}
#' \item{@recovery}{A tibble containing the recovery values of analyte
#' standards (recovery = predicted / expected). }
#' \item{@recovery_avg}{A tibble of mean recovery values across replicates.}
#' \item{@well_data}{A tibble of predicted concentrations for all individual
#' wells.}
#' \item{@summary_data}{A tibble of mean predicted concentrations across all
#' replicates.}
#' \item{@curve_data}{A tibble of standard curve metadata.}
#' }
"u5plex"
1 change: 1 addition & 0 deletions R/luminary-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## usethis namespace: start
#' @importFrom rlang .data
#' @importFrom S7 props
#' @importFrom stats reformulate
#' @importFrom stats setNames
#' @importFrom utils str
Expand Down
33 changes: 17 additions & 16 deletions R/refit_curves.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
#' Refit standard curves
#'
#' \loadmathjax
#' Function to refit n-parameter logistic curves to standards in an intelliframe object
#' and interpolate concentrations for all samples, based on the updated models.
#'
#' @details
#' Most of these details have been reproduced from the \code{\link{nplr}} function that is doing most of the heavy lifting.
#'
#' The 5-parameter logistic regression is of the form:
#' \deqn{y = B + (T - B)/[1 + 10^{(b*(x_{\text{mid}} - x))}]^s}
#' \mjdeqn{y = B + (T - B)/[1 + 10^{(b*(x_{\text{mid}} - x))}]^s}{}
#'
#' where \eqn{B} and \eqn{T} are the bottom and top asymptotes, respectively,
#' \eqn{b} and \eqn{x_{\text{mid}}} are the Hill slope and the x-coordinate at
#' the inflection point, respectively, and \eqn{s} is an asymmetric coefficient.
#' where \mjeqn{B}{} and \mjeqn{T}{} are the bottom and top asymptotes, respectively,
#' \mjeqn{b}{} and \mjeqn{x_{\text{mid}}}{} are the Hill slope and the x-coordinate at
#' the inflection point, respectively, and \mjeqn{s}{} is an asymmetric coefficient.
#' This equation is sometimes referred to as the Richards' equation \[1,2\].
#' When specifying \code{npars = 4}, the \eqn{s} parameter is forced to be 1,
#' When specifying \code{npars = 4}, the \mjeqn{s}{} parameter is forced to be 1,
#' and the corresponding model is a 4-parameter logistic regression, symmetrical
#' around its inflection point. When specifying \code{npars = 3} or \code{npars = 2},
#' add 2 more constraints and force \eqn{B} and \eqn{T} to be 0 and 1, respectively.
#' add 2 more constraints and force \mjeqn{B}{} and \mjeqn{T}{} to be 0 and 1, respectively.
#'
#' Weight methods:
#'
#' The model parameters are optimized, simultaneously, using \code{\link{nlm}},
#' given a sum of squared errors function, \eqn{\text{sse(Y)}}, to minimize:
#' \deqn{\text{sse}(Y) = Σ [W(Y_{\text{obs}} - Y_{\text{fit}})^2 ]}
#' where \eqn{Y_{\text{obs}}}, \eqn{Y_{\text{fit}}} and \eqn{W} are the vectors
#' given a sum of squared errors function, \mjeqn{\text{sse(Y)}}{}, to minimize:
#' \mjdeqn{\text{sse}(Y) = \sum{W(Y_{\text{obs}} - Y_{\text{fit}})^2 }}{}
#' where \mjeqn{Y_{\text{obs}}}{}, \mjeqn{Y_{\text{fit}}}{} and \mjeqn{W}{} are the vectors
#' of observed values, fitted values and weights, respectively.
#' In order to reduce the effect of possible outliers, the weights can be computed in different ways:
#'
#' residual weights, \code{"res"}:
#' \deqn{W = (1/\text{residuals})^\text{LPweight}}
#' where \eqn{\text{residuals}} and \eqn{\text{LPweight}} are the squared error
#' \mjdeqn{W = (1/\text{residuals})^\text{LPweight}}{}
#' where \mjeqn{\text{residuals}}{} and \mjeqn{\text{LPweight}}{} are the squared error
#' between the observed and fitted values, and a tuning parameter, respectively.
#' Best results are generally obtained by setting \code{LPweight = 0.25} (default value),
#' while setting \code{LPweight = 0} results in computing a non-weighted sum of squared errors.
#'
#' standard weights, \code{"sdw"}:
#' \deqn{W = 1/\text{Var}(Y_{\text{obs}_r})}
#' where \eqn{\text{Var}(Y_{\text{obs}_r})} is the vector of the within-replicates variances.
#' \mjdeqn{W = 1/\text{Var}(Y_{\text{obs}_r})}{}
#' where \mjeqn{\text{Var}(Y_{\text{obs}_r})}{} is the vector of the within-replicates variances.
#'
#' general weights, \code{"gw"}:
#' \deqn{W = 1/Y_{\text{fit}}^\text{LPweight}}
#' where \eqn{Y_{\text{fit}}} are the fitted values. As for the residuals-weights method,
#' setting \eqn{LPweight = 0} results in computing a non-weighted sum of squared errors.
#' \mjdeqn{W = 1/Y_{\text{fit}}^\text{LPweight}}{}
#' where \mjeqn{Y_{\text{fit}}}{} are the fitted values. As for the residuals-weights method,
#' setting \mjeqn{\text{LPweight} = 0}{} results in computing a non-weighted sum of squared errors.
#' The standard weights and general weights methods are described in \[3\].
#' @param .intelliframe Intelliframe object to refit
#' @param npars A numeric value (or \code{"all"}) to specify the number of
Expand Down
7 changes: 4 additions & 3 deletions man/extract_sheet_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/read_xmap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions man/refit_curves.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/u5plex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b38b3f

Please sign in to comment.