ctACF: Continuous Time Autocorrelation Function (ctACF)

View source: R/ctACF.R

ctACFR Documentation

Continuous Time Autocorrelation Function (ctACF)

Description

This function computes an approximate continuous time autocorrelation function (ACF) for data containing multiple subjects and/or variables.

Usage

ctACF(
  dat,
  varnames = "auto",
  ccfnames = "all",
  idcol = "id",
  timecol = "time",
  plot = TRUE,
  timestep = "auto",
  time.max = "auto",
  nboot = 100,
  ...
)

Arguments

dat

The input data in data frame or data table format.

varnames

Character vector of variable names in the data to compute the ACF for. 'auto' uses all columns that are not time / id.

ccfnames

Character vector of variable names in the data to compute cross correlation for. 'all' uses all variables in varnames.

idcol

The name of the column containing subject IDs (default is 'id').

timecol

The name of the column containing time values (default is 'time').

plot

A logical value indicating whether to create a plot (default is TRUE).

timestep

The time step for discretizing data. 'auto' to automatically determine the timestep based on data distribution (default is 'auto'). In this case the timestep is computed as 1/10th of the 10th percentile for time intervals in the data.

time.max

The maximum time lag to compute the ACF (default is 10). If 'auto', is set to 10 times the 90th percentile interval in the data.

nboot

The number of bootstrap samples for confidence interval estimation (default is 100).

...

additional arguments (such as demean=FALSE) to pass to the stats::acf function.

Details

This function computes the continuous time ACF by discretizing the data and then performing bootstrapped ACF calculations to estimate the confidence intervals. It can create ACF plots with confidence intervals if 'plot' is set to TRUE.

Value

If 'plot' is TRUE, the function returns a ggplot object of the ACF plot. If 'plot' is FALSE, it returns a data table with ACF estimates and confidence intervals.

See Also

ctDiscretiseData

Examples

data.table::setDTthreads(1) #ignore this line
# Example usage:
head(ctstantestdat)
ctACF(ctstantestdat,varnames=c('Y1'),idcol='id',timecol='time',nboot=5)


ctsem documentation built on Nov. 2, 2023, 6:03 p.m.