[R] Solving two nonlinear equations with two knowns

Ravi Varadhan RVaradhan at jhmi.edu
Mon Jul 20 19:38:57 CEST 2009


I just realized that the problem occurs when b becomes smaller than -1
during iterations, causing the integral to be divergent (it is infinite at u
= tau).  So, you have to constrain your exponent to be greater than -1.
There is no way to constrain parameters in dfsane.  

However, you can do a parameter transform such that b + 1 is positive.
Define b = exp(k) - 1, and work with "k" as your parameter.  This might
help.

Ravi. 


----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of yhsu6 at illinois.edu
Sent: Sunday, July 19, 2009 9:39 PM
To: Ravi Varadhan; Berend Hasselman; r-help at r-project.org
Subject: Re: [R] Solving two nonlinear equations with two knowns

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)

______________________________________________
R-help at 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.




More information about the R-help mailing list