smooth_cases: Smoothing single-case data

View source: R/deprec-smooth_cases.R

smooth_casesR Documentation

Smoothing single-case data

Description

This function is superseded by the more versatile transform.scdf function. The smooth_cases function provides procedures to smooth single-case data (i.e., to eliminate noise). A moving average function (mean- or median-based) replaces each data point by the average of the surrounding data points step-by-step. With a local regression function, each data point is regressed by its surrounding data points.

Usage

smooth_cases(data, dvar, mvar, method = "mean", intensity = NULL, FUN = NULL)

Arguments

data

A single-case data frame. See scdf() to learn about this format.

dvar

Character string with the name of the dependent variable. Defaults to the attributes in the scdf file.

mvar

Character string with the name of the measurement time variable. Defaults to the attributes in the scdf file.

method, FUN

Method determining the smoothed scores. Default method = "median" is a moving median function. Further possible values are: "mean" and a non-parametric "regression".

intensity

For method = "median" and "mean" it is the lag used for computing the average. Default is intensity = 1. In case of method = "regression" it is the proportion of surrounding data influencing each data point, which is intensity = 0.2 by default.

Details

moving_median, moving_mean, and local_regression are helper function for transform.scdf returning the smoothed values of a numeric vector.

Value

Returns a data frame (for each single-case) with smoothed data points. See scdf to learn about the format of these data frames.

Author(s)

Juergen Wilbert

See Also

Other data manipulation functions: add_l2(), as.data.frame.scdf(), as_scdf(), fill_missing(), moving_median(), outlier(), ranks(), scdf(), select_cases(), set_vars(), shift(), standardize(), truncate_phase()

Examples


## Use the three different smoothing functions and compare the results
study <- c(
  "Original" = Huber2014$Berta,
  "Moving median" = smooth_cases(Huber2014$Berta, method = "median"),
  "Moving mean" = smooth_cases(Huber2014$Berta, method = "mean"),
  "Local regression" = smooth_cases(Huber2014$Berta, method = "regression")
)
plot(study)

Huber2014$Berta %>% 
transform(
  "compliance (moving median)" = moving_median(compliance),
  "compliance (moving mean)" = moving_mean(compliance),
  "compliance (local regression)" = local_regression(compliance, mt)
)


scan documentation built on July 1, 2024, 9:07 a.m.