An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091102/eeafc7bf/attachment-0001.pl>
need help in using Hessian matrix
2 messages · Laila Alkhalfan, Uwe Ligges
Laila Alkhalfan wrote:
Hi
I need to find the Hessian matrix for a complicated function from a certain
kind of data but i keep getting this error
Error in f1 - f2 : non-numeric argument to binary operator
the data is given by
U<-runif(n)
Us<-sort(U)
tau1<- 2
F1tau<- pgamma((tau1/theta1),shape,1)
N1<-sum(Us<F1tau)
X1<- Us[1:N1]
Ti<- theta1*qgamma(Us[1:N1],shape,1)
w=N1+1
V<- Us[w:r]
N2<- length(V)
V1<-theta2*qgamma(V,shape,1)
Tj<-V1+tau1-(theta2/theta1)*tau1
c1<-matrix(Ti,ncol=1)
c2<-matrix(Tj,ncol=1)
cc<-data.frame(rbind(c1,c2))[,1]
require(numDeriv)
m1<- function(x) #a function that generates the estimates
{
loglik<-function(alpha,theta1,theta2){
-(
log(factorial(n)/(factorial(N1)*factorial(N2)))-r*lgamma(alpha)-alpha*N1*log(theta1)
-alpha*(r-N1)*log(theta2)+(alpha-1)*sum(log(cc[1:N1]))+(alpha-1)*sum(log(cc[w:r]-tau1+
(theta2/theta1)*tau1))-(1/theta1)*sum(cc[1:N1])-(1/theta2)*sum(cc[w:r]-tau1+(theta2/theta1)*tau1)+
(n-r)*log(1-pgamma((max(cc)-tau1+(theta2/theta1)*tau1)/theta2,alpha,1)))
}}
H<-hessian(m1, cc)
Is there a particular reason why you need the hessian? PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, *reproducible* code. Please make your function more readable. We are happy to help, but that means you need to make your code readable and reproducible by giving some corresponding data. Best wishes, Uwe Ligges
Thank you and take care. Laila [[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.