nls_fit {breathtestcore} | R Documentation |
Individual curve fit with nls to 13C breath test data
Description
Fits individual exponential beta curves to 13C breath test time series
Usage
nls_fit(data, dose = 100, start = list(m = 50, k = 1/100, beta = 2))
Arguments
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
|
Value
A list of class ("breathtestnlsfit" "breathtestfit") with elements
- coef
Estimated parameters in a key-value format with columns
patient_id, group, parameter, stat, method
andvalue
. Parameterstat
always has value"estimate"
. Confidence intervals might be added later, so do not take for granted all parameters are estimates.- data
Input data;
nls_fit
does not decimate the data. If you have large data sets where subsampling might be required to achieve faster convergence, usingnls_fit
anyway is only relevant to show how NOT to do it. Usenlme_fit
orstan_fit
instead.
See Also
Base methods coef, plot, print
; methods from package
broom: tidy, augment
.
Examples
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)