我从OLS获得了两个函数,用于从一组编码数据中获取mean和std dev。我正在使用solnp执行优化,通过使用低于R代码最小化目标均值函数= 500的函数std dev。
但是,我的x编码数据仅设置为-1到1,但数据可能超出间隔。如何显示mean和std dev的优化值?
fn1=function(x) {S=intercept1+x1S*x[1]+x2S*x[2]+x3S*x[3]+x4S*x[1]*x[2]+x5S*x[1]*x[3]+x6S*x[2]*x[ 3]+x7S*x[1]^2+x8S*x[2]^2+x9S*x[3]^2
} eqn1=function(x) {m=intercept2+x1m*x[1]+x2m*x[2]+x3m*x[3]+x4m*x[1]*x[2]+x5m*x[1]*x[3]+x6m*x[2]*x[ 3]+x7m*x[1]^2+x8m*x[2]^2+x9m*x[3]^2
}
constraint=c(500)
x0 = c(-1, -1, -1)
LG=solnp(x0, fun = fn1, eqfun = eqn1,eqB = constraint)
结果
Iter: 1 fn: 69.1474 Pars: 2.59803 11.49848 -1.42309
Iter: 2 fn: 16.6575 Pars: 0.11328 2.47160 -1.13136
Iter: 3 fn: -25.4959 Pars: -1.29057 -4.34931 0.11716
Iter: 4 fn: 18.7180 Pars: -0.80939 -0.48576 -0.60873
Iter: 5 fn: -30508.7839 Pars: -38.31650 71.04339 -18.61200
Iter: 6 fn: 8659561.9838 Pars: -1212.62541 -171.17422 -91.98102
Iter: 7 fn: -92947015.8433 Pars: 1553.64673 -4069.16237 993.85107
Iter: 8 fn: 145185.9376 Pars: 2732.20221 -1444.17722 579.73287
Iter: 9 fn: -53715280.8638 Pars: 19547.74783 -10608.46092 4207.13900