I fit my CDF to sum of exponentials and now I want to take the numerical derivative of this function to obtain probability density.I will really appreciate your help reagrding the error messages I am getting which I don't understand. * *> fitterma <- function(xtime) {a <- -0.09144115 b <- -0.01335756 c <- -2.368057 d <- -0.00600052 return(exp(a+b*xtime)+exp(c+d*xtime)) }> numericDeriv(fitterma,"xtime")*Error in numericDeriv(fitterma, "xtime") : * * cannot coerce type 'closure' to vector of type 'double'* * * *Thanks,* *parmee* [[alternative HTML version deleted]]
Please do not do multiple postings. You do not need numerical derivative, but a refresher course in calculus. fitterma.deriv <- function(xtime) { a <- -0.09144115 b <- -0.01335756 c <- -2.368057 d <- -0.00600052 deriv <- b * exp(a + b*xtime) + d * exp(c + d * xtime) return(deriv) } require(numDeriv) xtime <- seq(0, 1, length=100) deriv.exact <- fitterma.deriv(xtime) deriv.num <- grad(x=xtime, func=fitterma)> all.equal(deriv.exact, deriv.num)[1] TRUE>Hope this is helpful, Ravi. ____________________________________________________________________ Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu ----- Original Message ----- From: Parminder Mankoo <pkmankoo09 at gmail.com> Date: Tuesday, July 6, 2010 7:03 pm Subject: [R] numerical derivative R help To: r-help at r-project.org> I fit my CDF to sum of exponentials and now I want to take the numerical > derivative of this function to obtain probability density.I will really > appreciate your help reagrding the error messages I am getting which > I don't > understand. > > * > * > > > fitterma <- function(xtime) { > > a <- -0.09144115 > > b <- -0.01335756 > > c <- -2.368057 > > d <- -0.00600052 > > return(exp(a+b*xtime)+exp(c+d*xtime)) > > } > > > > numericDeriv(fitterma,"xtime") > > > *Error in numericDeriv(fitterma, "xtime") : * > > * cannot coerce type 'closure' to vector of type 'double'* > > * > * > > *Thanks,* > > *parmee* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code.
Which package are you using? -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Parminder Mankoo Sent: Tuesday, July 06, 2010 10:50 PM To: r-help at r-project.org Subject: [R] numerical derivative R help Importance: Low I fit my CDF to sum of exponentials and now I want to take the numerical derivative of this function to obtain probability density.I will really appreciate your help reagrding the error messages I am getting which I don't understand. * *> fitterma <- function(xtime) {a <- -0.09144115 b <- -0.01335756 c <- -2.368057 d <- -0.00600052 return(exp(a+b*xtime)+exp(c+d*xtime)) }> numericDeriv(fitterma,"xtime")*Error in numericDeriv(fitterma, "xtime") : * * cannot coerce type 'closure' to vector of type 'double'* * * *Thanks,* *parmee* [[alternative HTML version deleted]] ______________________________________________ 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. DISCLAIMER:\ Sample Disclaimer added in a VBScript.\ ...{{dropped:3}}