【问题标题】:How to use of nloptr library to maximize Spearman correlation between two arrays如何使用 nloptr 库来最大化两个数组之间的 Spearman 相关性
【发布时间】:2019-06-26 08:52:58
【问题描述】:

我有两个数组。比如第一个是A,第二个是B:

A

我也有常数 teta=1。 我做了一个数组:

D=B-teta

以及A和D之间的相关系数

科夫

挑战是通过改变常数 teta 使 koeff 成为最大值。 据我了解,我可以使用 nloptr 库。应该怎么用?

最好的问候!

附:我用求解器一般减少梯度在 excel 中完成了这项工作。我在 R 中没有找到这个函数。

【问题讨论】:

  • Spearman 相关性排名正确吗?所以固定的位移(这不会改变排名)不会产生影响。
  • 对不起,你是对的。
  • D= log(D+teta) 那是正确的数组
  • log(x(i)+ϑ) 也不会改变排名(它是单调的)。您可能需要先考虑一下这个问题。
  • 欧文,我在 excel 中做了这样的工作。如果 teta 接近 -2,则相关性正在增长。我不知道怎么做。我想通过功能优化来做这样的工作

标签: r row regression nonlinear-optimization nlopt


【解决方案1】:

说明log(B+ϑ) 不会更改顺序。

> # ranks for different theta
> theta <- -1; rank(log(B+theta))
[1] 5 1 2 3 4
> theta <- 3; rank(log(B+theta))
[1] 5 1 2 3 4
> theta <- 10; rank(log(B+theta))
[1] 5 1 2 3 4
> # theta=-2 is a border case: we get -infinity
> theta=-2; log(B+theta)
[1] 2.397895     -Inf 1.386294 1.791759 2.302585
> rank(log(B+theta))
[1] 5 1 2 3 4
>

因此,所有 Spearman 相关性都应该相同:

> A <- c(2,5,6,10,11)
> cor(A,B,method="spearman")
[1] 0
> theta <- -1; cor(A,log(B+theta),method="spearman")
[1] 0
> theta <- 3; cor(A,log(B+theta),method="spearman")
[1] 0
> theta <- 10; cor(A,log(B+theta),method="spearman")
[1] 0
> theta <- -2; cor(A,log(B+theta),method="spearman")
[1] 0
> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 2023-03-26
    • 2018-03-31
    • 2018-11-04
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 2013-03-30
    相关资源
    最近更新 更多