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

R语言 sfsmisc包 roundfixS()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-30 01:41:22 | 显示全部楼层 |阅读模式
roundfixS(sfsmisc)
roundfixS()所属R语言包:sfsmisc

                                        Round to Integer Keeping the Sum Fixed
                                         舍入到整数保持确定的数额。

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

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

Given a real numbers y_i with the particular property that &sum;_i y_i is integer, find integer numbers x_i which are close to y_i (     |x[i] - y[i]| < 1 for all i), and have identical &ldquo;marginal&rdquo; sum, sum(x) == sum(y).
给定一个实数y_i特定的属性&sum;_i y_i是整数,求整数x_i接近y_i(     |x[i] - y[i]| < 1 for all i),并具有相同的“边缘”的总和,sum(x) == sum(y)。

As I found later, the problem is known as &ldquo;Apportionment Problem&rdquo; and it is quite an old problem with several solution methods proposed historically, but only in 1982, Balinski and Young proved that there is no method that fulfills three natural desiderata.
后来我发现,这个问题被称为“分配问题”,这是一个很老的问题,历史上提出的几种解决方法,但仅在1982年,Balinski和年轻的证明,有没有一种方法能满足三个自然desiderata。

Note that the (first) three methods currently available here were all (re?)-invented by M.Maechler, without any knowledge of the litterature.  At the time of writing, I have not even checked to which (if any) of the historical methods they match.
(第一)目前有三种方法可在这里需要注意的是(重新)发明的M.Maechler,没有任何的LITTERATURE知识。在写作的时候,我什至都没有检查(如果有的话)的历史方法相匹配。


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


roundfixS(x, method = c("offset-round", "round+fix", "1greedy"))



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

参数:x
a numeric vector which must sum to an integer
一个数值向量总和必须为整数


参数:method
character string specifying the algorithm to be used.
字符串特别指定要使用的算法。


Details

详细信息----------Details----------

Without hindsight, it may be surprising that all three methods give identical results (in all situations and simulations considered), notably that the idea of "mass shifting" employed in the iterative "1greedy" algorithm seems equivalent to the much simpler idea used in "offset-round".
没有事后看来,它可能是令人惊讶的是,所有这三种方法得出相同的结果(在考虑所有情况,模拟),尤其是“质量转移”受雇在迭代的想法"1greedy"算法似乎更简单的想法用于在"offset-round"。

I am pretty sure that these algorithms solve the L_p optimization problem, min_x ||y - x||_p, typically for all p in [1,Inf] simultaneously, but have not bothered to find a formal proof.
我敢肯定,这些算法解决了L_p优化问题,min_x ||y - x||_p,通常为所有的p in [1,Inf]同时,但并没有费心去寻找一个正式的证明。


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

a numeric vector, say r, of the same length as x, but with integer values and fulfulling sum(r) == sum(x).
一个数值向量,说r,x,但与整数值和fulfulling sum(r) == sum(x)长度相同的。


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


Martin Maechler, November 2007



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

Fair Representation: Meeting the Ideal of One Man, One Vote;



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

round etc
round等


实例----------Examples----------


## trivial example[#简单的例子]
kk <- c(0,1,7)
stopifnot(identical(kk, roundfixS(kk))) # failed at some point[在某些时候失败]

x <- c(-1.4, -1, 0.244, 0.493, 1.222, 1.222, 2, 2, 2.2, 2.444, 3.625, 3.95)
sum(x) # an integer[整数]
r <- roundfixS(x)
stopifnot(all.equal(sum(r), sum(x)))
m <- cbind(x=x, `r2i(x)` = r, resid = x - r, `|res|` = abs(x-r))
rbind(m, c(colSums(m[,1:2]), 0, sum(abs(m[,"|res|"]))))

chk <- function(y) {
  cat("sum(y) =", format(S <- sum(y)),"\n")
  r2  <- roundfixS(y, method="offset")
  r2. <- roundfixS(y, method="round")
  r2_ <- roundfixS(y, method="1g")
  stopifnot(all.equal(sum(r2 ), S),
            all.equal(sum(r2.), S),
            all.equal(sum(r2_), S))
  all(r2 == r2. &amp;&amp; r2. == r2_) # TRUE if all give the same result[TRUE如果得到同样的结果]
}

makeIntSum <- function(y) {
   n <- length(y)
   y[n] <- ceiling(y[n]) - (sum(y[-n]) %% 1)
   y
}
set.seed(11)
y <- makeIntSum(rnorm(100))
chk(y)

## nastier example:[#厉害的例子:]
set.seed(7)
y <- makeIntSum(rpois(100, 10) + c(runif(75, min= 0, max=.2),
                                   runif(25, min=.5, max=.9)))
chk(y)

## Not run: [#不运行:]
for(i in 1:1000)
    stopifnot(chk(makeIntSum(rpois(100, 10) +
                             c(runif(75, min= 0, max=.2),
                               runif(25, min=.5, max=.9)))))

## End(Not run)[#(不执行)]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-21 17:06 , Processed in 0.027304 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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