[R] Solving two nonlinear equations with two knowns

yhsu6 at illinois.edu yhsu6 at illinois.edu
Mon Jul 20 03:38:31 CEST 2009


I try to use integrate command to get theoretical mean and variance, and then solve for a and b. I have an error as follows,
Iteration:  0  ||F(x0)||:  2.7096 
Error in integrate(InverseF1, tau, 1, mu = mu2, sigma = sigma2, a = a,  : 
  non-finite function value

Any suggestion?
 
#R code:
mu2=0.4
sigma2=4
tau=0.75
mean.diff=2
var.ratio=3

InverseF1<-function(u,mu,sigma,a,b,tau)
{
qnorm(u,mean=mu,sd=sigma)+a*(abs(u-tau))^b*(u>tau)
}

InverseF2<-function(u,mu,sigma)
{
qnorm(u,mean=mu,sd=sigma)
}

part1<-function(u,mu,sigma,a,b,tau)
{
(InverseF2(u,mu,sigma)+a*(abs(u-tau))^b*(u>tau))^2
}
part2<-function(u,mu,sigma)
{
InverseF2(u,mu,sigma)^2
}

parameter<- function(cons) {
a<-cons[1]
b<-cons[2]
f <- rep(NA, 2)
EX<-integrate(InverseF2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(InverseF1,tau,1,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value 
EY<-integrate(InverseF2,0,1,mu=mu2,sigma=sigma2)$value 
VarX<-integrate(part2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(part1,tau,1,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value-EX^2
VarY<-integrate(part2,0,1,mu=mu2,sigma=sigma2)$value-EY^2
f[1] <- abs(EX - EY) - mean.diff
f[2] <- sqrt(VarX) - sqrt(var.ratio) * sqrt(VarY) 
f
} 

library(BB)
c0<-c(3,1)
ans1 <- dfsane(par=c0, fn=parameter, method=3)




More information about the R-help mailing list