Skip to content

Commit

Permalink
fix diff method (breaking)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Jun 24, 2024
1 parent ce47b60 commit e0e9894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions R/smoothness.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Functions to quantify the smoothness of a vector, which can be used in some cases
#' as an index of "linearity". A smooth series is one that does not have abrupt changes in
#' its values. The smoothness of a series can be measured in different ways, such
#' its values. The smoothness of a series can be approximated in different ways, such
#' as the standard deviation of the standardized differences or the lag-one
#' autocorrelation.
#'
Expand All @@ -25,6 +25,10 @@
#' # When perfectly linear, the "smoothness" is 1
#' smoothness(1:10)
#'
#' # And closer to zero for random
#' smoothness(rnorm(1000))
#' smoothness(rnorm(1000), method = "diff")
#'
#' @return Value of smoothness.
#' @references https://stats.stackexchange.com/questions/24607/how-to-measure-smoothness-of-a-time-series-in-r
#'
Expand Down Expand Up @@ -54,7 +58,8 @@ smoothness.numeric <- function(x,
if (method == "cor") {
smooth <- stats::cor(utils::head(x, length(x) - lag), utils::tail(x, length(x) - lag))

Check warning on line 59 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/smoothness.R,line=59,col=5,[object_overwrite_linter] 'smooth' is an exported object from package 'stats'. Avoid re-using such symbols.

Check warning on line 59 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/smoothness.R,line=59,col=5,[object_overwrite_linter] 'smooth' is an exported object from package 'stats'. Avoid re-using such symbols.
} else {
smooth <- stats::sd(diff(x, lag = lag)) / abs(mean(diff(x, lag = lag)))
diff <- standardize(diff(x))

Check warning on line 61 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/smoothness.R,line=61,col=5,[object_overwrite_linter] 'diff' is an exported object from package 'base'. Avoid re-using such symbols.

Check warning on line 61 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/smoothness.R,line=61,col=5,[object_overwrite_linter] 'diff' is an exported object from package 'base'. Avoid re-using such symbols.
smooth <- 1 - mean((diff(diff) ** 2) / 4) # Note the reversal to match the other method

Check warning on line 62 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/smoothness.R,line=62,col=5,[object_overwrite_linter] 'smooth' is an exported object from package 'stats'. Avoid re-using such symbols.

Check warning on line 62 in R/smoothness.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/smoothness.R,line=62,col=5,[object_overwrite_linter] 'smooth' is an exported object from package 'stats'. Avoid re-using such symbols.
}

if (!is.null(iterations)) {
Expand Down
6 changes: 5 additions & 1 deletion man/smoothness.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0e9894

Please sign in to comment.