找回密码
 注册
查看: 864|回复: 0

R语言 aroma.light包 weightedMedian()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-25 12:07:41 | 显示全部楼层 |阅读模式
weightedMedian(aroma.light)
weightedMedian()所属R语言包:aroma.light

                                        Weighted Median Value
                                         加权中值价值

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Computes a weighted median of a numeric vector.
计算加权中位数的数字向量。


用法----------Usage----------





参数----------Arguments----------

参数:x
a numeric vector containing the values whose weighted median is to be computed.
numericvector,包含的加权中位数是要计算的值。


参数:w
a vector of weights the same length as x giving the weights to use for each element of x. Negative weights are treated as zero weights. Default value is equal weight to all values.
相同的长度为x给权使用每个x元素的权重向量。负权重将被视为零重量。默认值是同等重量的所有值。


参数:na.rm
a logical value indicating whether NA values in x should be stripped before the computation proceeds, or not.  If NA, no check at all for NAs is done. Default value is NA (for effiency).
一个逻辑值,指明是否NA值x应该被剥夺之前,计算所得的,或没有。如果NA,没有在所有的检查NA的完成。默认值是NA(effiency)。


参数:interpolate
If TRUE, linear interpolation is used to get a consistant estimate of the weighted median.
如果TRUE,使用线性插值得到一个加权中位数洽场估计。


参数:ties
If interpolate == FALSE, a character string specifying how to solve ties between two x's that are satisfying the weighted median criteria. Note that at most two values can satisfy the criteria. When ties is "min", the smaller value of the two is returned and when it is "max", the larger value is returned. If ties is "mean", the mean of the two values is returned and if it is "both", both values are returned. Finally, if ties is "weighted" (or NULL) a weighted average of the two are returned, where the weights are weights of all values x[i] <= x[k] and x[i] >= x[k], respectively.
如果interpolate == FALSE,一个字符串,指定如何解决两个x的之间的关系,满足加权中位数标准。请注意,最多两个值能满足标准。当ties是"min",两个较小的值返回,当它是"max",值越大,则返回。 ties如果是"mean",这两个值的平均值,则返回,如果是"both",这两个值返回。最后,如果ties是"weighted"(或NULL)返回两者的加权平均,权重的地方x[i] <= x[k]和x[i] >= x[k]所有值的权重分别。


参数:method
If "shell", then order() is used and when method="quick", then internal qsort() is used.
如果"shell",则order()使用method="quick",然后内部qsort()使用。


参数:...
Not used.
不使用。


Details

详情----------Details----------

For the n elements x = c(x[1], x[2], ..., x[n]) with positive weights w = c(w[1], w[2], ..., w[n]) such that sum(w) = S, the weighted median is defined as the element x[k] for which the total weight of all elements x[i] < x[k] is less or equal to S/2 and for which the total weight of all elements x[i] > x[k] is less or equal to S/2 (c.f. [1]).
n元素x = c(x[1], x[2], ..., x[n])正权w = c(w[1], w[2], ..., w[n])等sum(w) = S,加权中位数为元素定义x[k]总重量为所有元素x[i] < x[k]是小于或等于S/2和所有元素总重量x[i] > x[k]是小于或等于S/2(CF [1])。

If w is missing then all elements of x are given the same positive weight. If all weights are zero, NA is returned.
w如果缺少那么所有元素x都给予同样积极的重量。如果所有的权重都为零,NA返回。

If one or more weights are Inf, it is the same as these weights have the same weight and the others has zero. This makes things easier for cases where the weights are result of a division with zero. In this case median() is used internally.
如果一个或多个重Inf,这些权重是一样具有相同的重量和其他具有零。这使事情变得容易的情况下,权重是一个零的表决结果。在这种情况下median()内部使用。

When all the weights are the same (after values with weight zero are excluded and Inf's are taken care of), median is used internally.
当所有的权重是相同的(重量零值后排除Inf的照顾),median内部使用的。

The weighted median solves the following optimization problem:
加权中位数解决了以下优化问题:

where x=(x_1,x_2,&hellip;,x_K) are scalars and w=(w_1,w_2,&hellip;,w_K) are the corresponding "weights" for each individual x value.
x=(x_1,x_2,&hellip;,x_K)标量和w=(w_1,w_2,&hellip;,w_K)是每一个人x值相应的“砝码”。


值----------Value----------

Returns the weighted median.
返回加权位数。


基准----------Benchmarks----------

When implementing this function speed has been highly prioritized and it also making use of the internal quick sort algorithm (from R v1.5.0). The result is that weightedMedian(x) is about half as slow as median(x). It is hard to say how much since it depends on the data set, but it is also hard to time it exactly since internal garbage collector etc might mess up the measurements.
当执行此功能的速度一直高度优先,同时也使内部的快速排序算法(R V1.5.0)。结果是,weightedMedian(x)是一半左右median(x)缓慢。这是很难说多少,因为它取决于数据集,但正是因为内部的垃圾收集器等可能搞砸了测量时间,也很难。

Initial test also indicates that method="shell", which uses order() is slower than method="quick", which uses internal qsort().  Non-weighted median can use partial sorting which is faster because all values do not have to be sorted.
初步试验还表明,method="shell",它使用order()是比method="quick",它使用内部qsort()慢。这是更快,因为所有的值没有进行排序可以使用部分非加权中位数排序。

See examples below for some simple benchmarking tests.
见下面的例子进行一些简单的基准测试。


作者(S)----------Author(s)----------



Henrik Bengtsson and Ola H鰏sjer, Centre for Mathematical
Sciences, Lund University.
Thanks to Roger Koenker, Econometrics, University of Illinois, for
the initial ideas.




参考文献----------References----------

The MIT Press, Massachusetts Institute of Technology, 1989.

参见----------See Also----------

median, mean() and weighted.mean.
median,mean()weighted.mean。


举例----------Examples----------


x <- 1:10
n <- length(x)

m1 &lt;- median(x)                           # 5.5[5.5]
m2 &lt;- weightedMedian(x)                   # 5.5[5.5]
stopifnot(identical(m1, m2))

w <- rep(1, n)
m1 &lt;- weightedMedian(x, w)                # 5.5 (default)[5.5(默认)]
m2 &lt;- weightedMedian(x, ties="weighted")  # 5.5 (default)[5.5(默认)]
m3 &lt;- weightedMedian(x, ties="min")       # 5[5]
m4 &lt;- weightedMedian(x, ties="max")       # 6[6]
stopifnot(identical(m1,m2))

# Pull the median towards zero[拉中位数接近零]
w[1] <- 5
m1 &lt;- weightedMedian(x, w)                # 3.5[3.5]
y &lt;- c(rep(0,w[1]), x[-1])                # Only possible for integer weights[唯一可能为整数的重量]
m2 &lt;- median(y)                           # 3.5[3.5]
stopifnot(identical(m1,m2))

# Put even more weight on the zero[零放在更重]
w[1] <- 8.5
weightedMedian(x, w)                # 2[2]

# All weight on the first value[所有重量上的第一个值]
w[1] <- Inf
weightedMedian(x, w)                # 1[1]

# All weight on the last value[所有重量上的最后一个值]
w[1] <- 1
w[n] <- Inf
weightedMedian(x, w)                # 10[10]

# All weights set to zero[所有的权重设置为零]
w <- rep(0, n)
weightedMedian(x, w)                # NA[不适用]

# Simple benchmarking[简单的基准测试]
bench <- function(N=1e5, K=10) {
  x <- rnorm(N)
  t <- c()
  gc()
  t[1] <- system.time(for (k in 1:K) median(x))[3]
  gc()
  t[2] <- system.time(for (k in 1:K) weightedMedian(x, method="quick"))[3]
  gc()
  t[3] <- system.time(for (k in 1:K) weightedMedian(x, method="shell"))[3]
  t <- t / t[1]
  t[4] <- t[2]/t[3]
  names(t) <- c("median", "wMed-quick", "wMed-shell", "quick/shell")
  t
}

print(bench(N=  5, K=1000))
print(bench(N=100, K=1000))
print(bench(N=1e3, K=100))
print(bench(N=1e5, K=10))
print(bench(N=1e6, K=1))


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 01:39 , Processed in 0.020158 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表