反转R中优化的输入和输出

问题描述 投票:0回答:1

也许这太简单了。但是下面我展示了一个优化,其中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个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.