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

Switch to Position-Based Percentile Calculation for Regulatory Compliance | timeAverage #396

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
12 changes: 10 additions & 2 deletions R/timeAverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
#' }
timeAverage <- function(mydata, avg.time = "day", data.thresh = 0,
statistic = "mean", type = "default", percentile = NA,
percentileInterpolation=TRUE,
start.date = NA, end.date = NA, interval = NA,
vector.ws = FALSE, fill = FALSE, progress = TRUE, ...) {

Expand Down Expand Up @@ -236,9 +237,16 @@ timeAverage <- function(mydata, avg.time = "day", data.thresh = 0,
}
}

if (statistic == "percentile") {
if (statistic == "percentile" & percentileInterpolation==TRUE) {
FUN <- function(x)
quantile(x, probs = percentile, na.rm = TRUE)
quantile(x, probs = percentile,na.rm = TRUE)
} else if (statistic == "percentile" & percentileInterpolation==FALSE){
FUN <-function(x){
sorted_data <- sort(na.omit(x))
n <- length(sorted_data)
position <- trunc(((percentile) * n)+sign(((percentile) * n))*0.5)
return(sorted_data[position])
}
}

calc.mean <- function(mydata, start.date) { ## function to calculate means
Expand Down