Hi everyone. My problem is about multivariate analysis. Given a multivariate data X, of dimension (n by p), n is the number of observations while p is the number of variables. I wanted a sample of size p+1 that will have its product of the eigen values of the covariance matrix to be the minimum among all the possible samples (n combination (p+1)). I have written a syntax with worked well, but the problem is that it does not work when the dimension of X is large (when n is greater than 25). I think the problem is memory size, is there anyway I can maximize the memory. Here is the syntax that I used. > bestunits <- function(x){ + n <- nrow(x) + p <- ncol(x) + h <- p+1 + nchoosek <- function(n,h){ + factorial(n)/(factorial(h+1)*factorial(n-h-1))} + vec11 <- matrix(nrow=nchoosek(n,h), ncol=p) + vec12 <- matrix(nrow=nchoosek(n,h), ncol=h) + for (i in 1:nchoosek(n,h)){ + flag <- sample(1:n, h, replace=FALSE) + z <- x[flag,] + y <- eigen(var(z), only.values=TRUE)$values + vec11[i,] <- y + vec12[i,] <- flag + } + product <- apply(vec11,1,prod) + best <- which.min(product) + sample <- vec12[best,] + bestsample <- x[sample,] + return(bestsample) + } Thanks Oyeyemi, Gafar Matanmi Department of Statistics University of Ilorin Ilorin, Nigeria
[[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.