Skip to content

None-linear equality constrained optimisation problems

2 messages · Michael Griffiths, Berend Hasselman

#
Michael Griffiths wrote
system of non-linear equations.
So you could for example use package nleqslv. As follows.

library(nleqslv)

f <- function(x) {
    b0 <- x[1]
    b1 <- x[2]
    
    pL <- 1/(1+exp(-b0+b1)) 
    pM <- 1/(1+exp(-b0)) 
    pH <- 1/(1+exp(-b0-b1)) 
    
    CR <-  (1 - pM/pH) - 0.2
    TF <-  mean(pL,pM,pH) - .005## which must equal 0.5% 
    
    c(CR,TF)
}
 
bstart <- c(.5,.5)
nleqslv(bstart ,f, control=list(trace=0))

with output (excerpt)

$x
[1] -5.0685870  0.2247176
$fvec
[1] 1.337569e-09 8.879125e-10

bstart <- c(.85,.85)
nleqslv(bstart ,f, control=list(trace=0))

with output (excerpt)

$x
[1] 1.384720 6.678025
$fvec
[1]  1.402461e-11 -3.595026e-11

So your solution for b0 and b1  depends heavily on the starting values.

BTW: your non-linear constraint is not really non-linear.
1-pM/pH=.2 is equivalent to .8 * pH = pM which is linear.


Berend


--
View this message in context: http://r.789695.n4.nabble.com/None-linear-equality-constrained-optimisation-problems-tp4213442p4213731.html
Sent from the R help mailing list archive at Nabble.com.