Parminder Mankoo
2010-Jul-06 20:25 UTC
[R] Help needed with numericDeriv and optim functions
Hello All:
I have defined the following function (fitterma as a sum of exponentials)
that best fits my cumulative distribution. I am also attaching the
"xtime"
values that I have. I want to try two things as indicated below and am
experiencing problems. Any help will be greatly appreciated.
Best, Parmee
-----------------------
*fitterma <- function(xtime) { *
*a <- -0.09144115*
*b <- -0.01335756*
*c <- -2.368057*
*d <- -0.00600052*
*return(exp(a+b*xtime)+exp(c+d*xtime))*
*}*
I want to do two things:
*First, take the numerical derivative of this function (fitterma)* to obtain
probability density function. I tried using:
*> numericDeriv(fitterma,"xtime")*
*Error in numericDeriv(fitterma, "xtime") : *
* cannot coerce type 'closure' to vector of type 'double'*
Looking at the complaint above, I don't understand how to use the above
function properly. Any help will be appreciated.
*Secondly, I want to minimize this function (fitterma) as a function of
xtime*. I tried using:
*> optim(1, fitterma)*
But I don't understand this function either of how to use it properly.
--------
*> xtime*
[1] 1 2 3 4 7 8 10 11 12 13 15 16 18 19 20 21 22 24
25 27 29 30 31 33 35 36 42
[28] 43 44 45 48 49 51 52 53 54 56 59 61 63 72 73 80 82 84
87 90 92 95 99 100 103 105 110
[55] 111 112 117 118 122 126 132 133 139 140 143 144 151 153 156 162 164 177
186 200 201 216 228 231 242 250 260
[82] 278 283 287 314 340 357 378 384 389 392 411 467 553 587 991 999
[[alternative HTML version deleted]]
