[R] nonlinear least squares, multiresponse

Bill Simpson W.Simpson at gcal.ac.uk
Thu Apr 25 10:04:54 CEST 2002


Here is a solution that is fairly easy to do. (Not sure how statistically
reasonable it is--seems OK to me)

Use nlm() or optimize() to minimise the sum of the squared residuals
across all DVs simultaneously. If your IVs are a,b,c , your parameters
are b0,b1,b2, and your DVs are x,y,z, then nlm() will iteratively minimize

(x-fnx(a,b,c,b0,b1,b2))^2+
(y-fny(a,b,c,b0,b1,b2))^2+
(z-fnz(a,b,c,b0,b1,b2))^2

Or I suppose you could write a function that returns a vector
xhat, yhat, zhat

Here is a simple 1 IV 1 DV example to base your code on:

x<-c(0.02, 0.02, 0.06, 0.06, 0.11, 0.11, 0.22, 0.22, 0.56, 0.56, 1.10,
1.10)
y<-c(76, 47, 97, 107, 123, 139, 159, 152, 191, 201, 207, 200)
fn <- function(p) sum((y - (p[1] * x)/(p[2] + x))^2)
out<-nlm(fn,p=c(200,.1),hessian=TRUE)
out
#SSE = out$minimum; MSE = out$minimum/(n-p), n is #pts, p is #params
#estimates=out$estimate
se<-sqrt(diag(2*out$minimum/(length(y)-2)*solve(out$hessian)))  #SEs


Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list