Class: Statsample::DominanceAnalysis::ModelData

Inherits:
Object
  • Object
show all
Defined in:
lib/statsample/dominanceanalysis.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(independent, data, da) ⇒ ModelData

Returns a new instance of ModelData.



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/statsample/dominanceanalysis.rb', line 364

def initialize(independent, data, da)
  @independent=independent
  @data=data
  @predictors=da.predictors
  @dependent=da.dependent
  @cases=da.cases
  @method=da.method_association
  @contributions=@independent.inject({}){|a,v| a[v]=nil;a}
  
  r_class=da.regression_class
  
  if @dependent.size==1
    @lr=r_class.new(data, @dependent[0], :cases=>@cases)
  else
    @lr=r_class.new(data, @dependent, :cases=>@cases)
  end
end

Instance Attribute Details

#contributionsObject (readonly)

Returns the value of attribute contributions.



363
364
365
# File 'lib/statsample/dominanceanalysis.rb', line 363

def contributions
  @contributions
end

Instance Method Details

#add_contribution(f, v) ⇒ Object



381
382
383
# File 'lib/statsample/dominanceanalysis.rb', line 381

def add_contribution(f, v)
  @contributions[f]=v-r2
end

#add_table_rowObject



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/statsample/dominanceanalysis.rb', line 392

def add_table_row
  if @cases
    sign=sprintf("%0.3f", @lr.probability)
		else
		sign="???"
  end

  [name, sprintf("%0.3f",r2), sign] + @predictors.collect{|k|
    v=@contributions[k]
    if v.nil?
        "--"
    else
    sprintf("%0.3f",v)
    end
  }
end

#nameObject



387
388
389
390
391
# File 'lib/statsample/dominanceanalysis.rb', line 387

def name
  @independent.collect {|variable|
    DominanceAnalysis.predictor_name(variable)
  }.join("*")
end

#r2Object



384
385
386
# File 'lib/statsample/dominanceanalysis.rb', line 384

def r2
  @lr.send(@method)
end

#summaryObject



408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/statsample/dominanceanalysis.rb', line 408

def summary
  out=sprintf("%s: r2=%0.3f(p=%0.2f)\n",name, r2, @lr.significance, @lr.sst)
  out << @predictors.collect{|k|
    v=@contributions[k]
    if v.nil?
        "--"
    else
      sprintf("%s=%0.3f",k,v)
    end
  }.join(" | ") 
  out << "\n"
  return out
end