[R] dudi.pca behaviour and discrimin

Sebastien Durand sebastien.durand at umontreal.ca
Sat Jul 31 22:57:07 CEST 2004


Hello,

I not have attached in this e-mail the zipped 
list of matrices I am using because it has 1 meg 
once zipped and anyway we cannot send attached 
files on r-help mailling list.

First, after running the code that is written 
bellow, I realized that the printout of dudi.pca 
gives me for both of my matrices
$cw length that are unequal to either respective $rank or $eig lengths.
Is that normal, if not how can I solve it, or get 
around it?   (discrimin() seems to have an issue 
about that)

Secondly, it does not matter which matrices I am 
treating first, but once the second is pasted on 
the second run of my function best, discrimin 
crashes.
The weared thing about this is, that if I perform 
the same operations directly without making a 
function both matrices can be analysed by 
discrimin.
Is it my function that is wrong or the something within the discrimin code!

Here is my code:
load("~/matrix2.RData")

best<-function(liste=alt.transf,nombre=99){
	x<-liste[[nombre]]
	library(ade4)
	p<-99
	xx<-cov(x[,-(1:3)])
	a<-eigen(xx,only.values=T)
	poids<-cumsum(a$values/sum(a$values))
	nombre<-min(which(poids>=(p/100)),na.rm=T)
	acp<-dudi.pca(x[,-(1:3)],scale=T,scannf=F,nf=nombre) #if ve or vt
	print(acp)
	d<-discrimin(acp, as.factor(x[,1]),scan=F,nf=4)
  	return(d)
  }

  b<-best(k,1)

#look at the print out ...
....
$rank: 166
eigen values: 86.02 17.09 12.76 8.727 8.338 ...
   vector length mode    content
1 $cw    167    numeric column weights
2 $lw    475    numeric row weights
3 $eig   166    numeric eigen values
...
#now try
  b<-best(k,2)

#look at the print out ...
....
$rank: 218
eigen values: 104.7 28.94 14.56 10.62 7.793 ...
   vector length mode    content
1 $cw    219    numeric column weights
2 $lw    507    numeric row weights
3 $eig   218    numeric eigen values
...
Error in tapply(dudi$lw, fac, sum) : arguments must have same length

Any suggestions would be really helpful.  I got ton's a matrices to analyse

Thanks a lot!
-- 
  Sébastien Durand
Maîtrise en biologie
Université de Montréal
(514) 343-6864
Université du Québec à Montréal
(514) 987-3000 (1572#)




More information about the R-help mailing list