lib/statsample/factor/principalaxis.rb in statsample-0.14.0 vs lib/statsample/factor/principalaxis.rb in statsample-0.14.1

- old
+ new

@@ -122,21 +122,22 @@ pca=PCA.new(::Matrix.rows(work_matrix)) @initial_eigenvalues=pca.eigenvalues prev_sum=prev_com.inject(0) {|ac,v| ac+v} @iterations=0 t.times do |i| + "#{@name}: Iteration #{i}" if $DEBUG @iterations+=1 prev_com.each_with_index{|v,it| work_matrix[it][it]=v } pca=PCA.new(::Matrix.rows(work_matrix)) @communalities=pca.communalities(m) @eigenvalues=pca.eigenvalues com_sum = @communalities.inject(0) {|ac,v| ac+v} jump=true - break if (com_sum-prev_sum).abs<@delta + break if (com_sum-prev_sum).abs < @delta @communalities.each_with_index do |v2,i2| raise "Variable #{i2} with communality > 1" if v2>1.0 end prev_sum=com_sum prev_com=@communalities @@ -151,15 +152,20 @@ end alias :compute :iterate def initial_communalities if @initial_communalities.nil? + if @smc + # Based on O'Connors(2000) + @initial_communalities=@matrix.inverse.diagonal.map{|i| 1-(1.quo(i))} +=begin @initial_communalities=@matrix.column_size.times.collect {|i| rxx , rxy = PrincipalAxis.separate_matrices(@matrix,i) matrix=(rxy.t*rxx.inverse*rxy) matrix[0,0] } +=end else @initial_communalities=[1.0]*@matrix.column_size end end @initial_communalities