Displaying 20 results from an estimated 20000 matches similar to: "integration function"
2011 May 30
1
Error in minimizing an integrand using optim
Hi,
Am not sure if my code itself is correct. Here's what am trying to do:
Minimize integration of a function of gaussian distributed variable 'x' over
the interval qnorm(0.999) to Inf 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
2011 Feb 17
1
Integrate with an indicator function
Hi all,
I have some some problem with regard to finding the integral of a
function containing an indicator function.
please see the code below:
func1 <- function(x, mu){
(mu^2)*dnorm(x, mean = mu, sd = 1)*dgamma(x, shape=2)}
m1star <- function(x){
integrate(func1, lower = 0, upper = Inf,x)$val}
T <- function(x){
0.3*dnorm(x)/(0.3*dnorm(x)+0.7*m1star(x))}
func2 <-
2018 Feb 06
2
question with integrate function
Hi all,
The function h below is a function of c and it should be a monotone
increasing function since the integrand is nonnegative and integral is
taken from c to infinity. However, as we can see from the plot, it is not
shown to be monotone. Something wrong with the usage of integrate function?
Thanks so much for your help.
Hanna
h <- function(c){
g <- function(x){pnorm(x-8.8,
2011 Feb 17
1
Integration with an Indicator Function in R
Hi all,
I have some some problem with regard to finding the integral of a
function containing an indicator function.
please see the code below:
func1 <- function(x, mu){
(mu^2)*dnorm(x, mean = mu, sd = 1)*dgamma(x, shape=2)}
m1star <- function(x){
integrate(func1, lower = 0, upper = Inf,x)$val}
T <- function(x){
0.3*dnorm(x)/(0.3*dnorm(x)+0.7*m1star(x))}
func2 <-
2018 Feb 06
0
question with integrate function
Sorry. I meant in the previous email that the function h() is a monotone
decreasing function. Thanks very much.
2018-02-06 13:32 GMT-05:00 li li <hannah.hlx at gmail.com>:
> Hi all,
> The function h below is a function of c and it should be a monotone
> increasing function since the integrand is nonnegative and integral is
> taken from c to infinity. However, as we can see
2013 Mar 05
2
Error message
Dear all,
I got an error message when running the following code.
Can anyone give any suggestions on fixing this type of error?
Thank you very much in advance.
Hanna
> integrand <- function(x, rho, a, b, z){
+ x1 <- x[1]
+ x2 <- x[2]
+ Sigma <- matrix(c(1, rho, rho, 1), 2,2)
+ mu <- rep(0,2)
+ f <-
2002 Jun 28
1
integrate function fails! (PR#1718)
Full_Name: José Enrique Chacón
Version: 1.5.0 and 1.3.1
OS: Windows Millenium
Submission from: (NULL) (158.49.28.155)
Dear reader:
I was 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)
2018 Feb 06
1
question with integrate function
Hi Hanna,
your function is essentially zero outside a short interval around 9. And
the help page states: "If the function is approximately constant (in
particular, zero) over nearly all its range it is possible that the
result and error estimate may be seriously wrong."
You could try to integrate over a finite interval, say (7, 12).
G?ran Brostr?m
On 2018-02-06 19:40, li li wrote:
2009 Aug 07
1
Gauss-Laguerre using statmod
I believe this may be more related to analysis than it is to R, per se.
Suppose I have the following function that I wish to integrate:
ff <- function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma)
Then, given the parameters:
mu <- 300
sigma <- 50
m <- 250
target <- 200
sigma_i <- 50
I can use the function integrate as:
> integrate(ff, lower= -Inf, upper=target)
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),...){
2006 Nov 18
1
Questions regarding "integrate" function
Hi there. Thanks for your time in advance.
I am using R 2.2.0 and OS: Windows XP.
My final goal is to calculate 1/2*integral of
(f1(x)^1/2-f2(x)^(1/2))^2dx (Latex codes:
$\frac{1}{2}\int^{{\infty}}_{\infty}
(\sqrt{f_1(x)}-\sqrt{f_2(x)})^2dx $.) where f1(x) and f2(x) are two
marginal densities.
My problem:
I have the following R codes using "adapt" package. Although "adapt"
2006 Aug 26
1
Capture of iterative integration output
Hello,
I am a novice R user and am having difficulty retrieving the values
from 21 iterations of the R function integrate.
The only way I have found is to do a write.table and then a read.table
as shown in the code below. I would rather capture the 21 values inside
the braces ( sapply might work, but I can't set it up without getting an
error in function) so I could compute the
2012 Mar 23
3
R numerical integration
Hi all,
Is there any other packages to do numerical integration other than the
default 'integrate'?
Basically, I am integrating:
integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value
The integration is ok provided sigma is >0.
However, when mu=-1.645074 and sigma=17535.26
It stopped working. On the other hand, Maple gives me a value of
0.5005299403.
It is an
2011 Oct 05
2
cuhre usage ?? multidimensional integration
my=function(x){
len=1
for(i in 1:len){
y[i]=x[i]
}
g=1
w=NULL
t=NULL
for(i in 1:len)w[i]=x[i+len]
for(i in 1:len)t[i]=x[i+2*len]
for(i in 1:len)g=g*dnorm(y[i])*dnorm(w[i])*dnorm(z[i])
return(g)
}
cuhre(6,1,my,rep(-100,6),rep(100,6))
Error in crff(match.call(), integrand, "cuhre", libargs, ...) :
Additional argument not expected in the integrand function
function change to
2019 Dec 08
2
What should dnorm(0, 0, -Inf) return?
Yes, that looks like a bug and an easily fixable one too.
However, I spy another issue: Why do we check the !R_FINITE(x) && mu == x before checking for sd < 0 ? The difference is whether we
return ML_NAN;
or
ML_ERR_return_NAN;
but surely negative sd should always be an error?
I'd be inclined to do
if (sigma < 0) ML_ERR_return_NAN;
if(!R_FINITE(sigma)) return R_D__0;
2010 Nov 17
2
Numerical integration
Hi!
I was wondering if there are any other functions for numerical integration,
besides 'integrate' from the stats package, but which wouldn't require the
integrand to be vectorized. Oh, and must be capable of integrating over
(-inf,+inf).
Thanks in advance,
Eduardo Horta
[[alternative HTML version deleted]]
2008 Mar 19
1
problem with optim and integrate
Dear all,
I want to min "integrate( (p1*dnorm+p2*dnorm+p3*dnorm)^(1.3))" for p, mu,
and sigma.
So, I have to estimate 8 parameters(p3=1-p1-p2).
I got this warning-"Error in integrate(numint, lower = -Inf, upper = Inf) :
non-finite function value."
My questions are
How could I fix it? I tried to divide into several intervals and sum up, but
I got same message.
My code is
2007 Sep 12
1
Integrate() error message, I am at a loss
Hello!
I have a problem with integrate() in my function nctspa(). Integrate
produces an error message "evaluation of function gave a result of
wrong length". I don't know what that means. Could anyone suggest me
what is wrong with my function?
These are the examples of function calls that work OK:
nctspa(a=1:10,n=5)
nctspa(a=1:10, n=5, mu=2, theta=3, renorm=0)
This does not work:
2012 Mar 22
2
Quicker way to apply values to a function
Hi all,
myint=function(mu,sigma){
integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value
}
mymu=seq(-3,3,length(1000))
mysigma=seq(0,1,length(500))[-1]
k=1
v=c()
for (j in 1:length(mymu)) {
for (i in 1:length(mysigma)) {
v[k]=myint(mymu[j],mysigma[i])
k=k+1
}
}
Basically, I want to investigate for what values of mu and sigma, the
integral is divergent.
Is there another way
2004 Mar 02
2
Problem with Integrate
The background: I'm trying to fit a Poisson-lognormal distrbutuion to
some data. This is a way of modelling species abundances:
N ~ Pois(lam)
log(lam) ~ N(mu, sigma2)
The number of individuals are Poisson distributed with an abundance
drawn from a log-normal distrbution.
To fit this to data, I need to integrate out lam. In principle, I can
do it this way:
PLN1 <- function(lam, Count,