# [S] Integration difficulties

Nicole DePriest Demers (ntd@stat.ohio-state.edu)
Tue, 10 Mar 1998 18:11:18 -0500 (EST)

I am trying to integrate a function and a few problems have arisen.

#Function to be integrated is

moment_function(x,theta,k=1) x^k*p.mix(x,theta)

#where p.mix is a mixture of two normal distributions

p.mix_function(x,theta) .5*dnorm(x,theta) + .5*dnorm(x,-theta)

Note what happens in the following cases:

1) > ans_integrate(moment,-Inf,-1,theta=0.1,k=2)
> ans\$integral
[1] -0.2443884
> ans\$call
integrate(f = moment, lower = - Inf, upper = -1, keep.xy = 2,
theta = 0.1)

#The integrate function ignored my k=2 argument in the call to
#integrate. The result is for k=1.

2) #I removed the default value for k
> moment_function(x,theta,k) x^k*p.mix(x,theta)
> ans_integrate(moment,-Inf,-1,theta=0.1,k=2)
Error in qsub(f, bound, sgn, 0, 1, aux = optargs(l..: singularity
encountered
Dumped

3) #I switched the order of k and theta.
> moment_function(x,k,theta=.1) x^k*p.mix(x,theta)
> ans_integrate(moment,-Inf,-1,k=2)
Error in qsub(f, bound, sgn, 0, 1, aux = optargs(l..: singularity
encountered
Dumped

4) #I supply defaults for k and theta and send a different value for
#theta when I call integrate.
> moment_function(x,k=2,theta=.1) x^k*p.mix(x,theta)
> ans_integrate(moment,-Inf,-1,theta=0.2)
> ans\$call
integrate(f = moment, lower = - Inf, upper = -1, theta = 0.2)

#For some reason, I need a default value for k in my integrand function
but not for theta. When k is supplied as an argument to integrate it is
ignored but theta is not. I want to vary both k and theta within the
integrate command. All suggestions/explanations will be appreciated.

Nicole Demers

______________________________________________________________________________
Nicole Demers
Statistics Department
The Ohio State University
1958 Neil Ave., #404
Columbus, OH 43210, USA
ntd@stat.ohio-state.edu

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news