nls_fit | R Documentation |
Fits individual exponential beta curves to 13C breath test time series
nls_fit(data, dose = 100, start = list(m = 50, k = 1/100, beta = 2))
data |
Data frame or tibble as created by |
dose |
Dose of acetate or octanoate. Currently, only one common dose for all records is supported. |
start |
Optional start values
|
A list of class ("breathtestnlsfit" "breathtestfit") with elements
Estimated parameters in a key-value format with
columns patient_id, group, parameter, stat, method
and value
.
Parameter stat
always has value "estimate"
.
Confidence intervals might be added later, so do not take for granted
all parameters are estimates.
Input data; nls_fit
does not decimate the data. If you have
large data sets where subsampling might be required to achieve faster convergence,
using nls_fit
anyway is only relevant to show how NOT to do it.
Use nlme_fit
or stan_fit
instead.
Base methods coef, plot, print
; methods from package
broom: tidy, augment
.
d = simulate_breathtest_data(n_records = 3, noise = 0.2, seed = 4711)
data = cleanup_data(d$data)
fit = nls_fit(data)
plot(fit) # calls plot.breathtestfit
options(digits = 2)
cf = coef(fit)
library(dplyr)
cf %>%
filter(grepl("m|k|beta", parameter )) %>%
select(-method, -group) %>%
tidyr::spread(parameter, value) %>%
inner_join(d$record, by = "patient_id") %>%
select(patient_id, m_in = m.y, m_out = m.x,
beta_in = beta.y, beta_out = beta.x,
k_in = k.y, k_out = k.x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.