search for: mahadist

Displaying 2 results from an estimated 2 matches for "mahadist".

2008 Oct 09
2
vectorization instead of using loop
...s. We want to calculate Mahalanobis distances, which take into account the covariance among variables. Below is the piece of code we wrote ("covmat" in the function below is the variance-covariance matrix among variables in Data that has to be fed into mahalonobis function we are using). mahadist = function(x, covmat) { dismat = matrix(0,ncol=nrow(x),nrow=nrow(x)) for (i in 1:nrow(x)) { dismat[i,] = mahalanobis(as.matrix(x), as.matrix(x[i,]), covmat)^.5 } return(dismat) } This piece of code works, but it is very slow. We were wondering if it's at all possible to somehow vect...
2008 Oct 07
1
vectorization of a loop for mahalanobis distance calculation
.... We want to calculate Mahalanobis distances, which take into account the covariance among variables. Below is the piece of code we wrote ("covmat" in the function below is the variance-covariance matrix among variables in Data that has to be fed into mahalonobis function we are using). mahadist = function(x, covmat) { dismat = matrix(0,ncol=nrow(x),nrow=nrow(x)) for (i in 1:nrow(x)) { dismat[i,] = mahalanobis(as.matrix(x), as.matrix(x[i,]), covmat)^.5 } return(dismat) } This piece of code works, but it is very slow. We were wondering if it's at all possible to someho...