[R] Solving a system of nonlinear equations involving weighted parameters
Geir H Bolstad
geir.bolstad at bio.ntnu.no
Tue Mar 27 11:35:07 CEST 2007
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
More information about the R-help
mailing list