[R] Using constrOptim() function

Ali Mahani alirezashah at yahoo.com
Wed Jun 3 18:54:10 CEST 2009


I have a function myFunction(beta,x) where beta is a vector of coefficients
and x is a data frame (think of it as a matrix). I want to optimize the
function myFunction() by ONLY changing beta, i.e. x stays constant, with 4
constraints. I have the following code (with a separate source file for the
function):

rm(list=ls())
source('mySourceFile')
x=read.csv("myFile.csv",head=TRUE,sep=",")
beta_i=c(1,1,1,1,1,1,-1)
ui=rbind(c(1,0,0,0,0,0,0),c(0,1,0,0,0,0,0),c(0,0,1,0,0,0,0),c(0,0,0,0,0,0,-1))
ci=c(0,0,0,0)
constrOptim(beta_i, myFunction, NULL, ui, ci, mu = 1e-04, control = list(),
method = "Nelder-Mead",    outer.iterations = 100, outer.eps = 1e-05)

I am getting this error:

Error in f(theta, ...) : argument "x" is missing, with no default

If I replace myFunction with myFunction(beta,x) I get this error:

Error in beta * feature_1[i, ] : non-numeric argument to binary operator

If I try myFunction(beta_i,x) I get:

Error in constrOptim(beta_i, mirror_lf(beta_i, x), NULL, ui, ci, mu = 1e-04, 
: 
  could not find function "f"

Clearly, I don;t have a good understanding of how to use constrOptim() or
optim() for that matter. Any guidance? Thank you!
-- 
View this message in context: http://www.nabble.com/Using-constrOptim%28%29-function-tp23855175p23855175.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list