% [lambda,V] = varimax(lambda[,sign,tol]) Varimax rotation % % Performs varimax rotation (Kaiser 1958) on the column vectors contained % in lambda. We follow Kaiser's notation. % % In: % lambda: DxL matrix (L tol*V(length(V)) V_old = V(length(V)); for i=1:L-1 for j=i+1:L % Optimal angle to rotate columns i, j x = lambda(:,i)./h; y = lambda(:,j)./h; u = x.*x - y.*y; v = 2*x.*y; t = atan2( 2*(D*u'*v-sum(u)*sum(v)), D*(u'*u-v'*v)-sum(u)^2+sum(v)^2 )/4; % Anticlockwise rotation of angle t (t+pi is valid, too) temp = [lambda(:,i) lambda(:,j)]*[cos(t) -sin(t); sin(t) cos(t)]; lambda(:,i) = temp(:,1); lambda(:,j) = temp(:,2); end end % New value of the objective function h = sqrt(sum(lambda'.^2))'+exp(-700); % Communalities temp=lambda./(h*ones(1,L)); V = [V sum(sum(temp.^4))-sum(sum(temp.^2).^2)/D]; % Objective function end % Sign inversion so that each column vector of lambda has mainly % components of the same sign if sign>0 for i=1:L if sum(lambda(:,i)) < 0 lambda(:,i) = -lambda(:,i); end end elseif sign<0 for i=1:L if sum(lambda(:,i)) > 0 lambda(:,i) = -lambda(:,i); end end end