Geir H Bolstad
2007-Mar-27 09:35 UTC
[R] Solving a system of nonlinear equations involving weighted parameters
Hi, I'm trying to solve the following system of nonlinear equations P1 - F2 = x[1] + (1/2) * x[3] * x[1]^2 P2 - F2 = x[2] + (1/2) * x [3] * x[2]^2 F1 - F2 = -(1/2) * x[1] - (1/2) * x[2] + (1/8) * x [3] * (x[1] + x[2])^2 B1 - F2 = (1/4) * x[1] - (1/4) * x[2] + (1/16) * x[3] * (x[1] - x[2])^2 B2 - F2 = (1/4) * x[1] + (1/4) * x[2] + (1/16) * x[3] * (x[1] - x[2])^2 where P1, P2, F1, F2, B1, and B2 are weighted parameters. I have tried to use f <- function(x){ (x[1]+(1/2)*x[3]*x[1]^2-P1+F2)^2 +(x[2]+(1/2)*x[3]*x[2]^2-P2+F2)^2 +(-(1/2)*x[1]-(1/2)*x[2]+(1/8)*x[3]*(x[1]+x[2])^2-F1+F2)^2 +((1/4)*x[1]-(1/4)*x[2]+(1/16)*x[3]*(x[1]-x[2])^2-B1+F2)^2 +(-(1/4)*x[1]+(1/4)*x[2]+(1/16)*x[3]*(x[1]-x[2])^2-B2+F2)^2 } optim(c(P1-F2,P2-F2,0), f) nlm(f, c(P1-F2,P2-F2,0)) but neither optim() or nlm() allows for weighted parameters. In addition I need standard errors for the estimates of x[1], x[2] and x[3]. Thanks Geir