View source: R/pipeline-detrend.R
| detrend | R Documentation |
Detrend pupil data by fitting a model of pupil_data ~ time and returning
the fitted values (the estimated trend) together with the residuals
(pupil_data - fitted_values). Two trend models are supported via the
method argument: "linear" (the default) removes a straight-line drift by
fitting an ordinary linear model, while "spline" removes a smooth,
potentially nonlinear drift by fitting a natural cubic spline basis of time
(splines::ns(time, df = spline_df)).
detrend(
eyeris,
method = c("linear", "spline"),
spline_df = 5,
call_info = NULL
)
eyeris |
An object of class |
method |
A string indicating the detrending model to fit. Either
|
spline_df |
The degrees of freedom for the natural cubic spline basis
used when |
call_info |
A list of call information and parameters. If not provided,
it will be generated from the function call. Defaults to |
This function is automatically called by glassbox() if detrend = TRUE.
Users should prefer using glassbox() rather than invoking this function
directly unless they have a specific reason to customize the pipeline
manually.
An eyeris object with two new columns in time series:
detrend_fitted_values, and pupil_raw_{...}_detrend
This function is part of the glassbox() preprocessing pipeline and is not
intended for direct use in most cases. Use glassbox(detrend = TRUE) for
linear detrending, or glassbox(detrend = list(method = "spline")) for
spline detrending.
Advanced users may call it directly if needed.
glassbox() for the recommended way to run this step as
part of the full eyeris glassbox preprocessing pipeline
For a complete, end-to-end reference pipeline that demonstrates how all
eyeris preprocessing functions are chained together in practice, see the
"Building Blocks Under the Hood" section of the Anatomy of an eyeris
Object vignette — vignette("anatomy", package = "eyeris") — as
well as the Complete Pupillometry Pipeline Walkthrough vignette:
vignette("complete-pipeline", package = "eyeris").
demo_data <- eyelink_asc_demo_dataset()
# (a) linear detrending (the default)
demo_data |>
eyeris::glassbox(detrend = TRUE) |> # set to FALSE to skip step (default)
# a wider `preview_window` makes the (slow) fitted trend easier to see
plot(seed = 0, preview_window = c(5, 20))
# (b) spline detrending (removes a smooth, nonlinear trend)
demo_data |>
eyeris::glassbox(detrend = list(method = "spline", spline_df = 5)) |>
plot(seed = 0, preview_window = c(5, 20))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.