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

R语言:nearPD()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 20:58:01 | 显示全部楼层 |阅读模式
nearPD(Matrix)
nearPD()所属R语言包:Matrix

                                        Nearest Positive Definite Matrix
                                         最近正正定矩阵

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

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

Compute the nearest positive definite matrix to an approximate one, typically a correlation or variance-covariance matrix.
最近正定矩阵计算近似的,通常是相关或协方差矩阵。


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


nearPD(x, corr = FALSE, keepDiag = FALSE, do2eigen = TRUE,
       doSym = FALSE, doDykstra = TRUE, only.values = FALSE,
       ensureSymmetry = !isSymmetric(x),
       eig.tol = 1e-06, conv.tol = 1e-07, posd.tol = 1e-08,
       maxit = 100, trace = FALSE)



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

参数:x
numeric n * n approximately positive definite matrix, typically an approximation to a correlation or covariance matrix.  If x is not symmetric (and ensureSymmetry is not false), symmpart(x) is used.
数字n * n约正定矩阵,通常是相关或协方差矩阵的近似。 x如果不是对称的(ensureSymmetry是不是假的),symmpart(x)使用。


参数:corr
logical indicating if the matrix should be a correlation matrix.
逻辑表明,如果矩阵应该是一个相关矩阵。


参数:keepDiag
logical, generalizing corr: if TRUE, the resulting matrix should have the same diagonal (diag(x)) as the input matrix.
逻辑,归纳corr如果TRUE,由此产生的基质应具有相同的输入矩阵对角线(diag(x))。


参数:do2eigen
logical indicating if a posdefify() eigen step should be applied to the result of the Higham algorithm.
逻辑表明如果posdefify()特征一步应适用于海厄姆算法的结果。


参数:doSym
logical indicating if X <- (X + t(X))/2 should be done, after X <- tcrossprod(Qd, Q); some doubt if this is necessary.
逻辑指示X <- (X + t(X))/2应该做的,后X <- tcrossprod(Qd, Q);一些疑问,如果这是必要的。


参数:doDykstra
logical indicating if Dykstra's correction should be used; true by default.  If false, the algorithm is basically the direct fixpoint iteration Y(k) = P_U(P_S(Y(k-1))).
Dykstra的校正应使用逻辑表示,默认为true。如果为false,该算法基本上是直接的不动点迭代Y(k) = P_U(P_S(Y(k-1)))。


参数:only.values
logical; if TRUE, the result is just the vector of eigen values of the approximating matrix.
逻辑,如果TRUE,结果只是近似矩阵的特征值的向量。


参数:ensureSymmetry
logical; by default, symmpart(x) is used whenever isSymmetric(x) is not true.  The user can explicitly set this to TRUE or FALSE, saving the symmetry test. Beware however that setting it FALSE for an asymmetric input x, is typically nonsense!
逻辑;默认情况下,symmpart(x)时使用isSymmetric(x)是不正确的。用户可以明确地设置TRUE或FALSE,节省对称测试。但是当心,设置FALSE不对称输入x,通常是无稽之谈!


参数:eig.tol
defines relative positiveness of eigenvalues compared to largest one, &lambda;_1. Eigen values &lambda;_k are treated as if zero when &lambda;_k / &lambda;_1 &le; eig.tol.
定义相对比最大的一个积极性的特征值,&lambda;_1。特征值&lambda;_k被视为零,如果当&lambda;_k / &lambda;_1 &le; eig.tol。


参数:conv.tol
convergence tolerance for Higham algorithm.
海厄姆算法的收敛公差。


参数:posd.tol
tolerance for enforcing positive definiteness (in the final posdefify step when do2eigen is TRUE).
宽容执行正定(在最后posdefify步do2eigen是TRUE)。“


参数:maxit
maximum number of iterations allowed.
迭代允许的最大数量。


参数:trace
logical or integer specifying if convergence monitoring should be traced.
逻辑或整数,指定应追溯到收敛监测。


Details

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

This implements the algorithm of Higham (2002), and then (if do2eigen is true) forces positive definiteness using code from posdefify.  The algorithm of Knol DL and ten Berge (1989) (not implemented here) is more general in (1) that it allows constraints to fix some rows (and columns) of the matrix and (2) to force the smallest eigenvalue to have a certain value.
实现海厄姆(2002年)的算法,然后(如果do2eigen是真实的)强制使用代码从posdefify正定。 Knol的DL和十贝格(1989)(未实现)算法是(1),它允许约束,以解决一些矩阵行(列)和(2)强制的最小特征值,有一个更一般的一定的价值。

Note that setting corr = TRUE just sets diag(.) <- 1 within the algorithm.
请注意,设置corr = TRUE设置diag(.) <- 1内的算法。

Higham (2002) uses Dykstra's correction, but the version by Jens Oehlschlaegel did not use it (accidentally), and has still lead to good results; this simplification, now only via doDykstra = FALSE, was active in nearPD() upto Matrix version 0.999375-40.
海厄姆使用Dykstra的修正(2002),但没有由Jens Oehlschlaegel的版本不使用它(意外),仍然引起了良好的效果,这种简化,现在只能通过doDykstra = FALSE,nearPD()积极高达矩阵0.999375-40版本。


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

If only.values = TRUE, a numeric vector of eigen values of the approximating matrix; Otherwise, as by default, an S3 object of class "nearPD", basically a list with components
如果only.values = TRUE,逼近矩阵的特征值的数值向量;否则,默认情况下,S3对象的class"nearPD",基本上是一个列表组件


参数:mat
a matrix of class dpoMatrix, the computed positive-definite matrix.
一类dpoMatrix,计算正定矩阵的矩阵。


参数:eigenvalues
numeric vector of eigen values of mat.
mat特征值的数值向量。


参数:corr
logical, just the argument corr.
逻辑,只是参数corr。


参数:normF
the Frobenius norm (norm(x-X, "F")) of the difference between the original and the resulting matrix.
Frobenius范数(norm(x-X, "F"))之间原有的差异以及由此产生的矩阵。


参数:iterations
number of iterations needed.
所需的迭代数。


参数:converged
logical indicating if iterations converged.
逻辑表示如果迭代收敛。


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


Jens Oehlschlaegel donated a first version.  Subsequent changes
by the Matrix package authors.




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

A Modified Cholesky Algorithm Based on a Symmetric Indefinite Factorization; SIAM J. Matrix Anal.\ Appl., 19, 1097&ndash;1110.
Least-squares approximation of an improper correlation matrix by a proper one. Psychometrika 54, 53&ndash;61.
Computing the nearest correlation matrix - a problem from finance; IMA Journal of Numerical Analysis 22, 329&ndash;343.

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

A first version of this (with non-optional corr=TRUE) has been available as nearcor(); and more simple versions with a similar purpose posdefify(), both from package sfsmisc.
一直的第一个版本(非选择性corr=TRUE)nearcor();类似用途posdefify()包sfsmisc,更简单的版本。


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


## Higham(2002), p.334f - simple example[#海厄姆(2002),p.334f  - 简单的例子]
A <- matrix(1, 3,3); A[1,3] <- A[3,1] <- 0
n.A <- nearPD(A, corr=TRUE, do2eigen=FALSE)
n.A[c("mat", "normF")]
stopifnot(all.equal(n.A$mat[1,2], 0.760689917),
           all.equal(n.A$normF, 0.52779033, tol=1e-9) )

set.seed(27)
m <- matrix(round(rnorm(25),2), 5, 5)
m <- m + t(m)
diag(m) <- pmax(0, diag(m)) + 1
(m <- round(cov2cor(m), 2))

str(near.m <- nearPD(m, trace = TRUE))
round(near.m$mat, 2)
norm(m - near.m$mat) # 1.102 / 1.08[1.102 / 1.08]

if(require("sfsmisc")) {
    m2 &lt;- posdefify(m) # a simpler approach[一个简单的方法]
    norm(m - m2)  # 1.185, i.e., slightly "less near"[1.185,即略“少近”]
}

round(nearPD(m, only.values=TRUE), 9)

## A longer example, extended from Jens' original,[#例如,从延原延长,]
## showing the effects of some of the options:[#显示一些选项的效果:]

pr <- Matrix(c(1,     0.477, 0.644, 0.478, 0.651, 0.826,
               0.477, 1,     0.516, 0.233, 0.682, 0.75,
               0.644, 0.516, 1,     0.599, 0.581, 0.742,
               0.478, 0.233, 0.599, 1,     0.741, 0.8,
               0.651, 0.682, 0.581, 0.741, 1,     0.798,
               0.826, 0.75,  0.742, 0.8,   0.798, 1),
             nrow = 6, ncol = 6)

nc.  &lt;- nearPD(pr, conv.tol = 1e-7) # default[默认]
nc.$iterations  # 2[2]
nc.1 <- nearPD(pr, conv.tol = 1e-7, corr = TRUE)
nc.1$iterations # 11 / 12 (!)[11/12(!)]
ncr   <- nearPD(pr, conv.tol = 1e-15)
str(ncr)# still 2 iterations[还有2次迭代]
ncr.1 <- nearPD(pr, conv.tol = 1e-15, corr = TRUE)
ncr.1 $ iterations # 27 / 30 ![27/30!]

## But indeed, the 'corr = TRUE' constraint did ensure a better solution;[#但实际上,“更正= TRUE”的约束,确保更好的解决方案;]
## cov2cor() does not just fix it up equivalently :[#cov2cor()不只是修复了等价:]
norm(pr - cov2cor(ncr$mat)) # = 0.09994[= 0.09994]
norm(pr -       ncr.1$mat)  # = 0.08746 / 0.08805[= 0.08746 / 0.08805]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 02:10 , Processed in 0.024807 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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