我想知道由dynutils包在包scale_quantile中是什么公式。我想检查一下,我是否能达到像这样的手工计算一样的结果。
# Air quality dataset
data = datasets::airquality
# Manual calculation
dat = data$Wind
#Calcuate quantile
q_995 = quantile(dat, 0.995)
q_005 = quantile(dat, 0.005)
#Filtering the data based on the quantile value
dat = dat[dat >= q_005 & dat <= q_995]
MEAN = mean(dat)
SD = sd(dat)
manual = (dat - MEAN)/SD这是我参考的文档站点,比额表文件_分位数。
发布于 2021-07-27 03:52:16
您可以查看源代码,也可以查看巨石阵。
scale_quantile <- function(x, outlier_cutoff = .05) {
if (is.null(dim(x))) {
sc <- scale_quantile(matrix(x, ncol = 1), outlier_cutoff = outlier_cutoff)
out <- sc[,1]
names(out) <- names(x)
attr(out, "addend") <- attr(sc, "addend")
attr(out, "multiplier") <- attr(sc, "multiplier")
out
} else {
quants <- apply(x, 2, stats::quantile, c(outlier_cutoff, 1 - outlier_cutoff), na.rm = TRUE)
addend <- -quants[1,]
divisor <- apply(quants, 2, diff)
divisor[divisor == 0] <- 1
apply_quantile_scale(x, addend, 1 / divisor)
}
}https://datascience.stackexchange.com/questions/98331
复制相似问题