Hello!

 

I am trying to write a function with vector and data.frame parameters that
uses the sum() function and values from the rows of the data.frame.

I need to pass this function as a parameter to optim().

 

My starting point is:

observs <- data.frame(y, x1, x2, x3)

 

Fn <- function(par, observs) {

                sum( (y - (par[1] * (x1 + 1) * x2^(-par[2]) * x3^par[3])^2 )

}

 

y, x1, x2, x3 are all vectors.

 

I am a bit new to R and I have not been able to find a good description of
how to iterate over rows in a data.frame.

 

What is a straightforward way to do this?

What am I missing?

 

Thanks

Stu

 


	[[alternative HTML version deleted]]


