Re: [R] Derivative of expm function

2014-04-24 Thread Martin Maechler
 Wagner Bonat wbo...@gmail.com
 on Wed, 23 Apr 2014 12:12:17 +0200 writes:

 Hi all !
 I am look for some efficient method to compute the derivative of
 exponential matrix function in R. For example, I have a simple matrix like

 log.Sigma  - matrix(c(par1, rho, rho, par2),2,2)

 require(Matrix)
 Sigma - expm(log.Sigma)

 I want some method to compute the derivatives of Sigma in relation the
 parameters par1, par2 and rho. Some idea ?

The  'expm' package has slightly newer / more reliable
algorithms for the matrix exponential.

It also contains an  expmFrechet()  function
which computes the Frechet derivative of the matrix exponential.

I'm pretty confident -- but did not start thinking more deeply --
that this should provide the necessary parts to get
partial derivatives like yours as well.

Martin Maechler, ETH Zurich

 Wagner Hugo Bonat
 LEG - Laboratório de Estatística e Geoinformação
 UFPR - Universidade Federal do Paraná

__
R-help@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.


[R] Derivative of expm function

2014-04-23 Thread Wagner Bonat
Hi all !

I am look for some efficient method to compute the derivative of
exponential matrix function in R. For example, I have a simple matrix like

log.Sigma  - matrix(c(par1, rho, rho, par2),2,2)

require(Matrix)
Sigma - expm(log.Sigma)

I want some method to compute the derivatives of Sigma in relation the
parameters par1, par2 and rho. Some idea ?

-- 
Wagner Hugo Bonat
LEG - Laboratório de Estatística e Geoinformação
UFPR - Universidade Federal do Paraná

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread Lisa
This is not a homework. I just want to see if there are some R functions or
some ideas I can borrow to solve my problem. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633071.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread David Winsemius


On Jun 29, 2011, at 10:48 AM, Lisa wrote:

This is not a homework. I just want to see if there are some R  
functions or

some ideas I can borrow to solve my problem.


There is a deriv function that provides limited support for symbolic  
differentiation.


The Rhelp list is advertised ( http://www.R-project.org/posting-guide.html 
 ) as expecting you to have made some efforts at searching. This  
answer might not have floated to the surface among the thousand or so  
hits, but at least you should have tried.


RSiteSearch(derivative)

And there is, of course, CrossValidated: http://stats.stackexchange.com/



--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633071.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread Gabor Grothendieck
On Tue, Jun 28, 2011 at 10:03 PM, Lisa lisa...@gmail.com wrote:
 Dear all,

 I just want to get the derivative of a function that looks like:

 y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

 where y is a scalar, x1, x2, and b are vectors. I am going to take the
 derivative of b with respect to y, but I cannot derive an expression in
 which b is function of y. I know there is another way to get the similar
 result, i.e., first take the derivative of y with respect to each element of
 b, and then take its reciprocal. But it is not what I want. Could someone
 please tell me how to solve this problem? Thank you in advance.

Assuming you meant the derivative of y with respect to b:

 D(expression(exp(x1*b) / (exp(x1*b) + exp(x2*b))), b)
exp(x1 * b) * x1/(exp(x1 * b) + exp(x2 * b)) - exp(x1 * b) *
(exp(x1 * b) * x1 + exp(x2 * b) * x2)/(exp(x1 * b) + exp(x2 *
b))^2

See ?D and also note deriv on the same help page for another alternative.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread Rolf Turner

On 30/06/11 06:16, Gabor Grothendieck wrote:

On Tue, Jun 28, 2011 at 10:03 PM, Lisalisa...@gmail.com  wrote:

Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance.

Assuming you meant the derivative of y with respect to b:


I think the original post made it quite clear that the derivative of b
with respect to y was indeed what was wanted; i.e. the OP needs to
do implicit differentiation which R does not do automatically.

cheers,

Rolf Turner

D(expression(exp(x1*b) / (exp(x1*b) + exp(x2*b))), b)

exp(x1 * b) * x1/(exp(x1 * b) + exp(x2 * b)) - exp(x1 * b) *
 (exp(x1 * b) * x1 + exp(x2 * b) * x2)/(exp(x1 * b) + exp(x2 *
 b))^2

See ?D and also note deriv on the same help page for another alternative.



__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread Lisa
Yes. I need to do implicit differentiation. After rearrangement, I got 

(x2 – x1) * b = log(1 / y - 1)

Take derivative of both sides with respect to y, I have

(x2 – x1) * b’[y] = - 1/y(1-y)

Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
RHS. This is why I posted my question here to see if there is some R
functions or some idea that can help me solve this problem. Thanks.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633947.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread Gabor Grothendieck
On Wed, Jun 29, 2011 at 4:35 PM, Lisa lisa...@gmail.com wrote:
 Yes. I need to do implicit differentiation. After rearrangement, I got

 (x2 – x1) * b = log(1 / y - 1)

 Take derivative of both sides with respect to y, I have

 (x2 – x1) * b’[y] = - 1/y(1-y)

 Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
 RHS. This is why I posted my question here to see if there is some R
 functions or some idea that can help me solve this problem. Thanks.


I am not sure if this counts as an approach that you are trying to exclude but:

db[i]/dy = { dlogit(y)/dy } / { dlogit(y)/db[i] } = { 1/{y(1-y)} / {
x1[i] - x2[i] }

The numerator is taken from your calculation and the denominator is
from linearity.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Derivative of a function

2011-06-29 Thread S Ellison
If you just want the value of the derivative at a particular point, would 
numerical derivatives suffice? If so, try (for example) the numDeriv package.

S

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Lisa [lisa...@gmail.com]
Sent: 29 June 2011 21:35
To: r-help@r-project.org
Subject: Re: [R] Derivative of a function

Yes. I need to do implicit differentiation. After rearrangement, I got

(x2 – x1) * b = log(1 / y - 1)

Take derivative of both sides with respect to y, I have

(x2 – x1) * b’[y] = - 1/y(1-y)

Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
RHS. This is why I posted my question here to see if there is some R
functions or some idea that can help me solve this problem. Thanks.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633947.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.
***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


[R] Derivative of a function

2011-06-28 Thread Lisa
Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance. 

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3631814.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Derivative of a function

2011-06-28 Thread Rolf Turner


(1) You really ought to do your own homework.

(2) What has this to do with R?

cheers,

Rolf Turner

On 29/06/11 14:03, Lisa wrote:

Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3631814.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.



__
R-help@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.


Re: [R] Derivative

2010-08-12 Thread TGS
This following works for me but I still favor the quick and dirty method 
suggested originally by David.

options(scipen = 10)
x - seq(0,2, by = .01)
f - expression(5*cos(2*x)-2*x*sin(2*x))
D(f, 'x')
f.prime - function(x){
-(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) * 2)))
}
curve(expr = f.prime, from = 1, to = 2, n = 101)
uniroot(f = f.prime, interval = c(1,2), tol = .1)

On Aug 11, 2010, at 10:56 PM, David Winsemius wrote:


On Aug 12, 2010, at 12:49 AM, Dennis Murphy wrote:

 Hi:
 
 Try the following:
 
 f - function(x) 5*cos(2*x)-2*x*sin(2*x)
 curve(f, -5, 5)
 abline(0, 0, lty = 'dotted')
 
 This shows rather clearly that your function has multiple roots, which isn't
 surprising given that it's a linear combination of sines and cosines. To
 find a specific root numerically, use function uniroot on f, as follows:
 
 uniroot(f, c(0, 2))

Except he was asking for the root of the derivative. If the classroom 
assignment allows use of R's limited symbolic differentiation you could try:

 df.dx - D(expression(5*cos(2*x)-2*x*sin(2*x)), x)
 df.dx
-(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) *
   2)))
(Which as one of the examples in the deriv help page notes is not the most 
simple form.)

I was assuming that the OP wanted a solution to:

d( abs(f(x)) )/dt  = 0 in the domain [1,2]

So:
f.df.dx - function (x) {
eval(parse(text=D(expression(5*cos(2*x)-2*x*sin(2*x)), x) ) )
   }
#  no abs() but we should be satisfied with either a minimum or a maximum
uniroot(f.df.dx, c(1,2) )

$root
[1] 1.958218267

$f.root
[1] 1.138013788e-05

$iter
[1] 4

$estim.prec
[1] 6.103515625e-05

It doesn't agree with my earlier method and I think this one has a greater 
probablity of being correct. I don't think I needed to take second differences.

-- 
David.

 $root
 [1] 0.6569286
 
 $f.root
 [1] -0.0001196119
 
 $iter
 [1] 6
 
 $estim.prec
 [1] 6.103516e-05
 
 This catches the root that lies between x = 0 and x = 2. If you want to find
 a set of roots, you can try a loop. Fortunately, since the function is even,
 you really only need to find the roots on one side of zero, since the ones
 on the other side are the same with opposite sign.
 
 lo - seq(0, 4.5, by = 1.5)
 hi -  seq(1.5, 6, by = 1.5)
 roots - numeric(length(lo))
 
 for(i in seq_along(lo)) roots[i] - uniroot(f, c(lo[i], hi[i]))$root
 roots
 
 See ?uniroot for other options and tolerance settings.
 
 HTH,
 Dennis
 
 On Wed, Aug 11, 2010 at 6:21 PM, TGS cran.questi...@gmail.com wrote:
 
 How would I numerically find the x value where the derivative of the
 function below is zero?
 
 x - seq(1,2, by = .01)
 y - 5*cos(2*x)-2*x*sin(2*x)
 plot(x,abs(y), type = l, ylab = |y|)
 
-- 

David Winsemius, MD
West Hartford, CT

__
R-help@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.


[R] Derivative

2010-08-11 Thread TGS
How would I numerically find the x value where the derivative of the function 
below is zero?

x - seq(1,2, by = .01)
y - 5*cos(2*x)-2*x*sin(2*x)
plot(x,abs(y), type = l, ylab = |y|)

__
R-help@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.


Re: [R] Derivative

2010-08-11 Thread David Winsemius


On Aug 11, 2010, at 9:21 PM, TGS wrote:

How would I numerically find the x value where the derivative of the  
function below is zero?


x - seq(1,2, by = .01)
y - 5*cos(2*x)-2*x*sin(2*x)
plot(x,abs(y), type = l, ylab = |y|)


Two ideas:
---minimize abs(diff(y))

abline(v=x[which.min(abs( diff(y) )) ])

---Or maximize the second derivative

plot(x[-(1:2)],diff(diff(y)), type = l, ylab = |y|)
abline(v=x[which.max(diff(diff(y)))])




__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Derivative

2010-08-11 Thread Dennis Murphy
Hi:

Try the following:

f - function(x) 5*cos(2*x)-2*x*sin(2*x)
curve(f, -5, 5)
abline(0, 0, lty = 'dotted')

This shows rather clearly that your function has multiple roots, which isn't
surprising given that it's a linear combination of sines and cosines. To
find a specific root numerically, use function uniroot on f, as follows:

 uniroot(f, c(0, 2))
$root
[1] 0.6569286

$f.root
[1] -0.0001196119

$iter
[1] 6

$estim.prec
[1] 6.103516e-05

This catches the root that lies between x = 0 and x = 2. If you want to find
a set of roots, you can try a loop. Fortunately, since the function is even,
you really only need to find the roots on one side of zero, since the ones
on the other side are the same with opposite sign.

lo - seq(0, 4.5, by = 1.5)
hi -  seq(1.5, 6, by = 1.5)
roots - numeric(length(lo))

for(i in seq_along(lo)) roots[i] - uniroot(f, c(lo[i], hi[i]))$root
roots

See ?uniroot for other options and tolerance settings.

HTH,
Dennis

On Wed, Aug 11, 2010 at 6:21 PM, TGS cran.questi...@gmail.com wrote:

 How would I numerically find the x value where the derivative of the
 function below is zero?

 x - seq(1,2, by = .01)
 y - 5*cos(2*x)-2*x*sin(2*x)
 plot(x,abs(y), type = l, ylab = |y|)

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Derivative

2010-08-11 Thread David Winsemius


On Aug 12, 2010, at 12:49 AM, Dennis Murphy wrote:


Hi:

Try the following:

f - function(x) 5*cos(2*x)-2*x*sin(2*x)
curve(f, -5, 5)
abline(0, 0, lty = 'dotted')

This shows rather clearly that your function has multiple roots,  
which isn't
surprising given that it's a linear combination of sines and  
cosines. To
find a specific root numerically, use function uniroot on f, as  
follows:



uniroot(f, c(0, 2))


Except he was asking for the root of the derivative. If the classroom  
assignment allows use of R's limited symbolic differentiation you  
could try:


 df.dx - D(expression(5*cos(2*x)-2*x*sin(2*x)), x)
 df.dx
-(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) *
2)))
(Which as one of the examples in the deriv help page notes is not the  
most simple form.)


I was assuming that the OP wanted a solution to:

d( abs(f(x)) )/dt  = 0 in the domain [1,2]

So:
f.df.dx - function (x) {
 eval(parse(text=D(expression(5*cos(2*x)-2*x*sin(2*x)), x) ) )
}
#  no abs() but we should be satisfied with either a minimum or a  
maximum

uniroot(f.df.dx, c(1,2) )

$root
[1] 1.958218267

$f.root
[1] 1.138013788e-05

$iter
[1] 4

$estim.prec
[1] 6.103515625e-05

It doesn't agree with my earlier method and I think this one has a  
greater probablity of being correct. I don't think I needed to take  
second differences.


--
David.


$root
[1] 0.6569286

$f.root
[1] -0.0001196119

$iter
[1] 6

$estim.prec
[1] 6.103516e-05

This catches the root that lies between x = 0 and x = 2. If you want  
to find
a set of roots, you can try a loop. Fortunately, since the function  
is even,
you really only need to find the roots on one side of zero, since  
the ones

on the other side are the same with opposite sign.

lo - seq(0, 4.5, by = 1.5)
hi -  seq(1.5, 6, by = 1.5)
roots - numeric(length(lo))

for(i in seq_along(lo)) roots[i] - uniroot(f, c(lo[i], hi[i]))$root
roots

See ?uniroot for other options and tolerance settings.

HTH,
Dennis

On Wed, Aug 11, 2010 at 6:21 PM, TGS cran.questi...@gmail.com wrote:


How would I numerically find the x value where the derivative of the
function below is zero?

x - seq(1,2, by = .01)
y - 5*cos(2*x)-2*x*sin(2*x)
plot(x,abs(y), type = l, ylab = |y|)



--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


[R] Derivative of the probit

2010-05-06 Thread Andrew Redd
Is there a function to compute the derivative of the probit (qnorm) function
in R, or in any of the packages?

Thanks,
-Andrew

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Derivative of the probit

2010-05-06 Thread Thomas Stewart
f-function(x) 1/dnorm(qnorm(x))
for x in (0,1)

-tgs

On Thu, May 6, 2010 at 4:40 PM, Andrew Redd ar...@stat.tamu.edu wrote:

 Is there a function to compute the derivative of the probit (qnorm)
 function
 in R, or in any of the packages?

 Thanks,
 -Andrew

[[alternative HTML version deleted]]

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Derivative of the probit

2010-05-06 Thread Ted Harding
On 06-May-10 20:40:30, Andrew Redd wrote:
 Is there a function to compute the derivative of the probit (qnorm)
 function
 in R, or in any of the packages?
 
 Thanks,
 -Andrew

I don't think so (though stand to be corrected). However, it would
be straightforward to write one.

For simplicity of notation:
  P(x) = pnorm(x)
  Q(p) = qnrom(p)
  D(x) = dnorm(x)
  ' stands for derivative.

Then

  P'(x) = D(x)

  P(Q(p)) = p

Differentiate w.r.to p:

  P'(Q(p))*Q'(p) = 1

  Q'(p) = 1/P'(Q(p)) = 1/D(Q(p))

Hence:

  dqnorm - function(p){ 1/dnorm(qnorm(p)) }

(I think that's right ... )

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 06-May-10   Time: 22:23:53
-- XFMail --

__
R-help@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.


Re: [R] Derivative of a smooth function

2010-04-04 Thread Julien Gagneur
Hi Fir,

you can alternatively use local regression, implemented in the package locfit, 
which can also estimate derivatives:

library(locfit)
attach(cars)
# main fit
fit - locfit( dist ~ speed )
# fit 1st derivative
fitd - locfit( dist ~ speed , deriv =1)
# plots...
plot(speed, dist )
lines(fit)
lines(fitd, col=red)


Hope this helps,

Julien

On Fri, Apr 2, 2010 at 2:06 PM, FMH kagba2...@yahoo.com wrote:

 
 Dear All,
 
 I've been searching for appropriate codes to compute the rate of change and
 the curvature of  nonparametric regression model whish was denoted by a
 smooth function but unfortunately don't manage to do it. I presume that such
 characteristics from a smooth curve can be determined by the first and
 second derivative operators.
 
 The following are the example of fitting a nonparametric regression model
 via smoothing spline function from the Help file in R.
 
 ###
 attach(cars)
 plot(speed, dist, main = data(cars)smoothing splines)
 cars.spl - smooth.spline(speed, dist)
 lines(cars.spl, col = blue)
 lines(smooth.spline(speed, dist, df=10), lty=2, col = red)
 legend(5,120,c(paste(default [C.V.] = df =,round(cars.spl$df,1)),s( * ,
 df = 10)), col = c(blue,red), lty = 1:2, bg='bisque')
 detach()
 
 ###
 
 
 Could someone please advice me the appropriate way to determine such
 derivatives on the curves which were fitted by the function above and would
 like to thank you in advance.
 
 Cheers
 Fir
 
 
 
 
 
 __
 R-help@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.
 


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Derivative of a smooth function

2010-04-03 Thread Chidambaram Annamalai
While this doesn't answer your question, I want to let you know that there
is a proposal for a related improvement within R that will let users compute
(numerically) the derivatives, of any order, of a given function inside of
R. In your case, this means that you will write the smooth spline function,
symbolically f(x), that will interpolate between the points. Using Automatic
Differentiation, the proposed solution, will automatically let you find
f'(x), f''(x), etc.. by using the same function but overloading the meaning
of the arithmetic operators and mathematical functions to act upon a special
data type.

The initial idea
http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2010:adinrcame
from Prof. John Nash who suggested bringing the ability of Automatic
Differentiation to R. We both have, since, collaborated to bring out
adetailed 
proposalhttp://socghop.appspot.com/gsoc/student_proposal/show/google/gsoc2010/quantumelixir/t126989852709outlining
the various features to be implemented.

Note that, this is being planned to be implemented as part of Google's
Summer of Code program for this year. So, should our proposal be selected,
much more than simple second derivative computation can be accomplished from
within R.

Regards,
Chillu

On Fri, Apr 2, 2010 at 2:06 PM, FMH kagba2...@yahoo.com wrote:


 Dear All,

 I've been searching for appropriate codes to compute the rate of change and
 the curvature of  nonparametric regression model whish was denoted by a
 smooth function but unfortunately don't manage to do it. I presume that such
 characteristics from a smooth curve can be determined by the first and
 second derivative operators.

 The following are the example of fitting a nonparametric regression model
 via smoothing spline function from the Help file in R.

 ###
 attach(cars)
 plot(speed, dist, main = data(cars)smoothing splines)
 cars.spl - smooth.spline(speed, dist)
 lines(cars.spl, col = blue)
 lines(smooth.spline(speed, dist, df=10), lty=2, col = red)
 legend(5,120,c(paste(default [C.V.] = df =,round(cars.spl$df,1)),s( * ,
 df = 10)), col = c(blue,red), lty = 1:2, bg='bisque')
 detach()

 ###


 Could someone please advice me the appropriate way to determine such
 derivatives on the curves which were fitted by the function above and would
 like to thank you in advance.

 Cheers
 Fir





 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


[R] Derivative of a smooth function

2010-04-02 Thread FMH

Dear All,

I've been searching for appropriate codes to compute the rate of change and the 
curvature of  nonparametric regression model whish was denoted by a smooth 
function but unfortunately don't manage to do it. I presume that such 
characteristics from a smooth curve can be determined by the first and second 
derivative operators.

The following are the example of fitting a nonparametric regression model via 
smoothing spline function from the Help file in R.

###
attach(cars)
plot(speed, dist, main = data(cars)    smoothing splines)
cars.spl - smooth.spline(speed, dist)
lines(cars.spl, col = blue)
lines(smooth.spline(speed, dist, df=10), lty=2, col = red)
legend(5,120,c(paste(default [C.V.] = df =,round(cars.spl$df,1)),s( * , df 
= 10)), col = c(blue,red), lty = 1:2, bg='bisque')
detach()

###


Could someone please advice me the appropriate way to determine such 
derivatives on the curves which were fitted by the function above and would 
like to thank you in advance.

Cheers
Fir 





__
R-help@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.


Re: [R] Derivative of a smooth function

2010-04-02 Thread Ravi Varadhan
Please learn how to use `RsiteSearch' before posting questions to the list:

 RSiteSearch(derivative smooth function)

This should have provided you with plenty of solutions. 

Ravi.


Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: FMH kagba2...@yahoo.com
Date: Friday, April 2, 2010 4:39 am
Subject: [R] Derivative of a smooth function
To: r-help@r-project.org
Cc: r-sig-fina...@stat.math.ethz.ch


 Dear All,
 
 I've been searching for appropriate codes to compute the rate of 
 change and the curvature of  nonparametric regression model whish was 
 denoted by a smooth function but unfortunately don't manage to do it. 
 I presume that such characteristics from a smooth curve can be 
 determined by the first and second derivative operators.
 
 The following are the example of fitting a nonparametric regression 
 model via smoothing spline function from the Help file in R.
 
 ###
 attach(cars)
 plot(speed, dist, main = data(cars)    smoothing splines)
 cars.spl - smooth.spline(speed, dist)
 lines(cars.spl, col = blue)
 lines(smooth.spline(speed, dist, df=10), lty=2, col = red)
 legend(5,120,c(paste(default [C.V.] = df 
 =,round(cars.spl$df,1)),s( * , df = 10)), col = c(blue,red), 
 lty = 1:2, bg='bisque')
 detach()
 
 ###
 
 
 Could someone please advice me the appropriate way to determine such 
 derivatives on the curves which were fitted by the function above and 
 would like to thank you in advance.
 
 Cheers
 Fir 
 
 
 
 
 
 __
 R-help@r-project.org mailing list
 
 PLEASE do read the posting guide 
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] Derivative of nonparametric curve

2009-09-14 Thread FMH
Thank you



- Original Message 
From: spencerg spencer.gra...@prodsyse.com
To: Liaw, Andy andy_l...@merck.com
Cc: Rolf Turner r.tur...@auckland.ac.nz; FMH kagba2...@yahoo.com; 
r-help@r-project.org
Sent: Wednesday, September 9, 2009 3:08:43 PM
Subject: Re: [R] Derivative of nonparametric curve

    This may be overkill for your application, but you might be interested in 
the fda package, for which a new book appeared a couple of months ago:  
Functional Data Analysis with R and Matlab (Springer Use R! series, by 
Ramsay, Hooker and Graves;  I'm the third author).  The package includes a 
scripts subdirectory with R code to recreate all but one of the 76 figures in 
the book.  [To find this scripts directory, use system.file('scripts', 
package='fda').] 

    Functional data analysis generalizes spline smoothing in two important 
ways: 

          (1) It supports the use of an arbitrary finite basis set to 
approximate elements of a function space;  spline smoothing uses splines only, 
usually cubic splines.  The first derivative of a cubic spline is piecewise 
quadratic, and the second derivative is piecewise linear.  If you want 
something smoother than linear, you need at least a quartic spline, and Ramsay 
has recommended quintics -- degree 5 polynomials = order 6 spline. 

          (2) It allows the curve to be smoothed using an arbitrary linear 
differential operator, not just the second derivative.  This can be important 
if you have theory saying that the truth should follow a particular 
differential equation.  Otherwise, if you want to estimate the second 
derivative, Ramsay has recommended smoothing with the fourth derivative rather 
than the second.  (In any event, smoothing is achieved by penalized least 
squares with the penalty being proportional to the integral of the square of 
the chosen linear differential operator.) 

    To reinforce this second point, chapter 11 of Functional Data Analysis 
with R and Matlab describes functional differential analysis, which will 
estimate non-constant coefficients in a differential equation model. 

    Hope this helps.      Spencer Graves


Liaw, Andy wrote:
 From: Rolf Turner
  
 On 8/09/2009, at 9:07 PM, FMH wrote:
 
    
 Dear All,
 
 I'm looking for a way on computing the derivative of first and  second 
 order of a smoothing curve produced by a nonprametric  regression. For 
 instance, if we run the R script below, a smooth  nonparametric regression 
 curve is produced.
 
 provide.data(trawl)
 Zone92  - (Year == 0  Zone == 1)
 Position - cbind(Longitude - 143, Latitude)
 dimnames(Position)[[2]][1] - Longitude - 143
 sm.regression(Longitude, Score1, method = aicc, col = red,  model = 
 linear)
 
 Could someone please give some hints on the way to find the  derivative on 
 the curve at some points ?
      
 See
 
     ?smooth.spline
 and
     ?predict.smooth.spline
    
 
 Since sm.regression() (from the sm package, I presume) uses kernel
 methods, a kernel-based estimator of derivatives is available in the
 KernSmooth package.
 
 Andy
    
     cheers,
 
         Rolf Turner
 
 ##
 Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
 
 __
 R-help@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.
 
    
 Notice:  This e-mail message, together with any attachme...{{dropped:12}}
 
 __
 R-help@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.
 
  


-- Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567


   
__
R-help@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.


Re: [R] Derivative of nonparametric curve

2009-09-09 Thread Liaw, Andy
From: Rolf Turner
 
 On 8/09/2009, at 9:07 PM, FMH wrote:
 
  Dear All,
 
  I'm looking for a way on computing the derivative of first and  
  second order of a smoothing curve produced by a nonprametric  
  regression. For instance, if we run the R script below, a smooth  
  nonparametric regression curve is produced.
 
  provide.data(trawl)
  Zone92   - (Year == 0  Zone == 1)
  Position - cbind(Longitude - 143, Latitude)
  dimnames(Position)[[2]][1] - Longitude - 143
  sm.regression(Longitude, Score1, method = aicc, col = red,   
  model = linear)
 
  Could someone please give some hints on the way to find the  
  derivative on the curve at some points ?
 
 See
 
   ?smooth.spline
 and
   ?predict.smooth.spline

Since sm.regression() (from the sm package, I presume) uses kernel
methods, a kernel-based estimator of derivatives is available in the
KernSmooth package.

Andy
 
   cheers,
 
   Rolf Turner
 
 ##
 Attention:\ This e-mail message is privileged and 
 confid...{{dropped:9}}
 
 __
 R-help@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.
 
Notice:  This e-mail message, together with any attachme...{{dropped:12}}

__
R-help@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.


Re: [R] Derivative of nonparametric curve

2009-09-09 Thread spencerg
 This may be overkill for your application, but you might be 
interested in the fda package, for which a new book appeared a couple 
of months ago:  Functional Data Analysis with R and Matlab (Springer 
Use R! series, by Ramsay, Hooker and Graves;  I'm the third author).  
The package includes a scripts subdirectory with R code to recreate 
all but one of the 76 figures in the book.  [To find this scripts 
directory, use system.file('scripts', package='fda').] 



 Functional data analysis generalizes spline smoothing in two 
important ways: 



  (1) It supports the use of an arbitrary finite basis set to 
approximate elements of a function space;  spline smoothing uses splines 
only, usually cubic splines.  The first derivative of a cubic spline is 
piecewise quadratic, and the second derivative is piecewise linear.  If 
you want something smoother than linear, you need at least a quartic 
spline, and Ramsay has recommended quintics -- degree 5 polynomials = 
order 6 spline. 



  (2) It allows the curve to be smoothed using an arbitrary 
linear differential operator, not just the second derivative.  This can 
be important if you have theory saying that the truth should follow a 
particular differential equation.  Otherwise, if you want to estimate 
the second derivative, Ramsay has recommended smoothing with the fourth 
derivative rather than the second.  (In any event, smoothing is achieved 
by penalized least squares with the penalty being proportional to the 
integral of the square of the chosen linear differential operator.) 



 To reinforce this second point, chapter 11 of Functional Data 
Analysis with R and Matlab describes functional differential 
analysis, which will estimate non-constant coefficients in a 
differential equation model. 



 Hope this helps. 
 Spencer Graves



Liaw, Andy wrote:

From: Rolf Turner
  

On 8/09/2009, at 9:07 PM, FMH wrote:



Dear All,

I'm looking for a way on computing the derivative of first and  
second order of a smoothing curve produced by a nonprametric  
regression. For instance, if we run the R script below, a smooth  
nonparametric regression curve is produced.


provide.data(trawl)
Zone92   - (Year == 0  Zone == 1)
Position - cbind(Longitude - 143, Latitude)
dimnames(Position)[[2]][1] - Longitude - 143
sm.regression(Longitude, Score1, method = aicc, col = red,   
model = linear)


Could someone please give some hints on the way to find the  
derivative on the curve at some points ?
  

See

?smooth.spline
and
?predict.smooth.spline



Since sm.regression() (from the sm package, I presume) uses kernel
methods, a kernel-based estimator of derivatives is available in the
KernSmooth package.

Andy
 
  

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and 
confid...{{dropped:9}}


__
R-help@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.



Notice:  This e-mail message, together with any attachme...{{dropped:12}}

__
R-help@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.

  



--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

__
R-help@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.


[R] Derivative of nonparametric curve

2009-09-08 Thread FMH
Dear All,

I'm looking for a way on computing the derivative of first and second order of 
a smoothing curve produced by a nonprametric regression. For instance, if we 
run the R script below, a smooth nonparametric regression curve is produced. 

provide.data(trawl)
Zone92   - (Year == 0  Zone == 1)
Position - cbind(Longitude - 143, Latitude)
dimnames(Position)[[2]][1] - Longitude - 143
sm.regression(Longitude, Score1, method = aicc, col = red,  model = 
linear)

Could someone please give some hints on the way to find the derivative on the 
curve at some points ?

Thank you.
Kagba




__
R-help@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.


Re: [R] Derivative of nonparametric curve

2009-09-08 Thread Rolf Turner


On 8/09/2009, at 9:07 PM, FMH wrote:


Dear All,

I'm looking for a way on computing the derivative of first and  
second order of a smoothing curve produced by a nonprametric  
regression. For instance, if we run the R script below, a smooth  
nonparametric regression curve is produced.


provide.data(trawl)
Zone92   - (Year == 0  Zone == 1)
Position - cbind(Longitude - 143, Latitude)
dimnames(Position)[[2]][1] - Longitude - 143
sm.regression(Longitude, Score1, method = aicc, col = red,   
model = linear)


Could someone please give some hints on the way to find the  
derivative on the curve at some points ?


See

?smooth.spline
and
?predict.smooth.spline

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.