s-news
[Top] [All Lists]

Finding the inverse of a function (not necessarily monotonic) through nu

To: <s-news@lists.biostat.wustl.edu>
Subject: Finding the inverse of a function (not necessarily monotonic) through numerical methods.
From: "Steve Su" <s.su@qut.edu.au>
Date: Sat, 22 Mar 2003 20:44:21 +1000
Dear All,

Splus 6 on Windows currently have an optimize function which can help one
find the inverse of a function quickly, e.g:

function is x=lambda1 + (p^lambda3 - (1 - p)^lambda4)/lambda2

# Define the Objective function:
qgl.rs.f<-
function(p, lambda1, lambda2, lambda3, lambda4,x)
{
quants <- abs(lambda1 + (p^lambda3 - (1 - p)^lambda4)/lambda2-x)
quants
}

# Using optimize:

optimize(qgl.rs.f,lambda1=0, lambda2=-1, lambda3=-1.5,
lambda4=3,x=-5,interval=c(0,1))$minimum

This works very nicely but it is fairly slow if you want to evalue for
x<-seq(-10,3,length=1000), the syntax is as follows:

# vectorised optimize

apply(matrix(seq(-10,3,length=1000)),1,function(k)
optimize(qgl.rs.f,lambda=0, lambda2=-1, lambda3=-1.5,
lambda4=3,x=k,interval=c(0,1))$minimum)

I am wondering if there is a quicker way to achieve this result? I am not
entirely sure how Splus find the inverse of a normal density for example, as
the programs are coded in .Internal but if there is a function which can be
used generally in Splus then it will be useful to know this.

Thank you for your attention, all comments welcome.



















****************************************************************************
**********

 Steve Su (s.su@qut.edu.au)
 PhD student.

 School of Accountancy
 School of Mathematical Sciences
 Queensland University of Technology

 Postal Address: Steve Su, School of Accountancy, QUT, PO Box 2434,
Brisbane,
 Queensland, Australia, 4000.


 Phone:  +61 7 3864 2017
 Fax:    +61 7 3864 1812
 Mobile: 0421  840  586
     .
   _--_|\
  /      QUT
  \_.--._/
        v

****************************************************************************
**********


<Prev in Thread] Current Thread [Next in Thread>