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.
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 isintensity = 1
. In case ofmethod = "regression"
it is the proportion of surrounding data influencing each data point, which isintensity = 0.2
by default.
Value
Returns a data frame (for each single-case) with smoothed data
points. See scdf
to learn about the format of these data
frames.
Details
moving_median
, moving_mean
, and local_regression
are
helper function for transform.scdf
returning the smoothed
values of a numeric vector.
See also
Other data manipulation functions:
add_l2()
,
as.data.frame.scdf()
,
as_scdf()
,
fill_missing()
,
moving_median()
,
outlier()
,
ranks()
,
rescale()
,
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)
#> Warning: This function is deprecated. It might be dropped without any further notice in a future update of scan.
#> Please use function 'scplot' from the package 'scplot' instead of 'plot'.
#> Warning: This function is deprecated. It might be dropped without any further notice in a future update of scan.
#> Please use function 'scplot' from the package 'scplot' instead of 'style_plot'.
Huber2014$Berta |>
transform(
"compliance (moving median)" = moving_median(compliance),
"compliance (moving mean)" = moving_mean(compliance),
"compliance (local regression)" = local_regression(compliance, mt)
)
#> #A single-case data frame with one case
#>
#> Berta: mt compliance phase compliance (moving median) compliance (moving mean)
#> 1 25 A 25 25
#> 2 20.8 A 25 28.47
#> 3 39.6 A 39.6 47.69
#> 4 75 A 45 55.9
#> 5 45 A 45 38.5
#> 6 14.6 A 45 32.97
#> 7 45.8 A 45 37.36
#> 8 33.3 A 33.3 33.99
#> 9 31.3 A 32.5 32.6
#> 10 32.5 A 32.5 23.1
#> 11 4.2 B 32.5 24.37
#> 12 45.8 B 32.5 33.82
#> 13 31.3 B 31.3 24.84
#> 14 9.4 B 9.4 13.51
#> 15 6.3 B 6.3 8
#> compliance (local regression)
#> 22.02
#> 28.81
#> 39.6
#> 42.3
#> 45
#> 45.4
#> 45.8
#> 36.07
#> 32.2
#> 32.5
#> 39.15
#> 45.8
#> 29.41
#> 15.05
#> 6.58
#> # ... up to 14 more rows