| nlme_fit {breathtestcore} | R Documentation |
Mixed-model nlme fit to 13C Breath Data
Description
Fits exponential beta curves to 13C breath test series data using a mixed-model population approach. See https://menne-biomed.de/blog/breath-test-stan for a comparison between single curve, mixed-model population and Bayesian methods.
Usage
nlme_fit(
data,
dose = 100,
start = list(m = 30, k = 1/100, beta = 2),
sample_minutes = 15
)
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. The dose only affects parameter |
start |
Optional start values. In most case, the default values are good
enough to achieve convergence, but slightly different values for |
sample_minutes |
When the mean sampling interval is < |
Value
A list of class ("breathtestnlmefit" "breathtestfit") with elements
- coef
Estimated parameters in a key-value format with columns
patient_id, group, parameter, stat, methodandvalue. Parameterstatcurrently always has value"estimate". Confidence intervals will be added later, so do not take for granted that all parameters are estimates. Has an attribute AIC which can be retrieved by the S3-functionAIC.- data
The data effectively fitted. If points are to closely sampled in the input, e.g. with BreathId devices, data are subsampled before fitting.
See Also
Base methods coef, plot, print; methods from package
broom: tidy, augment.
Examples
d = simulate_breathtest_data(n_records = 3, noise = 0.7, seed = 4712)
data = cleanup_data(d$data)
fit = nlme_fit(data)
plot(fit) # calls plot.breathtestfit
options(digits = 3)
library(dplyr)
cf = coef(fit)
# The coefficients are in long key-value format
cf
# AIC can be extracted
AIC(fit)
# Reformat the coefficients to wide format and compare
# with the expected coefficients from the simulation
# in d$record.
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)