Hello R-help, I need to compute matrices of first derivatives of a covariance matrix C with entries given by c_ij=theta*exp(-0.5* sum(eta*(x[i,]-x[j,])^2)), wrt to elements of eta, a m-dimensional vector of parameters, given a n*m data matrix x. So far, I have been computing matrices for each parameter (given by par[index]) analytically, using the following
kmatder<- function(x, par, index) { ## x: n*m matrix ## par: vector of parameters, m=length(par)=ncol(x) ## compute matrix of partial derivatives wrt parameter par[index]: Cder = d C/d par[index] theta<-1 eta<-par n<-nrow(x) Cder<-matrix(0,n,n) for (i in 1:n) { for (j in i:n) { Cder[i,j]<-(-0.5*((x[i,index]-x[j,index])^2))*theta*exp(-0.5* sum(eta*(x[i,]-x[j,])^2)) } } Cder<-0.5*(Cder+t(Cder)) Cder } I was wondering whether it might be possible to speed up things using numDeriv (jacobian). If so, what would be the right way to implement a suitable method ? Cheers, Gao Daomeng [[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.