[R] a strange problem with integrate()

vito muggeo vmuggeo at dssm.unipa.it
Wed Mar 1 18:27:43 CET 2006


Dear all,
I am stuck on the following problem with integrate(). I have been out of 
luck using RSiteSearch()..

My function is

g2<-function(b,theta,xi,yi,sigma2){
       xi<-cbind(1,xi)
       eta<-drop(xi%*%theta)
       num<-exp((eta + rep(b,length(eta)))*yi)
       den<- 1 + exp(eta + rep(b,length(eta)))
       result=(num/den)*exp((-b^2)/sigma2)/sqrt(2*pi*sigma2)
       r=prod(result)
       return(r)
       }

And I am interested in evaluating the simple integral, but:

 > integrate(g2,-2,2,theta=c(-2,3),xi=c(1,2,5,6),yi=c(1,0,1,1),sigma2=1)
Error in integrate(g2, -2, 2, theta = c(-2, 3), xi = c(1, 2, 5, 6), yi = 
c(1,  :
         evaluation of function gave a result of wrong length
 >

I have checked the integrand function

 > valori<-seq(-2,2,l=30)
 > risvalori<-NULL
 > for(k in valori) 
risvalori[length(risvalori)+1]<-g2(k,theta=c(-2,3),xi=c(1,2,5,6),yi=c(1,0,1,1),sigma2=1)
 > plot(valori, risvalori)

And the integral exists..

Please, any comment is coming?

many thanks,
vito

-- 
====================================
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 6626240
fax: 091 485726/485612




More information about the R-help mailing list