Skip to content

Instantly share code, notes, and snippets.

@even4void
Created August 25, 2010 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save even4void/549216 to your computer and use it in GitHub Desktop.
Save even4void/549216 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'statsample'
sample=200
a=sample.times.collect {rand}.to_scale
b=sample.times.collect {rand}.to_scale
c=sample.times.collect {rand}.to_scale
d=sample.times.collect {rand}.to_scale
ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
# Set the dependent variable
ds['y']=ds.collect{|row| row['a']*5+row['b']*3+row['c']*2+row['d']+rand()}
rb=ReportBuilder.new(:name=>"Example of Regression Analysis")
# Add a correlation matrix
cm=Statsample::Bivariate.correlation_matrix(ds)
rb.add(cm)
# Add a Linear Regression
lr=Statsample::Regression::Multiple::RubyEngine.new(ds,'y')
rb.add(lr)
puts rb.to_text
rb.save_rtf("dominance_analysis.rtf")
rb.save_html("dominance_analysis.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment