exponentialFit: Fit an asymptotic decay model to reach deviations.

View source: R/models.R

exponentialFitR Documentation

Fit an asymptotic decay model to reach deviations.

Description

This function is part of a set of functions to fit and evaluate a simple exponential function to reach deviations.

Usage

exponentialFit(
  signal,
  timepoints = length(signal),
  mode = "learning",
  gridpoints = 11,
  gridfits = 10,
  setN0 = NULL,
  asymptoteRange = NULL
)

Arguments

signal

A vector of length N with reach deviation data. These should start around 0 and go up (ideally they are baselined).

timepoints

NULL or a vector of length N with the timepoints at which to evaluate the exponential. If NULL, the N values in 'signal' are placed at: 0, 1, ... N-2, N-1.

mode

A string, one of "learning" or "washout". For "learning" the signal starts at 0 and increases with exponentially decaying errors, going towards asymptote ("N0"), and for "washout" it starts at "N0" and approaches 0 over time.

gridpoints

Number of values for rate of change and asymptote, that are tested in a grid.

gridfits

Number of best results from gridsearch that are used for optimizing a fit.

setN0

NULL or number, if the asymptote is known, it can be set here.

asymptoteRange

NULL or a vector specifying the upper and lower bound for the asymptote (N0). If NULL, the range will be (-1,2) * max(signal) which may be too wide for very noisy data.

Details

?

Value

A named numeric vector with the optimal parameter that fits a simple rate model to the data as best as possible, with these elements: - lambda: the rate of change in the range [0,1] - N0: the asymptote (or starting value) in the unit of the signal

Examples

data(tworatedata)
learning <- rowMeans(tworatedata[which(tworatedata$block == 2),c(4:20)], na.rm=TRUE)
par <- exponentialFit(signal=learning)
par
plot(c(0:99), learning, ylim=c(0,35))
expfit <- Reach::exponentialModel(par=par, timepoints=seq(0,99,0.5))
lines(expfit, col='red')

thartbm/handlocs documentation built on Feb. 18, 2025, 10:53 p.m.