Class: Statsample::Regression::Multiple::AlglibEngine
- Inherits:
-
BaseEngine
show all
- Defined in:
- lib/statsample/regression/multiple/alglibengine.rb
Instance Attribute Summary
Attributes inherited from BaseEngine
#cases, #digits, #name, #total_cases, #valid_cases
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseEngine
#anova, #assign_names, #coeffs_se, #coeffs_t, #coeffs_tolerances, #constant_se, #constant_t, #df_e, #df_r, #estimated_variance_covariance_matrix, #f, #mse, #msr, #predicted, #probability, #r2_adjusted, #report_building, #residuals, #se_estimate, #se_r2, #sse, #sse_direct, #ssr, #ssr_direct, #standarized_predicted, #tolerance, univariate?
#summary
Constructor Details
#initialize(ds, y_var, opts = Hash.new) ⇒ AlglibEngine
Returns a new instance of AlglibEngine.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 20
def initialize(ds,y_var, opts=Hash.new)
super
@ds = ds.reject_values(*Daru::MISSING_VALUES)
@ds_valid = @ds
@dy = @ds[@y_var]
@ds_indep = ds.dup(ds.vectors.to_a - [y_var])
columns = []
@fields = []
@ds.vectors.each do |f|
if f != @y_var
columns.push(@ds[f].to_a)
@fields.push(f)
end
end
@dep_columns = columns.dup
columns.push(@ds[@y_var])
matrix=Matrix.columns(columns)
@lr_s=nil
@lr=::Alglib::LinearRegression.build_from_matrix(matrix)
@coeffs=assign_names(@lr.coeffs)
end
|
Class Method Details
._load(data) ⇒ Object
47
48
49
50
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 47
def self._load(data)
h=Marshal.load(data)
self.new(h['ds'], h['y_var'])
end
|
Instance Method Details
43
44
45
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 43
def _dump(i)
Marshal.dump({'ds'=>@ds,'y_var'=>@y_var})
end
|
#build_standarized ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 96
def build_standarized
@ds_s=@ds.standardize
columns=[]
@ds_s.vectors.each{|f|
columns.push(@ds_s[f].to_a) unless f == @y_var
}
@dep_columns_s=columns.dup
columns.push(@ds_s[@y_var])
matrix=Matrix.columns(columns)
@lr_s=Alglib::LinearRegression.build_from_matrix(matrix)
end
|
52
53
54
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 52
def coeffs
@coeffs
end
|
80
81
82
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 80
def constant
@lr.constant
end
|
89
90
91
92
93
94
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 89
def lr_s
if @lr_s.nil?
build_standarized
end
@lr_s
end
|
#matrix_resolution ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 57
def matrix_resolution
mse_p=mse
columns=@dep_columns.dup.map {|xi| xi.map{|i| i.to_f}}
columns.unshift([1.0]*@ds.cases)
y=Matrix.columns([@dy.data.map {|i| i.to_f}])
x=Matrix.columns(columns)
xt=x.t
matrix=((xt*x)).inverse*xt
matrix*y
end
|
#process(v) ⇒ Object
108
109
110
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 108
def process(v)
@lr.process(v)
end
|
#process_s(v) ⇒ Object
112
113
114
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 112
def process_s(v)
lr_s.process(v)
end
|
72
73
74
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 72
def r
Bivariate::pearson(@dy,predicted)
end
|
68
69
70
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 68
def r2
r**2
end
|
76
77
78
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 76
def sst
@dy.ss
end
|
#standarized_coeffs ⇒ Object
84
85
86
87
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 84
def standarized_coeffs
l=lr_s
assign_names(l.coeffs)
end
|
#standarized_residuals ⇒ Object
???? Not equal to SPSS output
116
117
118
119
120
|
# File 'lib/statsample/regression/multiple/alglibengine.rb', line 116
def standarized_residuals
res = residuals
red_sd = residuals.sds
Daru::Vector.new(res.collect {|v| v.quo(red_sd) })
end
|