nls_fit {breathtestcore}R Documentation

Individual curve fit with nls to 13C breath test data


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 frame or tibble as created by cleanup_data, with mandatory columns patient_id, group, minute and pdr. It is recommended to run all data through cleanup_data which will insert dummy columns for patient_id and minute if the data are distinct, and report an error if not.


Dose of acetate or octanoate. Currently, only one common dose for all records is supported.


Optional start values patient_id and group.


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.

See Also

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)
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)

[Package breathtestcore version 0.8.1 Index]