[R] Error in 1/ue : non-numeric argument to binary operator.

R. Michael Weylandt michael.weylandt at gmail.com
Wed Oct 19 09:14:42 CEST 2011


Short answer since it's late:

integrate doesn't return a number (directly): add $value somewhere
(either on the integrate() output before assignment or on later use of
ue) and you should be fine.

Michael

On Wed, Oct 19, 2011 at 1:11 AM, beiyu <beiyulin at gmail.com> wrote:
> hi, I have a problem. The R shows that
> Error in 1/ue : non-numeric argument to binary operator.
>
> Here is the code:
>
>
> #  simulation of tempered stable processes by compound Poisson approximation
>
> tsp<-function(n,e,a,c,lema){
>
>
> x<-numeric(n)
>
>
> for (i in 1:n){
>
> repeat{
>
>
> w<-runif(1)
> v<-runif(1)
> x<-e*(w^(-1/a))
>
>
>
>
>
> fex<-function(x1){ if (x1>=e) {a1<-a*(e^(-a))/(x^a-1)}}
>
> vex<-function(x2){c*exp(-lema*x2)/(x2^(a+1))}
>
> ue<-integrate(vex,e,Inf)
>
> aa<-(1/ue)*c
>
>
> pex<-function(x3){aa*exp(-lema*x3)/(x3^(a+1))}
>
>
>
>
>
> if (x>=e) {pex(x)}
>
>
>
>
> T<-fex(x)*(e^(-a))*(exp(-lema*e))/(pex(x)*a*ue)
>
> if(V*T<=1)  break
>
> if (ue<=2) break
>
> }
>
> x
>
> }
> }
>
> tsp(10,0.01,1.5,1,10)
>
>
> Could any one help me? Thx~
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Error-in-1-ue-non-numeric-argument-to-binary-operator-tp3917605p3917605.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list