TElm: [Robust] linear model with nonlinear time predictor

View source: R/TElm.R

TElmR Documentation

[Robust] linear model with nonlinear time predictor

Description

Fit a linear model or robust linear model with time as a covariate, while estimating the shape of the nonlinear interpolation between starting and ending time. First resamples data with replacement 200 times, and each time estimates the best-shaped curve to interpolate between initial time-related offset and asymptotic time (i.e., rate at which effect of time saturates at zero). Then uses the mean estimated rate to transform the timeVar predictor into an exponentially decaying variable interpolating between initial time (time offset magnitude of 1) and arbitrarily large time values (time offset magnitude 0). Last uses this transformed time variable in a tef_rlm_boot [rlm or lm] model (i.e., attempts to answer the question "how different was the start than the end?").

Usage

TElm(
  formIn,
  dat,
  timeVar,
  startingOffset = T,
  robust = F,
  fixRate = NA,
  nBoot = 250
)

Arguments

formIn

model formula, as in lm()

dat

model data, as in lm()

timeVar

String. Indicates which model predictor is time (i.e., should be transformed). Must be numeric and positive.

startingOffset

By default (if T) time is coded to start at 1 and saturate to 0. If startingOffset is F, time starts at 0 and saturates to 1. May assist in interpreting interactions with other variables, etc.

robust

Logical. Should rlm be used?

fixRate

If numeric, use this as a rate parameter [binary-log of 50 percent time constant] rather than estimating it (e.g., to improve reproducibility)

nBoot

Number of bootstrapped models to fit after rate [time constant] has been estimated (passed to tef_rlm_boot)

Details

Rate is parameterized as a time constant, or the amount of time it takes for half of change to occur. The value of rate has a lower bound of the .0333 quantile of the time variable (i.e., 87.5% of change happens in the first 10% of time) and an upper bound of the .333 quantile of the time variable (i.e., 87.5% of change takes 100% of the time to happen). These bounds provide some robustness in estimates of asympototic effects (i.e., "controlling for time") as well as initial effects (i.e., "time-related starting offset"). Uses this transformed time variable in a tef_rlm_boot model to estimate bootstrapped parameter coefficients and out-of-sample prediction.

Mean estimated rate is calculated after trimming the upper 25% and lower 25% of bootstrapped rate estimates, for robustness to extremes in resampling.

Note

The TElm approach to including a nonlinear time function in regression is quite different than the TEfit approach. TElm utilizes a point estimate for the rate parameter in order to coerce the model into a generalized linear format; TEfit simultaneously finds the best combination of rate, start, and asympote parameters. In effect, TElm treats magnitude of change as being of theoretical interest (and rate as a nuisance parameter to be controlled for), while TEfit treats the starting value, rate, and the asymptotic value as each being of theoretical interest.

See Also

TElmem for mixed-effects extension of TElm; TEglm for generalized extension of TElm

Examples

dat <- data.frame(trialNum = 1:200, resp = log(11:210)+rnorm(200))

# using a Linear Model
m_lm <- TElm(resp ~ trialNum,dat, 'trialNum')
summary(m_lm)
m_lm$bootSummary
m_lm$rate

# using a Robust Linear Model
m_rlm <- TElm(resp ~ trialNum,dat,'trialNum',robust=TRUE)
summary(m_rlm)
m_rlm$bootSummary
m_rlm$rate

# comparing fits
plot(dat[,c('trialNum','resp')])
lines(dat$trialNum,fitted(m_lm),col='blue')
lines(dat$trialNum,fitted(m_rlm),col='red')

# Examining the bootstrapped rates and other parameters together
summary(m_rlm$bootRate)
cor(m_rlm$bootRate)


akcochrane/TEfits documentation built on June 12, 2025, 11:10 a.m.