Method: Statsample::Factor::ParallelAnalysis#compute
- Defined in:
- lib/statsample/factor/parallelanalysis.rb
#compute ⇒ Object
Perform calculation. Shouldn’t be called directly for the user
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/statsample/factor/parallelanalysis.rb', line 122 def compute @original=Statsample::Bivariate.send(matrix_method, @ds).eigenvalues unless no_data @ds_eigenvalues=Daru::DataFrame.new({}, order: (1..@n_variables).map{|v| ("ev_%05d" % v).to_sym}) if bootstrap_method==:parameter or bootstrap_method==:random rng = Distribution::Normal.rng end @iterations.times do |i| begin puts "#{@name}: Iteration #{i}" if $DEBUG or debug # Create a dataset of dummy values ds_bootstrap = Daru::DataFrame.new({}, order: @ds.vectors, index: @n_cases) @fields.each do |f| if bootstrap_method==:random ds_bootstrap[f] = Daru::Vector.new(@n_cases.times.map {|c| rng.call}) elsif bootstrap_method==:data ds_bootstrap[f] = ds[f].sample_with_replacement(@n_cases) else raise "bootstrap_method doesn't recogniced" end end matrix=Statsample::Bivariate.send(matrix_method, ds_bootstrap) matrix=matrix.to_gsl if @use_gsl if smc smc_v=matrix.inverse.diagonal.map{|ii| 1-(1.quo(ii))} smc_v.each_with_index do |v,ii| matrix[ii,ii]=v end end ev=matrix.eigenvalues @ds_eigenvalues.add_row(ev) rescue Statsample::Bivariate::Tetrachoric::RequerimentNotMeet => e puts "Error: #{e}" if $DEBUG redo end end end |