[R] Matrix multiplication multivariate

MarcioRibeiro mestat at pop.com.br
Sat Feb 21 00:55:09 CET 2009


Hi listers...
I am trying to do a matrix multiplication...
Suppose my data has 100 obs and 2 variables...
I calculated the estimateurs of location and dispersion...
So now I would like to do the following...
t(Xi-location)%*%solve(dispersion)%*%(Xi-location)
My code is...
Z<-rep(2,200)
Z<-matrix(Z,nrow=100,ncol=2,byrow=TRUE)
p<-ncol(Z)
N<-nrow(Z)
poids<-rep(1/N,N)
results<-cov.wt(Z, wt=poids, method="ML")
loc<-t(as.matrix(results$center))
disp<-as.matrix(results$cov)
loc1<-rep(2.678117,100)#SUPPOSE THAT THE LOCATION HAS THIS VALUE...
loc2<-rep(4.824589,100)#EVEN THAT I STILL NEED TO FIND OUT TO DO THIS PART
MORE EFFICIENTLY...
loc<-cbind(loc1,loc2)

niter<-100
x1<-rep(0,niter)
x2<-rep(0,niter)
for (i in 1:niter){
x1[i]<-(Z[i,1]-loc[i,1])
x2[i]<-(Z[i,2]-loc[i,2])
}
x<-cbind(x1,x2)

So, I calculated (Xi-location=xi)
But now I am having a hard time to calculate
(t(xi)%*%solve(dispersion)%*%(xi))
I am trying something like this...

for (i in 1:niter){
w[i]<-t(x[i,])%*%idisp%*%(x[i,])
}

But there is something wrong with the dimensions... I am continuing to find
out a way...
But appreciate any suggestions!
Thanks in advance,
Marcio

-- 
View this message in context: http://www.nabble.com/Matrix-multiplication-multivariate-tp22130812p22130812.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list