[R] how to use mle with a defined function
Lin Pan
linpan1975 at yahoo.com
Mon Jul 2 23:23:17 CEST 2007
Hi all,
I am trying to use mle() to find a self-defined function. Here is my
function:
test <- function(a=0.1, b=0.1, c=0.001, e=0.2){
# omega is the known covariance matrix, Y is the response vector, X is the
explanatory matrix
odet = unlist(determinant(omega))[1]
# do cholesky decomposition
C = chol(omega)
# transform data
U = t(C)%*%Y
WW=t(C)%*%X
beta = lm(U~W)$coef
Z=Y-X%*%beta
V=solve(t(C), Z)
0.5*odet + 0.5*(t(V)%*%V)
}
and I am trying to call mle() to calculate the maximum likelihood estimates
for function (0.5*odet+0.5*(t(V)%*%V)) by
result = mle(test, method="Nelder-Mead")
But I get the following error message:
Error in optim(start, f, method = method, hessian = TRUE, ...) :
(list) object cannot be coerced to 'double'
I am pretty sure that the matrices, parameters etc are numerical before
importing to the function. But why I still get such error message? Could
anybody give some help on this? thanks a lot.
Lin
--
View this message in context: http://www.nabble.com/how-to-use-mle-with-a-defined-function-tf4015002.html#a11402268
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list