Displaying 20 results from an estimated 2000 matches similar to: "how to adjust the output"
2010 Feb 10
1
looping problem
Hi R-users,
I have this code here:
library(numDeriv)
fprime <- 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*bes1
c1*t1bes1*t2
}
## Newton
2010 Jan 26
1
newton method for single nonlinear equation
Hi r-users,
I would like to solve for z values using newton iteration method. I 'm not sure which part of the code is wrong since I'm not very good at programming but would like to learn. There seem to be some output but what I expected is a vector of z values. Thank you so much for any help given.
newton.inputsingle <- function(pars,n)
{ runi <- runif(974, min=0, max=1)
2010 Feb 09
0
For and while in looping
I would like to solve a nonlinear eqn using newton method and here is the code:
library(numDeriv)
fprime <- 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)
2010 Jan 26
1
Newton method
Hi r-users,
I hope somebody can help me with this code.
I would like to solve for z values using newton iteration method. I 'm not sure which part of the code is wrong since I'm not very good at programming but would like to learn. There seem to be some output but what I expected is a vector of z values. Thank you so much for any help given.
newton.inputsingle <-
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),...){
2008 Aug 26
2
Problem with Integrate for NEF-HS distribution
I need to calcuate the cumulative probability for the Natural Exponential Family - Hyperbolic secant distribution with a parameter theta between -pi/2 and pi/2. The integration should be between 0 and 1 as it is a probability.
The function "integrate" works fine when the absolute value of theta is not too large. That is, the NEF-HS distribution is not too skewed. However, once the
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
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" value (the
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) =
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){
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
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)
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 with
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
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]))
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"
2010 Feb 15
1
error message error
Hi r-users,
I hope somebody can help me to understand the error message. Here is my code;
## Newton iteration
newton_gam <- function(z)
{ n <- length(z)
r <- runif(n)
tol <- 1E-6
cdf <- vector(length=n, mode="numeric")
fprime <- vector(length=n, mode="numeric")
f <- vector(length=n, mode="numeric")
for (i in 1:1000)
{
2018 Mar 23
1
Integrate erros on certain functions
In the help for ?integrate:
>When integrating over infinite intervals do so explicitly, 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
2010 Jul 19
2
integral in R
Hello All,
I have to create a variable that is a function of another one (already
created), its cumulative distribution function and the integral of this
cumulative distribution, with limits: 0 and the value of the variable.
To be clear, I have the variable called “cip”. And its cdf called “cdfcip”
I need to create the variable:
bip = cip + ((1 – cdfcip)^4)*integral((1-cdf(u))^4*du, 0, value
2005 Nov 16
1
Error in integrate
Hi!
I am a beginner of R. I am trying to calculate integrate and draw a graph of the output, but just kept on getting error messages. I list my program and error message below. Please help. Many Thanks!
=======================
+ > a<--11
> b<-0.1
> c<-0.012
> x<-0:110
> t<-0:15
> integrand<-function(x) {exp(-exp(a-c*t)*(exp(b*x)-exp(c*x))/(b-c))}
>