search for: integrand

Displaying 20 results from an estimated 109 matches for "integrand".

2008 Aug 26
2
Problem with Integrate for NEF-HS distribution
...distribution. Is there any way that I can get around of this and let "integrate" work for the skewed distribution? Or is there any other function for integrating in R-package? Thanks a lot for your advice in advance! > theta<--1 > sech<-function(X) 2/(exp(-X)+exp(X)) > integrand <- function(X) {0.5*cos(theta)*exp(X*theta)*sech(pi*X/2)} > integrate(integrand, -3,1) 0.8134389 with absolute error < 7e-09 > integrate(integrand, -10,1) 0.9810894 with absolute error < 5.9e-06 > integrate(integrand, -15,1) 0.9840505 with absolute error < 7e-09 > integrate...
2011 Nov 10
2
performance of adaptIntegrate vs. integrate
Dear list, [cross-posting from Stack Overflow where this question has remained unanswered for two weeks] I'd like to perform a numerical integration in one dimension, I = int_a^b f(x) dx where the integrand f: x in IR -> f(x) in IR^p is vector-valued. integrate() only allows scalar integrands, thus I would need to call it many (p=200 typically) times, which sounds suboptimal. The cubature package seems well suited, as illustrated below, library(cubature) Nmax <- 1e3 tolerance <- 1e-4 integra...
2010 Dec 22
3
How to integrate a function with additional argument being a vector or matrix?
Dear expeRts, I somehow don't see why the following does not work: integrand <- function(x, vec, mat, val) 1 # dummy return value A <- matrix(runif(16), ncol = 4) u <- c(0.4, 0.1, 0.2, 0.3) integrand(0.3, u, A, 4) integrate(integrand, lower = 0, upper = 1, vec = u, mat = A, val = 4) I would like to integrate a function ("integrand") which gets an "x...
2011 May 30
1
Error in minimizing an integrand using optim
...by changing value of parameter 'mu'. mu is the shift in mean of 'x'. Code: # x follows gaussian distribution # fx2 to be minimized by changing values of mu # integration to be done over the interval (qnorm(0.999),Inf) p<-0.009 #constant R<-0.25 # constant e<-11 #constant integrand<-function(x){ (e*pnorm((qnorm(p)+sqrt(R)*x)/sqrt(1-R))*dnorm(x))^2/dnorm(x+mu)} fx2<-function(mu) { integrate(integrand, lower = qnorm(0.999), upper=Inf)$value} mu<-c(-1) #initial value for mu, which needs to be optimized such that fx2 is minimized output<-optim(par=mu, fx2, method...
2013 Feb 12
2
integrate function
Hi All, Can any one help to explain why min and max function couldn't work in the integrate function directly. For example, if issue following into R: integrand <- function(x) {min(1-x, x^2)} integrate(integrand, lower = 0, upper = 1) it will return this: Error in integrate(integrand, lower = 0, upper = 1) : evaluation of function gave a result of wrong length However, as min(U,V) = (U+V)/2-abs(U-V)/2 Below code working; integrand <- function(...
2012 Oct 20
4
Error in integrate(integrand, 0, Inf) : non-finite function value
Dear R users, When I run the code below, I get the error "Error in integrate(integrand, 0, Inf) : non-finite function value". The code works if the function returns only "sum(integ)". However, I want to add "cmh" to it. When I add "cmh" I get that error. I can't figure out why this is happening because my integrate function has nothing to do wi...
2008 Feb 15
0
Behaviour of integrate (was 'Poisson-lognormal probability calcul ations')
Hi again, Adding further information to my own query, this function gets to the core of the problem, which I think lies in the behaviour of 'integrate'. ------------------------------------- function (x, meanlog = 0, sdlog = 1, ...) { require(stats) integrand <- function(t, x, meanlog, sdlog) dpois(x,t)*dlnorm(t, meanlog, sdlog) mapply(function(x, meanlog, sdlog, ...) # (1/gamma(x+1))* integrate(function(t, x, meanlog, sdlog) # gamma(x+1)* integrand(t, x, meanlog, sdlog), lower...
2008 Feb 18
0
Solved (??) Behaviour of integrate (was 'Poisson-lognormal probab ility calculations')
Hi Again, I think I've solved my problem, but please tell me if you think I'm wrong, or you can see a better way! A plot of the integrand showed a very sharp peak, so I was running into the integrand "feature" mentioned in the note. I resolved it by limiting the range of integration as shown here: -------------------------------------------------- function (x, meanlog = 0, sdlog = 1, sdlim=6, rel.tol = .Machine$double.eps^0...
2004 May 05
4
Discontinuities in a simple graph (machine precision?)
Hi, I've got an ugly but fairly simple function: mdevstdev <- function(a){ l <- dnorm(a)/(1-pnorm(a)) integrand <- function(z)(abs(z-l)*dnorm(z)) inted <- integrate(integrand, a, Inf) inted[[1]]/((1- pnorm(a))*sqrt((1 + a*l - l^2))) } I wanted to quickly produce a graph of this over the range [-3,3] so I used: plotit <-function(x=seq(-3,3,0.01),...){ y<-sapply(x,mdevstdev) plot(x,y,...)...
2011 Jun 25
1
integration function
Hi all, Can anyone please take a look at the following two functions. The answer does not seem to be right. Thank you very much! f1 <- function(x) {integrand <- function (x, mu){ dnorm(x, mean=mu, sd=1)*dnorm(mu, mean=2, sd=1) } integrate(integrand, -Inf, Inf,x)$val } f2 <- function(x) {integrand <- function (x, mu){ dnorm(x, mean=mu, sd=1)*mu^2*dnorm(mu, mean=2, sd=1)...
2002 Jun 28
1
integrate function fails! (PR#1718)
...s trying to evaluate the L2 error produced when estimating the density function N(0,1) from a sample of size 100 using a kernel density estimate. It produced a strange value. You can reproduce the process by typing samp<-rnorm(100) fker<-function(x,h){sum(dnorm((rep(x,100)-samp)/h))/(100*h)} integrand<-function(x){(fker(x,5)-dnorm(x))^2} err<-integrate(integrand,-Inf,Inf) This value err of the L2 error is generally far from accurate. fker is the kernel density estimate with bandwidth h and Gaussian kernel. Obviously, h=5 is a very large choice far from the optimum which is around 0.4, but...
2008 Feb 15
0
Poisson-lognormal probability calculations
...------------------------- I'm having some problems with a Poisson-lognormal density (mass?) function. VGAM has the dpolono function, but that doesn't work for x-values over 170, and I need to go to *much* bigger numbers. It fails first because of gamma overflow, then because of non-finite integrand. --------------------- > VGAM::dpolono(170) [1] 4.808781e-09 > VGAM::dpolono(171) [1] 0 Warning message: In VGAM::dpolono(171) : value out of range in 'gammafn' > VGAM::dpolono(172) [1] 0 Warning message: In VGAM::dpolono(172) : value out of range in 'gammafn' > VGAM::dp...
2011 May 03
2
adaptIntegrate - how to pass additional parameters to the integrand
Hello, I am trying to use adaptIntegrate function but I need to pass on a few additional parameters to the integrand. However, this function seems not to have the flexibility of passing on such additional parameters. Am I missing something or this is a known limitation. Is there a good alternative to such restrictions, if there at all are? Many thanks for your time. HC -- View this message in context: http://...
2010 Feb 09
1
how to adjust the output
Hi R-users,   I have this code below and I understand the error message but do not know how to correct it.  My question is how do I get rid of “with absolute error < 7.5e-06” attach to value of cdf so that I can carry out the calculation.   integrand <- function(z) { alp  <- 2.0165   rho  <- 0.868   # simplified expressions   a      <- alp-0.5   c1     <- sqrt(pi)/(gamma(alp)*(1-rho)^alp)   c2     <- sqrt(rho)/(1-rho)   t1     <- exp(-z/(1-rho))   t2     <- (z/(2*c2))^a   bes1   <- besselI(z*c2,a)   t1bes1 <- t1...
2008 Sep 20
1
lower and upper limits in integrate as vectors
Dear R useRs, i try to integrate the following function for many values "integrand" <- function(z) { return(z * z) } i do this with a for-loop for(i in 2:4) { z <- integrate(integrand, i-1, i)$value cat("z", z, "\n") } to speed up the computation for many values i tried vectors in integrate to do this. vec1<-1:3 vec2<-2:4 integrate(...
2010 Oct 29
2
what´s wrong with this code?
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 funct...
2009 Dec 18
1
Numerical Integration
Dear @ll. I have to calculate numerical integrals for triangular and trapezoidal figures. I know you can calculate the exactly, but I want to do it this way to learn how to proceed with more complicated shapes. The code I'm using is the following: integrand<-function(x) { print(x) if(x<fx[1]) return(0) if(x>=fx[1] && x<fx[2]) return((x-fx[1])/(fx[2]-fx[1])) if(x>fx[2] && x<=fx[3]) return(1) if(x>fx[3] && x<=fx[4]) return((x-fx[4])/(fx[3]-fx[4])) if(x>fx[4]) return(0) } fx<-data...
2012 Jan 17
4
Problema para integrar una funcion ajustada a un conjunto de datos con la instruccion sm.density(x)
...na funcion sm.density() para obtener una especie de histograma pero con una curva que parece continua. 2. Una vez que obtengo esa curva necesito calcular el area bajo la curva en ciertos intervalos, esto equivale a aplicar una integral en esos intervalos. He intentado hacerlo de la siguiente forma: integrand <- function(x){sm.density(x)} lim02ene.via <- integrand(compara.tiempos2[,1]) int.lim02ene.via <- integrate(lim02ene.via, -Inf, Inf) pero obtengo el siguiente error: Error in get(as.character(FUN), mode = "function", envir = envir) : object ''lim02ene.via'' of...
2018 Mar 23
1
Integrate erros on certain functions
...ly, rather than just using a large number as the endpoint. This increases the chance of a correct answer ? any function whose integral over an infinite interval is finite must be near zero for most of that interval. I understand that and there are examples such as: ## a slowly-convergent integral integrand <- function(x) {1/((x+1)*sqrt(x))} integrate(integrand, lower = 0, upper = Inf) ## don't do this if you really want the integral from 0 to Inf integrate(integrand, lower = 0, upper = 1000000, stop.on.error = FALSE) #> failed with message ?the integral is probably divergent? which gives...
2006 Nov 18
1
Questions regarding "integrate" function
...apt" function is mainly designed for more than 2 dimensions, the manual says it will also call up "integrate" if the number of dimension equals one. I feed in the data x1 and x2 and bandwidths h1 and h2. These codes worked well when my final goal was to take double integrals. integrand <- function(x) { # x input is evaluation point for x1 and x2, a 2x1 vector x1.eval <- x[1] x2.eval <- x[2] # n is the number of observations n <- length(x1) # x1 and x2 are the vectors read from data.dat # Comp...