statsample 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data.tar.gz.sig +2 -1
  2. data/History.txt +11 -0
  3. data/Manifest.txt +2 -3
  4. data/README.txt +0 -17
  5. data/Rakefile +10 -9
  6. data/data/locale/es/LC_MESSAGES/statsample.mo +0 -0
  7. data/examples/principal_axis.rb +2 -0
  8. data/examples/u_test.rb +8 -0
  9. data/lib/distribution.rb +1 -1
  10. data/lib/statsample.rb +12 -12
  11. data/lib/statsample/anova/oneway.rb +4 -4
  12. data/lib/statsample/bivariate.rb +10 -3
  13. data/lib/statsample/bivariate/pearson.rb +55 -0
  14. data/lib/statsample/dataset.rb +57 -49
  15. data/lib/statsample/dominanceanalysis.rb +1 -2
  16. data/lib/statsample/dominanceanalysis/bootstrap.rb +46 -54
  17. data/lib/statsample/factor.rb +0 -1
  18. data/lib/statsample/factor/parallelanalysis.rb +9 -13
  19. data/lib/statsample/factor/pca.rb +5 -10
  20. data/lib/statsample/factor/principalaxis.rb +27 -33
  21. data/lib/statsample/matrix.rb +11 -11
  22. data/lib/statsample/mle.rb +0 -1
  23. data/lib/statsample/regression.rb +0 -1
  24. data/lib/statsample/reliability.rb +2 -2
  25. data/lib/statsample/reliability/multiscaleanalysis.rb +62 -15
  26. data/lib/statsample/reliability/scaleanalysis.rb +5 -6
  27. data/lib/statsample/test/f.rb +2 -5
  28. data/lib/statsample/test/levene.rb +2 -5
  29. data/lib/statsample/test/t.rb +4 -13
  30. data/lib/statsample/test/umannwhitney.rb +19 -19
  31. data/po/es/statsample.mo +0 -0
  32. data/po/es/statsample.po +304 -111
  33. data/po/statsample.pot +224 -90
  34. data/test/test_bivariate.rb +8 -69
  35. data/test/test_reliability.rb +3 -4
  36. metadata +30 -18
  37. metadata.gz.sig +0 -0
  38. data/lib/statsample/bivariate/polychoric.rb +0 -893
  39. data/lib/statsample/bivariate/tetrachoric.rb +0 -457
  40. data/test/test_bivariate_polychoric.rb +0 -70
@@ -1,4 +1,3 @@
1
-
2
1
  module Statsample
3
2
  # Dominance Analysis is a procedure based on an examination of the R<sup>2</sup> values
4
3
  # for all possible subset models, to identify the relevance of one or more
@@ -57,7 +56,7 @@ module Statsample
57
56
  # * Azen, R. & Budescu, D.V. (2006). Comparing predictors in Multivariate Regression Models: An extension of Dominance Analysis. <em>Journal of Educational and Behavioral Statistics, 31</em>(2), 157-180.
58
57
  #
59
58
  class DominanceAnalysis
60
- include Summarizable
59
+ include Summarizable
61
60
  # Class to generate the regressions. Default to Statsample::Regression::Multiple::MatrixEngine
62
61
  attr_accessor :regression_class
63
62
  # Name of analysis
@@ -66,9 +66,8 @@ module Statsample
66
66
  #
67
67
  # * Azen, R. & Budescu, D.V. (2003). The dominance analysis approach for comparing predictors in multiple regression. <em>Psychological Methods, 8</em>(2), 129-148.
68
68
  class Bootstrap
69
- include GetText
70
69
  include Writable
71
- bindtextdomain("statsample")
70
+ include Summarizable
72
71
  # Total Dominance results
73
72
  attr_reader :samples_td
74
73
  # Conditional Dominance results
@@ -169,68 +168,61 @@ module Statsample
169
168
  }
170
169
  end
171
170
  end
172
- # Summary of analysis
173
- def summary
174
- rp=ReportBuilder.new().add(self).to_text
175
- end
176
-
177
171
  def t
178
172
  Distribution::T.p_value(1-((1-@alpha) / 2), @n_samples - 1)
179
173
  end
180
- def report_building(generator) # :nodoc:
174
+ def report_building(builder) # :nodoc:
181
175
  raise "You should bootstrap first" if @n_samples==0
182
- anchor=generator.toc_entry(_("DAB: ")+@name)
183
- generator.html "<div class='dominance-analysis-bootstrap'>#{@name}<a name='#{anchor}'></a>"
184
-
185
- generator.text _("Sample size: %d\n") % @n_samples
186
- generator.text "t: #{t}\n"
187
- generator.text _("Linear Regression Engine: %s") % @regression_class.name
188
-
189
- table=ReportBuilder::Table.new(:name=>"Bootstrap report", :header => [_("pairs"), "sD","Dij", _("SE(Dij)"), "Pij", "Pji", "Pno", _("Reproducibility")])
190
- table.row([_("Complete dominance")])
191
- table.hr
192
- @pairs.each{|pair|
193
- std=@samples_td[pair].to_vector(:scale)
194
- ttd=da.total_dominance_pairwise(pair[0],pair[1])
195
- table.row(summary_pairs(pair,std,ttd))
196
- }
197
- table.hr
198
- table.row([_("Conditional dominance")])
199
- table.hr
200
- @pairs.each{|pair|
201
- std=@samples_cd[pair].to_vector(:scale)
202
- ttd=da.conditional_dominance_pairwise(pair[0],pair[1])
203
- table.row(summary_pairs(pair,std,ttd))
204
-
205
- }
206
- table.hr
207
- table.row([_("General Dominance")])
208
- table.hr
209
- @pairs.each{|pair|
210
- std=@samples_gd[pair].to_vector(:scale)
211
- ttd=da.general_dominance_pairwise(pair[0],pair[1])
212
- table.row(summary_pairs(pair,std,ttd))
213
- }
214
- generator.parse_element(table)
215
-
216
- table=ReportBuilder::Table.new(:name=>_("General averages"), :header=>[_("var"), _("mean"), _("se"), _("p.5"), _("p.95")])
217
-
218
- @fields.each{|f|
219
- v=@samples_ga[f].to_vector(:scale)
220
- row=[@ds.label(f), sprintf("%0.3f",v.mean), sprintf("%0.3f",v.sd), sprintf("%0.3f",v.percentil(5)),sprintf("%0.3f",v.percentil(95))]
221
- table.row(row)
222
-
223
- }
224
-
225
- generator.parse_element(table)
226
- generator.html("</div>")
176
+ builder.section(:name=>@name) do |generator|
177
+ generator.text _("Sample size: %d\n") % @n_samples
178
+ generator.text "t: #{t}\n"
179
+ generator.text _("Linear Regression Engine: %s") % @regression_class.name
180
+
181
+ table=ReportBuilder::Table.new(:name=>"Bootstrap report", :header => [_("pairs"), "sD","Dij", _("SE(Dij)"), "Pij", "Pji", "Pno", _("Reproducibility")])
182
+ table.row([_("Complete dominance"),"","","","","","",""])
183
+ table.hr
184
+ @pairs.each{|pair|
185
+ std=@samples_td[pair].to_vector(:scale)
186
+ ttd=da.total_dominance_pairwise(pair[0],pair[1])
187
+ table.row(summary_pairs(pair,std,ttd))
188
+ }
189
+ table.hr
190
+ table.row([_("Conditional dominance"),"","","","","","",""])
191
+ table.hr
192
+ @pairs.each{|pair|
193
+ std=@samples_cd[pair].to_vector(:scale)
194
+ ttd=da.conditional_dominance_pairwise(pair[0],pair[1])
195
+ table.row(summary_pairs(pair,std,ttd))
196
+
197
+ }
198
+ table.hr
199
+ table.row([_("General Dominance"),"","","","","","",""])
200
+ table.hr
201
+ @pairs.each{|pair|
202
+ std=@samples_gd[pair].to_vector(:scale)
203
+ ttd=da.general_dominance_pairwise(pair[0],pair[1])
204
+ table.row(summary_pairs(pair,std,ttd))
205
+ }
206
+ generator.parse_element(table)
207
+
208
+ table=ReportBuilder::Table.new(:name=>_("General averages"), :header=>[_("var"), _("mean"), _("se"), _("p.5"), _("p.95")])
209
+
210
+ @fields.each{|f|
211
+ v=@samples_ga[f].to_vector(:scale)
212
+ row=[@ds[f].name, sprintf("%0.3f",v.mean), sprintf("%0.3f",v.sd), sprintf("%0.3f",v.percentil(5)),sprintf("%0.3f",v.percentil(95))]
213
+ table.row(row)
214
+
215
+ }
216
+
217
+ generator.parse_element(table)
218
+ end
227
219
  end
228
220
  def summary_pairs(pair,std,ttd)
229
221
  freqs=std.proportions
230
222
  [0, 0.5, 1].each{|n|
231
223
  freqs[n]=0 if freqs[n].nil?
232
224
  }
233
- name=@ds.label(pair[0])+" - "+@ds.label(pair[1])
225
+ name="%s - %s" % [@ds[pair[0]].name, @ds[pair[1]].name]
234
226
  [name,f(ttd,1),f(std.mean,4),f(std.sd),f(freqs[1]), f(freqs[0]), f(freqs[0.5]), f(freqs[ttd])]
235
227
  end
236
228
  def f(v,n=3)
@@ -11,7 +11,6 @@ module Statsample
11
11
  # * Statsample::Factor::Varimax
12
12
  # * Statsample::Factor::Equimax
13
13
  # * Statsample::Factor::Quartimax
14
- #
15
14
  # See documentation of each class to use it
16
15
  module Factor
17
16
  end
@@ -15,7 +15,7 @@ module Factor
15
15
  class ParallelAnalysis
16
16
 
17
17
  include DirtyMemoize
18
-
18
+ include Summarizable
19
19
  # Number of random sets to produce. 50 by default
20
20
  attr_accessor :iterations
21
21
  # Name of analysis
@@ -47,7 +47,7 @@ class ParallelAnalysis
47
47
  @n_variables=@fields.size
48
48
  @n_cases=ds.cases
49
49
  opts_default={
50
- :name=>"Parallel Analysis",
50
+ :name=>_("Parallel Analysis"),
51
51
  :iterations=>50,
52
52
  :bootstrap_method => :raw_data,
53
53
  :factor_class => Statsample::Factor::PCA,
@@ -59,10 +59,6 @@ class ParallelAnalysis
59
59
  @opts[:matrix_method]==:correlation_matrix if @opts[:bootstrap_method]==:parameters
60
60
  opts_default.keys.each {|k| send("#{k}=", @opts[k]) }
61
61
  end
62
- # Summary of results
63
- def summary
64
- ReportBuilder.new(:no_title=>true).add(self).to_text
65
- end
66
62
  # Number of factor to retent
67
63
  def number_of_factors
68
64
  total=0
@@ -73,13 +69,13 @@ class ParallelAnalysis
73
69
  end
74
70
  def report_building(g) #:nodoc:
75
71
  g.section(:name=>@name) do |s|
76
- s.text "Bootstrap Method: #{bootstrap_method}"
77
- s.text "Correlation Matrix type : #{matrix_method}"
78
- s.text "Number of variables: #{@n_variables}"
79
- s.text "Number of cases: #{@n_cases}"
80
- s.text "Number of iterations: #{@iterations}"
81
- s.text "Number or factors to preserve: #{number_of_factors}"
82
- s.table(:name=>"Eigenvalues", :header=>["Eigenvalue", "actual", "mean","p.#{percentil}","preserve?"]) do |t|
72
+ s.text _("Bootstrap Method: %s") % bootstrap_method
73
+ s.text _("Correlation Matrix type : %s") % matrix_method
74
+ s.text _("Number of variables: %d") % @n_variables
75
+ s.text _("Number of cases: %d") % @n_cases
76
+ s.text _("Number of iterations: %d") % @iterations
77
+ s.text _("Number or factors to preserve: %d") % number_of_factors
78
+ s.table(:name=>_("Eigenvalues"), :header=>[_("Eigenvalue"), _("actual"), _("mean"),"p.#{percentil}",_("preserve?")]) do |t|
83
79
  ds_eigenvalues.fields.each_with_index do |f,i|
84
80
  v=ds_eigenvalues[f]
85
81
  t.row [i+1, "%0.4f" % @original[i], "%0.4f" % v.mean, "%0.4f" % v.percentil(percentil), (v.percentil(percentil)>0 and @original[i] > v.percentil(percentil)) ? "Yes":""]
@@ -36,8 +36,7 @@ module Factor
36
36
  attr_accessor :m
37
37
  # Use GSL if available
38
38
  attr_accessor :use_gsl
39
- include GetText
40
- bindtextdomain("statsample")
39
+ include Summarizable
41
40
 
42
41
  def initialize(matrix, opts=Hash.new)
43
42
  @use_gsl=nil
@@ -139,25 +138,21 @@ module Factor
139
138
  @eigenpairs=@eigenpairs.sort.reverse
140
139
  end
141
140
 
142
- def summary
143
- ReportBuilder.new(:no_title=>true).add(self).to_text
144
- end
145
141
  def report_building(builder) # :nodoc:
146
142
  builder.section(:name=>@name) do |generator|
147
- generator.text "Number of factors: #{m}"
148
- generator.table(:name=>_("Communalities"), :header=>["Variable","Initial","Extraction"]) do |t|
143
+ generator.text _("Number of factors: %d") % m
144
+ generator.table(:name=>_("Communalities"), :header=>[_("Variable"),_("Initial"),_("Extraction")]) do |t|
149
145
  communalities(m).each_with_index {|com,i|
150
146
  t.row([i, 1.0, sprintf("%0.3f", com)])
151
147
  }
152
148
  end
153
- generator.table(:name=>_("Eigenvalues"), :header=>["Variable","Value"]) do |t|
149
+ generator.table(:name=>_("Eigenvalues"), :header=>[_("Variable"),_("Value")]) do |t|
154
150
  eigenvalues.each_with_index {|eigenvalue,i|
155
151
  t.row([i, sprintf("%0.3f",eigenvalue)])
156
152
  }
157
153
  end
158
154
 
159
- generator.table(:name=>_("Component Matrix"), :header=>["Variable"]+m.times.collect {|c| c+1}) do |t|
160
-
155
+ generator.table(:name=>_("Component Matrix"), :header=>[_("Variable")]+m.times.collect {|c| c+1}) do |t|
161
156
  i=0
162
157
  component_matrix(m).to_a.each do |row|
163
158
  t.row([i]+row.collect {|c| sprintf("%0.3f",c)})
@@ -28,12 +28,11 @@ module Factor
28
28
  #
29
29
  class PrincipalAxis
30
30
  include DirtyMemoize
31
+ include Summarizable
31
32
  # Minimum difference between succesive iterations on sum of communalities
32
33
  DELTA=1e-3
33
34
  # Maximum number of iterations
34
35
  MAX_ITERATIONS=50
35
- include GetText
36
- bindtextdomain("statsample")
37
36
  # Number of factors. Set by default to the number of factors
38
37
  # with eigen values > 1 on PCA over data
39
38
  attr_accessor :m
@@ -58,6 +57,12 @@ module Factor
58
57
 
59
58
  def initialize(matrix, opts=Hash.new)
60
59
  @matrix=matrix
60
+ if @matrix.respond_to? :fields
61
+ @fields=@matrix.fields
62
+ else
63
+ @fields=@matrix.row_size.times.map {|i| _("Variable %d") % (i+1)}
64
+ end
65
+
61
66
  @name=""
62
67
  @m=nil
63
68
  @initial_eigenvalues=nil
@@ -167,40 +172,29 @@ module Factor
167
172
  rxx=Matrix.rows(rows)
168
173
  [rxx,rxy]
169
174
  end
170
- def summary
171
- rp=ReportBuilder.new()
172
- rp.add(self)
173
- rp.to_text
174
- end
175
175
  def report_building(generator)
176
176
  iterate if @clean
177
- anchor=generator.toc_entry(_("Factor Analysis: ")+name)
178
- generator.html "<div class='pca'>"+_("Factor Analysis")+" #{@name}<a name='#{anchor}'></a>"
179
-
180
- generator.text "Number of factors: #{m}"
181
- generator.text "Iterations: #{@iterations}"
182
-
183
- t=ReportBuilder::Table.new(:name=>_("Communalities"), :header=>["Variable","Initial","Extraction"])
184
- communalities(m).each_with_index {|com,i|
185
- t.row([i, sprintf("%0.4f", initial_communalities[i]), sprintf("%0.3f", com)])
186
- }
187
- generator.parse_element(t)
188
-
189
- t=ReportBuilder::Table.new(:name=>_("Eigenvalues"), :header=>["Variable","Value"])
190
- @initial_eigenvalues.each_with_index {|eigenvalue,i|
191
- t.row([i, sprintf("%0.3f",eigenvalue)])
192
- }
193
- generator.parse_element(t)
194
-
195
- t=ReportBuilder::Table.new(:name=>_("Component Matrix"), :header=>["Variable"]+m.times.collect {|c| c+1})
196
-
197
- i=0
198
- component_matrix(m).to_a.each do |row|
199
- t.row([i]+row.collect {|c| sprintf("%0.3f",c)})
200
- i+=1
177
+ generator.section(:name=>@name) do |s|
178
+ s.text _("Number of factors: %d") % m
179
+ s.text _("Iterations: %d") % @iterations
180
+ s.table(:name=>_("Communalities"), :header=>[_("Variable"),_("Initial"),_("Extraction")]) do |t|
181
+ communalities(m).each_with_index {|com,i|
182
+ t.row([@fields[i], sprintf("%0.4f", initial_communalities[i]), sprintf("%0.3f", com)])
183
+ }
184
+ end
185
+ s.table(:name=>_("Eigenvalues"), :header=>[_("Variable"),_("Value")]) do |t|
186
+ @initial_eigenvalues.each_with_index {|eigenvalue,i|
187
+ t.row([@fields[i], sprintf("%0.3f",eigenvalue)])
188
+ }
189
+ end
190
+ s.table(:name=>_("Component Matrix"), :header=>["Variable"]+m.times.collect {|c| c+1}) do |t|
191
+ i=0
192
+ component_matrix(m).to_a.each do |row|
193
+ t.row([@fields[i]]+row.collect {|c| sprintf("%0.3f",c)})
194
+ i+=1
195
+ end
196
+ end
201
197
  end
202
- generator.parse_element(t)
203
- generator.html("</div>")
204
198
  end
205
199
 
206
200
  dirty_writer :max_iterations, :epsilon, :smc
@@ -37,12 +37,8 @@ module Statsample
37
37
  #
38
38
  module CovariateMatrix
39
39
  include Summarizable
40
- # Gives a nice summary
41
- def summary
42
- rp=ReportBuilder.new()
43
- rp.add(self)
44
- rp.to_text
45
- end
40
+ @@covariatematrix=0
41
+
46
42
  # Get type of covariate matrix. Could be :covariance or :correlation
47
43
  def type
48
44
  if row_size==column_size
@@ -81,7 +77,7 @@ module Statsample
81
77
  end
82
78
  def fields
83
79
  raise "Should be square" if !square?
84
- @fields_x
80
+ fields_x
85
81
  end
86
82
  def fields=(v)
87
83
  raise "Matrix should be square" if !square?
@@ -97,17 +93,21 @@ module Statsample
97
93
  @fields_y=v
98
94
  end
99
95
  def fields_x
100
- @fields_x||=row_size.times.collect {|i| i}
96
+ @fields_x||=row_size.times.collect {|i| _("X%d") % i}
101
97
  end
102
98
  def fields_y
103
- @fields_y||=column_size.times.collect {|i| i}
99
+ @fields_y||=column_size.times.collect {|i| _("Y%d") % i}
104
100
  end
105
101
 
106
102
  def name=(v)
107
103
  @name=v
108
104
  end
109
105
  def name
110
- @name
106
+ @name||=get_new_name
107
+ end
108
+ def get_new_name
109
+ @@covariatematrix+=1
110
+ _("Covariate matrix %d") % @@covariatematrix
111
111
  end
112
112
  # Select a submatrix of factors. If you have a correlation matrix
113
113
  # with a, b and c, you could obtain a submatrix of correlations of
@@ -149,7 +149,7 @@ module Statsample
149
149
  matrix
150
150
  end
151
151
  def report_building(generator)
152
- @name||= (type==:correlation ? "Correlation":"Covariance")+" Matrix"
152
+ @name||= (type==:correlation ? _("Correlation"):_("Covariance"))+_(" Matrix")
153
153
  generator.table(:name=>@name, :header=>[""]+fields_y) do |t|
154
154
  row_size.times {|i|
155
155
  t.row([fields_x[i]]+@rows[i].collect {|i1| sprintf("%0.3f",i1).gsub("0.",".")})
@@ -134,7 +134,6 @@ module Statsample
134
134
  end
135
135
  end
136
136
  end
137
-
138
137
  require 'statsample/mle/normal'
139
138
  require 'statsample/mle/logit'
140
139
  require 'statsample/mle/probit'
@@ -35,7 +35,6 @@ module Statsample
35
35
  # => 1.99973746599856
36
36
  # sr.r
37
37
  # => 0.999987881153254
38
-
39
38
  def self.simple(x,y)
40
39
  Statsample::Regression::Simple.new_from_vectors(x,y)
41
40
  end
@@ -108,7 +108,7 @@ module Statsample
108
108
  out
109
109
  end # def
110
110
  end # self
111
- end # Reliability
112
- end # Statsample
111
+ end # Reliability
112
+ end # Statsample
113
113
  require 'statsample/reliability/scaleanalysis.rb'
114
114
  require 'statsample/reliability/multiscaleanalysis.rb'
@@ -1,33 +1,62 @@
1
1
  module Statsample
2
2
  module Reliability
3
- # DSL for analysis of multiple scales analysis. Analoge of Scale Reliability analysis on SPSS.
4
- # Returns several statistics for complete scale and each item
3
+ # DSL for analysis of multiple scales analysis.
4
+ # Retrieves reliability analysis for each scale and
5
+ # provides fast accessors to correlations matrix,
6
+ # PCA and Factor Analysis.
7
+ #
5
8
  # == Usage
6
9
  # @x1=[1,1,1,1,2,2,2,2,3,3,3,30].to_vector(:scale)
7
10
  # @x2=[1,1,1,2,2,3,3,3,3,4,4,50].to_vector(:scale)
8
11
  # @x3=[2,2,1,1,1,2,2,2,3,4,5,40].to_vector(:scale)
9
12
  # @x4=[1,2,3,4,4,4,4,3,4,4,5,30].to_vector(:scale)
10
13
  # ds={'x1'=>@x1,'x2'=>@x2,'x3'=>@x3,'x4'=>@x4}.to_dataset
11
- # msa=Statsample::Reliability::MultiScaleAnalysis.new(:name=>"Scales") do |m|
12
- # m.scale :s1, "Section 1", ds.clone(%w{x1 x2})
13
- # m.scale :s2, "Section 2", ds.clone(%w{x3 x4})
14
- # m.correlation_matrix
15
- # m.factor_analysis
14
+ # opts={:name=>"Scales", # Name of analysis
15
+ # :summary_correlation_matrix=>true, # Add correlation matrix
16
+ # :summary_pca } # Add PCA between scales
17
+ # msa=Statsample::Reliability::MultiScaleAnalysis.new(opts) do |m|
18
+ # m.scale :s1, ds.clone(%w{x1 x2})
19
+ # m.scale :s2, ds.clone(%w{x3 x4}), {:name=>"Scale 2"}
16
20
  # end
17
- # puts msa.summary
21
+ # # Retrieve summary
22
+ # puts msa.summary
18
23
  class MultiScaleAnalysis
19
24
  include Statsample::Summarizable
25
+ # Hash with scales
20
26
  attr_reader :scales
27
+ # Name of analysis
21
28
  attr_accessor :name
29
+ # Add a correlation matrix on summary
22
30
  attr_accessor :summary_correlation_matrix
31
+ # Add PCA to summary
23
32
  attr_accessor :summary_pca
33
+ # Add Principal Axis to summary
34
+ attr_accessor :summary_principal_axis
35
+ # Options for Factor::PCA object
24
36
  attr_accessor :pca_options
37
+ # Options for Factor::PrincipalAxis
38
+ attr_accessor :principal_axis_options
39
+ # Generates a new MultiScaleAnalysis
40
+ # Opts could be any accessor of the class
41
+ # * :name,
42
+ # * :summary_correlation_matrix
43
+ # * :summary_pca
44
+ # * :summary_principal_axis
45
+ # * :pca_options
46
+ # * :factor_analysis_options
47
+ #
48
+ # If block given, all methods should be called
49
+ # inside object environment.
50
+ #
25
51
  def initialize(opts=Hash.new, &block)
26
52
  @scales=Hash.new
27
53
  opts_default={ :name=>_("Multiple Scale analysis"),
28
54
  :summary_correlation_matrix=>false,
29
55
  :summary_pca=>false,
30
- :pca_options=>Hash.new}
56
+ :summary_principal_axis=>false,
57
+ :pca_options=>Hash.new,
58
+ :principal_axis_options=>Hash.new
59
+ }
31
60
  @opts=opts_default.merge(opts)
32
61
  @opts.each{|k,v|
33
62
  self.send("#{k}=",v) if self.respond_to? k
@@ -37,6 +66,12 @@ module Statsample
37
66
  block.arity<1 ? instance_eval(&block) : block.call(self)
38
67
  end
39
68
  end
69
+ # Add or retrieve a scale to analysis.
70
+ # If second parameters is a dataset, generates a ScaleAnalysis
71
+ # for <tt>ds</tt>, named <tt>code</tt> with options <tt>opts</tt>.
72
+ #
73
+ # If second parameters is empty, returns the ScaleAnalysis
74
+ # <tt>code</tt>.
40
75
  def scale(code,ds=nil, opts=nil)
41
76
  if ds.nil?
42
77
  @scales[code]
@@ -45,17 +80,24 @@ module Statsample
45
80
  @scales[code]=ScaleAnalysis.new(ds, opts)
46
81
  end
47
82
  end
83
+ # Delete ScaleAnalysis named <tt>code</tt>
48
84
  def delete_scale(code)
49
85
  @scales.delete code
50
86
  end
51
- def pca(opts=Hash.new)
87
+ # Retrieves a Principal Component Analysis (Factor::PCA)
88
+ # using all scales, using <tt>opts</tt> a options.
89
+ def pca(opts=nil)
90
+ opts||=pca_options
52
91
  Statsample::Factor::PCA.new(correlation_matrix,opts)
53
92
  end
54
- def factor_analysis(opts=nil)
55
- opts||=pca_options
56
- Statsample::Factor::FactorAnalysis.new(correlation_matrix,opts)
93
+ # Retrieves a PrincipalAxis Analysis (Factor::PrincipalAxis)
94
+ # using all scales, using <tt>opts</tt> a options.
95
+ def principal_axis_analysis(opts=nil)
96
+ opts||=principal_axis_options
97
+ Statsample::Factor::PrincipalAxis.new(correlation_matrix,opts)
57
98
  end
58
-
99
+ # Retrieves a Correlation Matrix between scales.
100
+ #
59
101
  def correlation_matrix
60
102
  vectors=Hash.new
61
103
  @scales.each_pair do |code,scale|
@@ -63,7 +105,7 @@ module Statsample
63
105
  end
64
106
  Statsample::Bivariate.correlation_matrix(vectors.to_dataset)
65
107
  end
66
- def report_building(b)
108
+ def report_building(b) # :nodoc:
67
109
  b.section(:name=>name) do |s|
68
110
  s.section(:name=>_("Reliability analysis of scales")) do |s2|
69
111
  @scales.each_pair do |k,scale|
@@ -80,6 +122,11 @@ module Statsample
80
122
  s2.parse_element(pca)
81
123
  end
82
124
  end
125
+ if summary_principal_axis
126
+ s.section(:name=>_("Principal Axis for %s") % name) do |s2|
127
+ s2.parse_element(principal_axis_analysis)
128
+ end
129
+ end
83
130
  end
84
131
  end
85
132
  end