Hi, i am writing a function to plot a pdf functions of a Generalized normal laplace distribution. The code is this { y = x-rho*mu cf.fn = function(s){ cplex = complex(1,0,1) temp1 = alpha*beta*exp(-sigma*s^2/2) temp2 = (alpha-cplex*s)*(beta+cplex*s) out = (temp1/temp2)^rho out } temp.fn = function(s){ (Mod(cf.fn(s)))*cos(Arg(cf.fn(s))-s*y) }
int.fn = function(t){sapply(t,FUN=temp.fn)} te = integrate(int.fn,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=1000000) temp3 = ifelse(te$message == "OK",te$value/pi,NA) temp3 } for example if i call the function like this : GNL.pdf.fn(x[100],mu,sigma,alpha,beta,rho) there is no problem and as expected a number is returned but if i try to call it with a sequence of number ex: x = seq(-4,4,0.1) this error keeps show in up Error in integrate(int.fn, lower = 0, upper = Inf) : evaluation of function gave a result of wrong length Anyone call help me please ? Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Error-in-integrate-int-fn-lower-0-upper-Inf-evaluation-of-function-gave-a-result-of-wrong-length-tp4541250p4541250.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.