Created
June 22, 2018 12:36
-
-
Save trinker/c9d3dc74fa9595f4562f4a3eaa2a4a91 to your computer and use it in GitHub Desktop.
Computing percentiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
percentile1 <- function(x) ecdf(x)(x) | |
percentile2 <- function(x) rank(x)/length(x) | |
library(tidyverse) | |
out <- data_frame( | |
x = rnorm(100000), | |
ecdf = ecdf(x)(x), | |
rank_len = rank(x)/length(x), | |
same = near(ecdf, rank_len) | |
) | |
x1 <- sort(rnorm(50, mean = .07, sd = .06)); x1 <- ifelse(x1 < 0, 0, x1) | |
percentile1(x1) | |
percentile2(x1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment