[R] deriv - accessing numeric output listed under gradient attribute

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Jul 20 01:57:33 CEST 2005



Jay Rotella wrote:
> Hi,
> I am interested in using the numeric output from the "gradient" attribute of 
> deriv's output in subsequent analyses.
> But, I have so far been unable to determine how to do so.
> 
> I will use the example from the deriv help to illustrate.
> 
> 
>>## function with defaulted arguments:
>>   (fx <- deriv(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"),
> 
>                   function(b0, b1, th, x = 1:7){} ) )
> 
>>    fx(2,3,4)
> 
> 
> This yields
> [1] 4.522689 4.121320 3.783811 3.500000 3.261345 3.060660 2.891905
> attr(,"gradient")
>      b0        b1        th
> [1,]  1 0.8408964 0.1092872
> [2,]  1 0.7071068 0.1837984
> [3,]  1 0.5946036 0.2318331
> [4,]  1 0.5000000 0.2599302
> [5,]  1 0.4204482 0.2732180
> [6,]  1 0.3535534 0.2756976
> [7,]  1 0.2973018 0.2704720
> 
> I would greatly appreciate it if anyone could tell me how to convert the 
> numbers listed under "b0", "b1", and "th" into a matrix.
> 
> Thanks!
> 
> Jay Rotella
> Ecology Department
> Montana State University
> Bozeman, MT 59717
> 


Try:

attr(fx(2, 3, 4), "gradient")

--sundar




More information about the R-help mailing list