Sha256: d833cd9d3d1c55a54375fc81d5bbd401ce94c74e65d061e6568df5065bea7162

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

#!/usr/bin/ruby
$:.unshift(File.dirname(__FILE__)+'/../lib/')

require 'statsample'
samples=100
variables=30
iterations=50
rng = GSL::Rng.alloc()
f1=samples.times.collect {rng.ugaussian()}.to_scale
f2=samples.times.collect {rng.ugaussian()}.to_scale
f3=samples.times.collect {rng.ugaussian()}.to_scale

vectors={}

variables.times do |i|
  vectors["v#{i}"]=samples.times.collect {|nv| f1[nv]*i+(f2[nv]*(15-i))+((f3[nv]*(30-i))*1.5)*rng.ugaussian()}.to_scale
  vectors["v#{i}"].name="Vector #{i}"
end
ds=vectors.to_dataset

pa=Statsample::Factor::ParallelAnalysis.new(ds, :iterations=>iterations, :debug=>true)
pca=Statsample::Factor::PCA.new(Statsample::Bivariate.correlation_matrix(ds))
rb=ReportBuilder.new(:name=>"Parallel Analysis with simulation") do
  text "There are 3 real factors on data"
  parse_element pca
  text "Traditional Kaiser criterion (k>1) returns #{pca.m} factors"
  parse_element pa
  text "Parallel Analysis returns #{pa.number_of_factors} factors to preserve"
end

puts rb.to_text

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statsample-0.18.0 examples/parallel_analysis.rb
statsample-0.17.0 examples/parallel_analysis.rb
statsample-0.16.0 examples/parallel_analysis.rb