| preprocess | R Documentation |
Builds the same lag-1 design used by fit_graphical_var() and fit_var(),
optionally detrends or differences each series, and returns tidy diagnostics
for missingness, day-boundary drops, simple linear trends, AR(1) persistence,
split-half mean/variance drift, an ADF-style unit-root screen, and
zero-variance variables. It makes the modelling input explicit before
estimating VAR, graphical VAR, uSEM, GIMME, or mlVAR models; with detrend
it also cleans a non-stationary series in place so the flags can be
rechecked on the transformed data.
preprocess(
data,
vars,
id = NULL,
day = NULL,
beep = NULL,
scale = TRUE,
center_within = TRUE,
detrend = "none",
checks = c("trend", "high_ar", "unit_root", "mean_shift", "sd_shift", "zero_variance"),
delete_missings = TRUE,
min_obs = NULL,
subject = NULL,
trend_alpha = 0.05,
ar_threshold = 0.95,
mean_shift_threshold = 0.8,
sd_ratio_threshold = 2,
unit_root_t_cutoff = -2.86
)
data |
A |
vars |
Character vector of variable names. |
id |
Character. Name of the person-ID column, or |
day |
Character. Name of the day/session column, or |
beep |
Character. Name of the measurement-occasion column, or |
scale |
Logical. Whether to standardize variables before lagging.
Default |
center_within |
Logical. Whether to centre within person when more than
one id is present. Default |
detrend |
How to remove non-stationarity from each series before
lagging. Either a single string applied to every variable, or a
named character vector giving a per-variable method (unlisted variables
are left untouched, e.g.
The diagnostics and the returned design reflect the detrended series, so the trend and unit-root flags can be rechecked after cleaning. |
checks |
Character vector selecting which stationarity checkups to run:
any of |
delete_missings |
Logical. If |
min_obs |
Integer or |
subject |
Optional vector naming the subject(s) to preprocess. |
trend_alpha |
Numeric p-value cutoff for the trend flag. Default |
ar_threshold |
Numeric absolute AR(1) cutoff for the high-persistence
flag. Default |
mean_shift_threshold |
Numeric absolute standardized split-half mean
shift cutoff. Default |
sd_ratio_threshold |
Numeric split-half SD ratio cutoff. Default |
unit_root_t_cutoff |
Numeric cutoff for the ADF-style lag-level
t-statistic. Values greater than this cutoff are flagged as unit-root risk.
Default |
A preprocess_result object with:
pairsThe ordered current/lagged design table, including
intercept and L1_* columns.
countsPer-subject/per-day row and lag-pair counts.
diagnosticsPer-subject/per-variable missingness, trend, AR(1), split-half drift, unit-root screen, and stationarity risk indicators.
matricesThe exact data_c and data_l matrices returned by
the VAR/GVAR preprocessing path.
set.seed(1)
d <- data.frame(id = 1, day = 1, beep = 1:40,
A = cumsum(rnorm(40)), B = rnorm(40))
pp <- preprocess(d, vars = c("A", "B"), id = "id", day = "day", beep = "beep")
pp$counts
pp$diagnostics
# Difference the trending series and recheck the flags:
preprocess(d, vars = c("A", "B"), id = "id", day = "day", beep = "beep",
detrend = "difference")$diagnostics
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.