[R] Optim() Help, Unusual Error

ApproxGaussian pcasas at technomics.net
Tue Mar 23 17:58:24 CET 2010


Hello all, any help with the following would be appreciated.

I am attempting to maximize 28 parameters similtaneously in Optim().  The
follwoing is my code:

Y<-comp[,9]
n<-length(Y)


e.1<-.5
e.2<-.5
e.3<-.5
e.4<-.5
e.5<-.5
e.6<-.5
e.7<-.5
e.8<-.5
e.9<-.5
e.10<-.5
e.11<-.5
e.12<-.5
e.13<-.5
e.14<-.5
e.15<-.5
e.16<-.5
e.17<-.5
e.18<-.5
e.19<-.5
e.20<-.5
e.21<-.5
e.21<-.5
e.22<-.5
e.23<-.5
e.24<-.5
e.25<-.5
e.26<-.5
e.27<-.5
e.28<-.5
par<-(e.1,e.2,e.3,e.4,e.5,e.6,e.7,e.8,e.9,e.10,e.11,e.12,e.13,e.14,e.15,e.16,e.17,e.18,e.19,e.20,e.21,e.22,e.23,e.24,e.25,e.26,e.27,e.28)


# Define the objective function:
objective.function <- function(par,comp,Y,n) {
e.1<-par[1]
e.2<-par[2]
e.3<-par[3]
e.4<-par[4]
e.5<-par[5]
e.6<-par[6]
e.7<-par[7]
e.8<-par[8]
e.9<-par[9]
e.10<-par[10]
e.11<-par[11]
e.12<-par[12]
e.13<-par[13]
e.14<-par[14]
e.15<-par[15]
e.16<-par[16]
e.17<-par[17]
e.18<-par[18]
e.19<-par[19]
e.20<-par[20]
e.21<-par[21]
e.22<-par[22]
e.23<-par[23]
e.24<-par[24]
e.25<-par[25]
e.26<-par[26]
e.27<-par[27]
e.28<-par[28]

residuals.squared <- c()

for (i in 1:n) residuals.squared[i] <- (Y[i] - (
((e.26^comp[i,3])*(e.27^(comp[i,7]-mean(comp[,7])))*(e.28^comp[i,6])*(comp[i,65]^comp[i,5]))*
(e.1*comp[i,10]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.21)
+
e.2*comp[i,11]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.21)
+
e.3*comp[i,12]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.21)
+
e.4*comp[i,13]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.22)
+
e.5*comp[i,14]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.22)
+
e.6*comp[i,15]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.22)
+
e.7*comp[i,16]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.23)
+
e.8*comp[i,17]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.24)
+
e.9*comp[i,18]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.24)
+
e.10*comp[i,19]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.24)
+
e.11*comp[i,20]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.24)
+
e.12*comp[i,21]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.13*comp[i,22]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.14*comp[i,23]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.15*comp[i,24]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.15*comp[i,25]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.16*comp[i,26]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.15*comp[i,27]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.12*comp[i,28]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25)
+
e.8*comp[i,29]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.24)
+
e.14*comp[i,30]*((((comp[i,34]+comp[i,35])+(e.17*(comp[i,36]+comp[i,37]+comp[i,38]))+(e.18*comp[i,41])+(e.19*comp[i,39])+(e.20*comp[i,42]))/(comp[i,31]+comp[i,32]+comp[i,33]))^e.25))^2)
)
sum.residuals.squared <- sum(residuals.squared)
return(sum.residuals.squared)
}


optim.results <- optim(par, fn=objective.function, method = "Nelder-Mead",
comp[,c(3,5,6,7,10:39,41:42,65)], Y=Y, n=n)


The error I am recieving however states: 
Error in fn(par, ...) : 
  unused argument(s) (X = list(Air.Platform. = c(1, 1...

Where "Air.Platform." is the column name for comp[i,3] used in the first
lines of my objective function.

I'm not sure how it is reminaing "unused".  Thanks for any help.

-Paul
-- 
View this message in context: http://n4.nabble.com/Optim-Help-Unusual-Error-tp1679363p1679363.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list