Error in a * b * y : non-conformable arrays
r
Solution
The phrase "conformable arrays" is linear algebra jargon that means "arrays that can sensibly be operated on together".
For example, if you want to add two arrays together, they need to be the same size.
In fact, since the standard math operators, `+`, `-`, `*`, `/`, `^`, etc. operate element-by-element, you always need the arrays (or matrices) to be the same size.
For (inner) matrix multiplication, `%*%`, the number of columns in the first matrix must be the same as the number of rows in the second matrix.
Problem
``` Cold <- matrix(c(1.89,3.76,2.47,4.76),2,2,byrow=TRUE) X <- matrix(c(0,2,2,4,3,6),3,2,byrow=TRUE) y <- matrix(c(1,5,6)) m <- 2; R <- 2; Ec <- 0.001; p <- 1/(m-1) C <- mat.or.vec(R,R) M <- length(X[,1]) mu <- mat.or.vec(M,R) #mu=matrix(,M,R) Q1=0;Q2=0; pl <- 1/(m-1) F=0; it <- 0; ph <- 1; repeat { #################### for (i in 1:M) { for (j in 1:R) { Q1=0;Q2=0;F=0 Q1 <- sum((X[i,]-Cold[j,])^2) for (k in 1:R) { Q2 <- sum((X[i,]-Cold[k,])^2) F=Q1/Q2+F } mu[i,j] <- solve(F) } } #################### ##########centre Update B=mat.or.vec(1,2); for (j in 1:R) { A=mat.or.vec(1,2); for (i in 1:M) { A=X[i,]*mu[i,j]^m+A #C=(t(mu)*X)/colSums(mu) } B=colSums(mu^m) C[j,] <- A/B[j]; } #########centre update end ph <- abs(sqrt(sum((C - Cold)^2))) Cold <- C ################## if(ph < Ec) { break; } it <- it+1 } ################## X plot(X[,1],X[,2],pch=5,lwd=6,col = "blue",cex = .6) for(i in 1:length(C[,1])) { points(C[i,1],C[i,2],pch=4,lwd=4) } library(MASS) w <- rep(1,nrow(X)) X <- cbind(w,X) X <- as.matrix(X) para <- mat.or.vec(3,R) #i<-0 h <- mat.or.vec(3,3) a <- mat.or.vec(3,3) b <- mat.or.vec(3,3) for(i in 1:R) #while (i<3) { h <- t(X)*(diag(mu[,i]))^2*X a <- solve(t(X)*(diag(mu[,i]))^2*X) b <- (t(X)*diag(mu[,i])^2) para[,i] <- a*b*y } ``` This is the code for clustering, it clusters the data and it works nice but it gives me >an error in the end part of calculating rule consequents, it is finally taking a toll on >me.It shows the error "Error in a * b * y : non-conformable arrays", Can anyone help me >please?