Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cumulative kurtosis #266

Closed
Tracked by #250
spsanderson opened this issue Sep 19, 2022 · 0 comments · Fixed by #269
Closed
Tracked by #250

cumulative kurtosis #266

spsanderson opened this issue Sep 19, 2022 · 0 comments · Fixed by #269
Assignees
Labels
enhancement New feature or request

Comments

@spsanderson
Copy link
Owner

spsanderson commented Sep 19, 2022

Function:

#' Cumulative Kurtosis
#' 
#' @family Vector Function
#' 
#' @author Steven P. Sanderson II, MPH
#' 
#' @details
#' A function to return the cumulative kurtosis of a vector.
#' 
#' @description 
#' A function to return the cumulative kurtosis of a vector.
#' 
#' @parm .x A numeric vector
#' 
#' @examples 
#' x <- mtcars$mpg
#' 
#' ckurtosis(x)
#' 
#' @return 
#' A numeric vector
#' 
#' @export
#' 

ckurtosis <- function(.x){
  kurtosis <- function(.x){
    length(.x) * sum((.x - mean(.x))^4) / (sum((.x - mean(.x))^2)^2)
  }
  sapply(seq_along(.x), function(k, z) kurtosis(z[1:k]), z = .x)
}

Example:

x <- mtcars$mpg

> ckurtosis(x)
 [1]      NaN      NaN 1.500000 2.189216 2.518932 1.786006 2.744467 2.724675
 [9] 2.930885 2.988093 2.690270 2.269038 2.176622 1.992044 2.839430 2.481896
[17] 2.356826 3.877115 3.174702 2.896931 3.000743 3.091225 3.182071 3.212816
[25] 3.352916 3.015952 2.837139 2.535185 2.595908 2.691103 2.738468 2.799467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant