Class: Statsample::Reliability::MultiScaleAnalysis
- Includes:
- Summarizable
- Defined in:
- lib/statsample/reliability/multiscaleanalysis.rb
Overview
DSL for analysis of multiple scales analysis. Retrieves reliability analysis for each scale and provides fast accessors to correlations matrix, PCA and Factor Analysis.
Usage
@x1 = Daru::Vector.new([1,1,1,1,2,2,2,2,3,3,3,30])
@x2 = Daru::Vector.new([1,1,1,2,2,3,3,3,3,4,4,50])
@x3 = Daru::Vector.new([2,2,1,1,1,2,2,2,3,4,5,40])
@x4 = Daru::Vector.new([1,2,3,4,4,4,4,3,4,4,5,30])
ds = Daru::DataFrame.new({:x1 => @x1,:x2 => @x2,:x3 => @x3,:x4 => @x4})
opts={:name=>"Scales", # Name of analysis
:summary_correlation_matrix=>true, # Add correlation matrix
:summary_pca } # Add PCA between scales
msa=Statsample::Reliability::MultiScaleAnalysis.new(opts) do |m|
m.scale :s1, ds.clone([:x1, :x2])
m.scale :s2, ds.clone([:x3, :x4]), {:name=>"Scale 2"}
end
# Retrieve summary
puts msa.summary
Instance Attribute Summary collapse
-
#map_options ⇒ Object
Options for MAP.
-
#name ⇒ Object
Name of analysis.
-
#parallel_analysis_options ⇒ Object
Options for Parallel Analysis.
-
#pca_options ⇒ Object
Options for Factor::PCA object.
-
#principal_axis_options ⇒ Object
Options for Factor::PrincipalAxis.
-
#scales ⇒ Object
readonly
Hash with scales.
-
#summary_correlation_matrix ⇒ Object
Add a correlation matrix on summary.
-
#summary_map ⇒ Object
Add MPA to summary.
-
#summary_parallel_analysis ⇒ Object
Add Parallel Analysis to summary.
-
#summary_pca ⇒ Object
Add PCA to summary.
-
#summary_principal_axis ⇒ Object
Add Principal Axis to summary.
Instance Method Summary collapse
-
#correlation_matrix ⇒ Object
Retrieves a Correlation Matrix between scales.
- #dataset_from_scales ⇒ Object
-
#delete_scale(code) ⇒ Object
Delete ScaleAnalysis named
code
. -
#initialize(opts = Hash.new, &block) ⇒ MultiScaleAnalysis
constructor
Generates a new MultiScaleAnalysis Opts could be any accessor of the class * :name, * :summary_correlation_matrix * :summary_pca * :summary_principal_axis * :summary_map * :pca_options * :factor_analysis_options * :map_options If block given, all methods should be called inside object environment.
-
#map(opts = nil) ⇒ Object
Retrieve Velicer’s MAP using all scales.
- #parallel_analysis(opts = nil) ⇒ Object
-
#pca(opts = nil) ⇒ Object
Retrieves a Principal Component Analysis (Factor::PCA) using all scales, using
opts
a options. -
#principal_axis_analysis(opts = nil) ⇒ Object
Retrieves a PrincipalAxis Analysis (Factor::PrincipalAxis) using all scales, using
opts
a options. -
#report_building(b) ⇒ Object
:nodoc:.
-
#scale(code, ds = nil, opts = nil) ⇒ Object
Add or retrieve a scale to analysis.
Methods included from Summarizable
Constructor Details
#initialize(opts = Hash.new, &block) ⇒ MultiScaleAnalysis
Generates a new MultiScaleAnalysis Opts could be any accessor of the class
-
:name,
-
:summary_correlation_matrix
-
:summary_pca
-
:summary_principal_axis
-
:summary_map
-
:pca_options
-
:factor_analysis_options
-
:map_options
If block given, all methods should be called inside object environment.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 64 def initialize(opts=Hash.new, &block) @scales=Hash.new @scales_keys=Array.new opts_default={ :name=>_("Multiple Scale analysis"), :summary_correlation_matrix=>false, :summary_pca=>false, :summary_principal_axis=>false, :summary_parallel_analysis=>false, :summary_map=>false, :pca_options=>Hash.new, :principal_axis_options=>Hash.new, :parallel_analysis_options=>Hash.new, :map_options=>Hash.new } @opts=opts_default.merge(opts) @opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k } if block block.arity<1 ? instance_eval(&block) : block.call(self) end end |
Instance Attribute Details
#map_options ⇒ Object
Options for MAP
48 49 50 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 48 def @map_options end |
#name ⇒ Object
Name of analysis
28 29 30 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 28 def name @name end |
#parallel_analysis_options ⇒ Object
Options for Parallel Analysis
43 44 45 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 43 def @parallel_analysis_options end |
#pca_options ⇒ Object
Options for Factor::PCA object
36 37 38 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 36 def @pca_options end |
#principal_axis_options ⇒ Object
Options for Factor::PrincipalAxis
38 39 40 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 38 def @principal_axis_options end |
#scales ⇒ Object (readonly)
Hash with scales
26 27 28 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 26 def scales @scales end |
#summary_correlation_matrix ⇒ Object
Add a correlation matrix on summary
30 31 32 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 30 def summary_correlation_matrix @summary_correlation_matrix end |
#summary_map ⇒ Object
Add MPA to summary
46 47 48 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 46 def summary_map @summary_map end |
#summary_parallel_analysis ⇒ Object
Add Parallel Analysis to summary
41 42 43 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 41 def summary_parallel_analysis @summary_parallel_analysis end |
#summary_pca ⇒ Object
Add PCA to summary
32 33 34 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 32 def summary_pca @summary_pca end |
#summary_principal_axis ⇒ Object
Add Principal Axis to summary
34 35 36 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 34 def summary_principal_axis @summary_principal_axis end |
Instance Method Details
#correlation_matrix ⇒ Object
Retrieves a Correlation Matrix between scales.
140 141 142 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 140 def correlation_matrix Statsample::Bivariate.correlation_matrix(dataset_from_scales) end |
#dataset_from_scales ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 125 def dataset_from_scales ds = Daru::DataFrame.new({}, order: @scales_keys.map(&:to_sym)) @scales.each_pair do |code,scale| ds[code.to_sym] = scale.ds.vector_sum end ds end |
#delete_scale(code) ⇒ Object
Delete ScaleAnalysis named code
103 104 105 106 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 103 def delete_scale(code) @scales_keys.delete code @scales.delete code end |
#map(opts = nil) ⇒ Object
Retrieve Velicer’s MAP using all scales.
115 116 117 118 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 115 def map(opts=nil) opts||= Statsample::Factor::MAP.new(correlation_matrix, opts) end |
#parallel_analysis(opts = nil) ⇒ Object
134 135 136 137 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 134 def parallel_analysis(opts=nil) opts||= Statsample::Factor::ParallelAnalysis.new(dataset_from_scales, opts) end |
#pca(opts = nil) ⇒ Object
Retrieves a Principal Component Analysis (Factor::PCA) using all scales, using opts
a options.
109 110 111 112 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 109 def pca(opts=nil) opts ||= Statsample::Factor::PCA.new(correlation_matrix, opts) end |
#principal_axis_analysis(opts = nil) ⇒ Object
Retrieves a PrincipalAxis Analysis (Factor::PrincipalAxis) using all scales, using opts
a options.
121 122 123 124 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 121 def principal_axis_analysis(opts=nil) opts||= Statsample::Factor::PrincipalAxis.new(correlation_matrix, opts) end |
#report_building(b) ⇒ Object
:nodoc:
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 144 def report_building(b) # :nodoc: b.section(:name=>name) do |s| s.section(:name=>_("Reliability analysis of scales")) do |s2| @scales.each_pair do |k, scale| s2.parse_element(scale) end end if summary_correlation_matrix s.section(:name=>_("Correlation matrix for %s") % name) do |s2| s2.parse_element(correlation_matrix) end end if summary_pca s.section(:name=>_("PCA for %s") % name) do |s2| s2.parse_element(pca) end end if summary_principal_axis s.section(:name=>_("Principal Axis for %s") % name) do |s2| s2.parse_element(principal_axis_analysis) end end if summary_parallel_analysis s.section(:name=>_("Parallel Analysis for %s") % name) do |s2| s2.parse_element(parallel_analysis) end end if summary_map s.section(:name=>_("MAP for %s") % name) do |s2| s2.parse_element(map) end end end end |
#scale(code, ds = nil, opts = nil) ⇒ Object
Add or retrieve a scale to analysis. If second parameters is a dataset, generates a ScaleAnalysis for ds
, named code
with options opts
.
If second parameters is empty, returns the ScaleAnalysis code
.
93 94 95 96 97 98 99 100 101 |
# File 'lib/statsample/reliability/multiscaleanalysis.rb', line 93 def scale(code, ds=nil, opts=nil) if ds.nil? @scales[code] else opts={:name=>_("Scale %s") % code} if opts.nil? @scales_keys.push(code) @scales[code]=ScaleAnalysis.new(ds, opts) end end |