G'day Jose,

On Fri, 29 Oct 2010 11:25:05 +0200
José Manuel Gavilán Ruiz <g...@us.es> wrote:

> Hello,  I  want  to  maximize  a  likelihood  function expressed as an
> integral  that  can not be symbolically evaluated. I expose my problem
> in a reduced form.
> 
> g<- function(x){
> integrand<-function(y) {exp(-x^2)*y}
> g<-integrate(integrand,0,1)
> }                         
> h<-function(x) log((g(x)))
> 
> g  is an object of the class function, but g(2) is a integrate object,
> I can print(g(2)) an get a result, but
> if I try h(2) R says is a nonnumeric argument for a mathematical
> function. My goal is to maximize h.

Which can be done without R quite trivially.

The result of g(x) is exp(-x^2)/2.
So h(x) is -x^2-log(2), which is maximised at x=0.

Cheers,

        Berwin

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to