Skip to content

Commit

Permalink
compute_median() change
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalomarques8 committed May 27, 2024
1 parent ea06311 commit 087e169
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/compute_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,15 @@ compute_median <- function(file, file_name, variable, weight = NULL, na.rm = FAL
}


# the original function from Hsmisc is incredibly buggy. It would return a result with NAs and na.rm = F.
# the original function from Hsmisc is incredibly buggy. It would return a result with NAs and na.rm = F. ## OLD COMMENT
if(!na.rm & (any(is.na(file[[variable]])) | any(is.na(weight_)) )){
return(NA)
}

unname(matrixStats::weightedMedian(x = file[[variable]],
w = weight_,
na.rm = na.rm))
unname(wtd.quantile(x = var, weights = weight_, probs = 0.5,
na.rm = na.rm, normwt = TRUE))
# previous functions matrixStats::weightedMedian wasn't outputing the same values as STATA, when weights were being applied.
# The argument "ties" was also working is a very wierd way. We will resort to the same method as in compute_percentiles() but with probs = 0.5.

}

Expand Down

0 comments on commit 087e169

Please sign in to comment.