ushr (version 0.1.0)

fit_model: Fit model and obtain parameter estimates

Description

This function fits either the biphasic or single phase model to the processed data and extracts the best-fit parameters.

Usage

fit_model(data, id_vector, param_names, initial_params, free_param_index,
  n_min_biphasic, model_list, whichcurve = get_biphasic,
  forward_param_transform_fn, inv_param_transform_fn, searchmethod)

Arguments

data

dataframe with columns for each subject's identifier ('id'), viral load measurements ('vl'), and timing of sampling ('time')

id_vector

vector of identifiers corresponding to the subjects to be fitted.

param_names

names of parameter vector.

initial_params

named vector of the initial parameter guess.

free_param_index

logical vector indicating whether the parameters A, delta, B, gamma are to be recovered. This should be c(TRUE, TRUE, TRUE, TRUE) for the biphasic model and c(FALSE, FALSE, TRUE, TRUE) for the single phase model.

n_min_biphasic

the minimum number of data points required to fit the biphasic model. Defaults to 6. It is highly advised not to go below this threshold.

model_list

character indicating which model is to be fit. Can be either 'four' for the biphasic model, or 'two' for the single phase model. Defaults to 'four'.

whichcurve

indicates which model prediction function to use. Should be get_biphasic for the biphasic model or get_singlephase for the singlephase model. Defaults to get_biphasic.

forward_param_transform_fn

list of transformation functions to be used when fitting the model in optim. Defaults to log transformations for all parameters (to allow unconstrained optimization).

inv_param_transform_fn

list of transformation functions to be used when back-transforming the transformed parameters. Should be the inverse of the forward transformation functions. Defaults to exponential.

searchmethod

optimization algorithm to be used in optim. Defaults to Nelder-Mead.