Hi!, 
I'm really hoping someone out there will be able to help me.

I recently started my MSc dissertation on Population Projection Matrices, which has been going well until now. I am trying to set-up a general script that does a pairwise comparison of all elements in my matrices. 

So for example, given that I have the following matrix S:

> S

        [,1]     [,2]         [,3]

[1,] 0.00000 0.007361183 0.0001634936

[2,] 13.88458 0.353988378 0.0000000000

[3,] 0.00000 16.086367098 0.3572819557

I'd like to create a matrix SA for each element in my matrix compared to another element like so:

> SA 

S-[1,1]

         [,1]        [,2]        [,3]

[1,] [1,1]-[1,1] [1,2]-[1,1] [1,3]-[1,1]

[2,] [2,1]-[1,1] [2,2]-[1,1] [2,3]-[1,1]

[3,] [3,1]-[1,1] [3,2]-[1,1] [3,3]-[1,1]



S-[1,2]

[...]



S-[1,3]

[...]

... and so on

The aim is to be able to prove existing rules and trends across matrix dimensions. 

For example, I've been trying to test whether the first line of values decreases or remains the same from column 1 to the penultimate column: S[1,j] >= S[1,l>j]

The last thing I tried was:

M<-Matlab2R("[0 24.724 1377.48;0.029328 0.26 0;0 0.014 0.78]") 

w <- abs(Re(eigen(M)$vectors[,1]))

v <- abs(Re(eigen(t(M))$vectors[,1]))

w <- w/sum(w)

v <- v/(t(v)%*%w) 

S <- (v%*%t(w))/as.vector(t(v)%*%w)

S



n<- length(S)

M.comp <- array(S,dim=c(n,n,n,n))

for (i in 1:n) {

for (j in 1:n) {

for (k in 1:n) {

for (l in 1:n) {

poscompa[1,3,1,j-1] <- S[i,j]<=S[k,l] # if=1, then TRUE and if=0, then FALSE 

}}}}

M.comp

sum(poscompa[1,3,1,1:n]) # should give me the value for n. I know this doesn't test it accurately, but first I need to get the loops to work right.

I'm getting an array of errors such as "can't find function poscompa (or compa)", "subscripts out of range" or "type of closure not valid" regardless of what I try. Using COMPAR (poscompa and compa) was the last recommendation I got, but I'm starting to wonder if there might be other ways to go about this. All out-of-the-box ideas I've come up with and tried haven't gotten me much farther. I've now practically exhausted my creative thinking, and I'm becoming very frustrated. I'd really like to get this script going since my current one would make my life hell for large populations (60x60 population matrices). 

Any ideas on how I could move forward? 



Many, many thanks!

Marta

	[[alternative HTML version deleted]]

