aboutsummaryrefslogtreecommitdiff
path: root/R/sigma_twocomp.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-10-22 12:34:40 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-10-22 12:34:40 +0200
commit4a6beafe6ca119500232ecda4b5672dd4a1877c2 (patch)
treeade255f256a2cebf6262f12f816925ca3ce9944c /R/sigma_twocomp.R
parenta9c7a1a8322567e9406a59ba0a4f910b89bd05e6 (diff)
Improve interface to experimental version of nlme
The experimental nlme version in my drat repository contains the variance function structure varConstProp which makes it possible to use the two-component error model in generalized nonlinear models using nlme::gnls() and in mixed effects models using nlme::nlme().
Diffstat (limited to 'R/sigma_twocomp.R')
-rw-r--r--R/sigma_twocomp.R33
1 files changed, 30 insertions, 3 deletions
diff --git a/R/sigma_twocomp.R b/R/sigma_twocomp.R
index 1e012d15..e8a92ced 100644
--- a/R/sigma_twocomp.R
+++ b/R/sigma_twocomp.R
@@ -23,7 +23,34 @@
#'
#' Rocke, David M. and Lorenzato, Stefan (1995) A two-component model for
#' measurement error in analytical chemistry. Technometrics 37(2), 176-184.
+#' @examples
+#' times <- c(0, 1, 3, 7, 14, 28, 60, 90, 120)
+#' d_pred <- data.frame(time = times, parent = 100 * exp(- 0.03 * times))
+#' set.seed(123456)
+#' d_syn <- add_err(d_pred, function(y) sigma_twocomp(y, 1, 0.07),
+#' reps = 2, n = 1)[[1]]
+#' f_nls <- nls(value ~ SSasymp(time, 0, parent_0, lrc), data = d_syn,
+#' start = list(parent_0 = 100, lrc = -3))
+#' library(nlme)
+#' f_gnls <- gnls(value ~ SSasymp(time, 0, parent_0, lrc),
+#' data = d_syn, na.action = na.omit,
+#' start = list(parent_0 = 100, lrc = -3))
+#' if (length(findFunction("varConstProp")) > 0) {
+#' f_gnls_tc <- gnls(value ~ SSasymp(time, 0, parent_0, lrc),
+#' data = d_syn, na.action = na.omit,
+#' start = list(parent_0 = 100, lrc = -3),
+#' weights = varConstProp())
+#' f_gnls_tc_sf <- gnls(value ~ SSasymp(time, 0, parent_0, lrc),
+#' data = d_syn, na.action = na.omit,
+#' start = list(parent_0 = 100, lrc = -3),
+#' control = list(sigma = 1),
+#' weights = varConstProp())
+#' }
+#' f_mkin <- mkinfit("SFO", d_syn, error_model = "const", quiet = TRUE)
+#' f_mkin_tc <- mkinfit("SFO", d_syn, error_model = "tc", quiet = TRUE)
+#' plot_res(f_mkin_tc, standardized = TRUE)
+#' AIC(f_nls, f_gnls, f_gnls_tc, f_gnls_tc_sf, f_mkin, f_mkin_tc)
#' @export
- sigma_twocomp <- function(y, sigma_low, rsd_high) {
- sqrt(sigma_low^2 + y^2 * rsd_high^2)
- }
+sigma_twocomp <- function(y, sigma_low, rsd_high) {
+ sqrt(sigma_low^2 + y^2 * rsd_high^2)
+}

Contact - Imprint