【问题标题】:Reversing the input and output of an optimization in R反转 R 中优化的输入和输出
【发布时间】:2018-02-28 22:56:24
【问题描述】:

也许这个问题太简单了。但下面我展示了一个优化,其中dfq 是输入,ncp 是输出。

我想知道如何扭转这种优化,以便我可以输入qncp(即,ncp 当前是输出),而不是得到df 作为输出?

df = 30 ; q = 2

f <- function (ncp, alpha, q, df){
abs(suppressWarnings(pt(q = q, df = df, ncp, lower.tail = FALSE)) - alpha)
}

sapply(c(.025, .975),
 function(x)optimize(f, interval = c(-20, 20), alpha = x, q = q, df = df)[[1]])

 # [1] -0.03931343  4.00808666  # Current output `ncp`, but want to become input#

【问题讨论】:

    标签: r function optimization


    【解决方案1】:
     Map(optimise,c(f),ncp=c(-0.03931343,4.00808666),alpha=c(.025, .975),q=q,interval=list(c(0,50)))
    [[1]]
    [[1]]$minimum
    [1] 29.9967
    
    [[1]]$objective
    [1] 4.711409e-09
    
    
    [[2]]
    [[2]]$minimum
    [1] 30.01264
    
    [[2]]$objective
    [1] 1.349743e-09
    
    mapply(optimise,c(f),ncp=c(-0.03931343,4.00808666),alpha=c(.025, .975),q=q,interval=list(c(0,50)))[1,]
    [[1]]
    [1] 29.9967
    
    [[2]]
    [1] 30.01264
    

    【讨论】:

      猜你喜欢
      • 2015-10-05
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2021-07-25
      • 2018-01-02
      相关资源
      最近更新 更多