Example of Dominance Analysis

This code

   1  #!/usr/bin/ruby
   2  require 'statsample'
   3  sample=200
   4  a=sample.times.collect {rand}.to_scale
   5  b=sample.times.collect {rand}.to_scale
   6  c=sample.times.collect {rand}.to_scale
   7  d=sample.times.collect {rand}.to_scale
   8  
   9  ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
  10  
  11  # Set the dependent variable
  12  
  13  ds['y']=ds.collect{|row| row['a']*5+row['b']*3+row['c']*2+row['d']+rand()}
  14  rb=ReportBuilder.new(:name=>"Example of Dominance Analysis")
  15  # Add a correlation matrix
  16  cm=Statsample::Bivariate.correlation_matrix(ds)
  17  rb.add(cm)
  18  # Add a Linear Regression
  19  lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
  20  rb.add(lr)
  21  # Add the dominance Analysis
  22  da=Statsample::DominanceAnalysis.new(ds,'y',:name=>"Dominance Analysis using group of predictors", :predictors=>['a', 'b', %w{c d}])
  23  rb.add(da)
  24  
  25  
  26  puts rb.to_text
  27  rb.save_rtf("dominance_analysis.rtf")
  28  rb.save_html("dominance_analysis.html")

Generates this output

Dominance Analysis
Correlation Matrix
+---+-------+-------+-------+-------+-------+
|   |   a   |   b   |   c   |   d   |   y   |
+---+-------+-------+-------+-------+-------+
| a | 1.000 | .082  | -.049 | .060  | .832  |
| b | .082  | 1.000 | -.075 | -.149 | .478  |
| c | -.049 | -.075 | 1.000 | -.004 | .235  |
| d | .060  | -.149 | -.004 | 1.000 | .133  |
| y | .832  | .478  | .235  | .133  | 1.000 |
+---+-------+-------+-------+-------+-------+

= Multiple Regression: Multiple reggresion of a,b,c,d on y
  Engine: Statsample::Regression::Multiple::RubyEngine
  Cases=200
  R=0.989
  R^2=0.978
  Equation=0.394 + 5.168a + 3.004b + 2.074c + 1.037d
  ANOVA
+------------+---------+-----+---------+----------+-------+
|   source   |   ss    | df  |   ms    |    f     |   s   |
+------------+---------+-----+---------+----------+-------+
| Regression | 705.539 | 4   | 176.385 | 2201.599 | 0.000 |
| Error      | 15.623  | 195 | 0.080   |          |       |
| Total      | 721.162 | 199 |         |          |       |
+------------+---------+-----+---------+----------+-------+

  Beta coefficients
+----------+-------+-------+-------+--------+
|  coeff   |   b   | beta  |  se   |   t    |
+----------+-------+-------+-------+--------+
| Constant | 0.394 | -     | 0.075 | 5.243  |
| a        | 5.168 | 0.800 | 0.069 | 75.402 |
| b        | 3.004 | 0.459 | 0.070 | 42.744 |
| c        | 2.074 | 0.309 | 0.071 | 29.227 |
| d        | 1.037 | 0.155 | 0.072 | 14.499 |
+----------+-------+-------+-------+--------+

= Dominance Analysis using group of predictors
  Dominance Analysis result
+------------------+-------+-------+-------+-------+-------+
|                  |  r2   | sign  |   a   |   b   | (c,d) |
+------------------+-------+-------+-------+-------+-------+
| Model 0          |       |       | 0.692 | 0.229 | 0.073 |
+------------------+-------+-------+-------+-------+-------+
| a                | 0.692 | 0.000 | --    | 0.169 | 0.083 |
| b                | 0.229 | 0.000 | 0.633 | --    | 0.118 |
| (c,d)            | 0.073 | 0.001 | 0.702 | 0.274 | --    |
+------------------+-------+-------+-------+-------+-------+
| k=1 Average      |       |       | 0.667 | 0.221 | 0.101 |
+------------------+-------+-------+-------+-------+-------+
| a*b              | 0.861 | 0.000 | --    | --    | 0.117 |
| a*(c,d)          | 0.775 | 0.000 | --    | 0.203 | --    |
| b*(c,d)          | 0.347 | 0.000 | 0.632 | --    | --    |
+------------------+-------+-------+-------+-------+-------+
| k=2 Average      |       |       | 0.632 | 0.203 | 0.117 |
+------------------+-------+-------+-------+-------+-------+
| a*b*(c,d)        | 0.978 | 0.000 | --    | --    | --    |
+------------------+-------+-------+-------+-------+-------+
| Overall averages |       |       | 0.664 | 0.218 | 0.097 |
+------------------+-------+-------+-------+-------+-------+

  Pairwise dominance
+-----------+-------+-------------+---------+
|   Pairs   | Total | Conditional | General |
+-----------+-------+-------------+---------+
| a - b     | 1.0   | 1.0         | 1.0     |
| a - c - d | 1.0   | 1.0         | 1.0     |
| b - c - d | 1.0   | 1.0         | 1.0     |
+-----------+-------+-------------+---------+

And save two files