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 geometric mean #258

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

cumulative geometric mean #258

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 Geometric Mean
#' 
#' @family Vector Function
#' 
#' @author Steven P. Sanderson II, MPH
#' 
#' @details
#' A function to return the cumulative geometric mean of a vector.
#' `exp(cummean(log(.x)))`
#' 
#' @description 
#' A function to return the cumulative geometric mean of a vector.
#' 
#' @parm .x A numeric vector
#' 
#' @examples 
#' x <- mtcars$mpg
#' 
#' cgmean(x)
#' 
#' @return 
#' A numeric vector
#' 
#' @export
#' 

cgmean <- function(.x){
  exp(cummean(log(.x)))
}

Example:

> cgmean(x)
 [1] 21.00000 21.00000 21.58363 21.53757 20.93755 20.43547 19.41935 19.98155
 [9] 20.27666 20.16633 19.93880 19.61678 19.42805 19.09044 18.33287 17.69470
[17] 17.50275 18.11190 18.61236 19.17879 19.28342 19.09293 18.90457 18.62961
[25] 18.65210 18.92738 19.15126 19.46993 19.33021 19.34242 19.18443 19.25006
@spsanderson spsanderson self-assigned this Sep 19, 2022
@spsanderson spsanderson added the enhancement New feature or request label Sep 19, 2022
@spsanderson spsanderson added this to the TidyDensity 1.2.3 milestone Sep 19, 2022
spsanderson added a commit that referenced this issue Sep 19, 2022
Fixes #256
Fixes #257
Fixes #258
Fixes #260
Fixes #265
Fixes #266
Fixes #267
Fixes #268
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