From e41dbe71ace848d3cbc389b757924e45eb614e35 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Mon, 9 May 2016 08:50:31 +0000 Subject: [PATCH 1/9] document coefficients --- lib/statsample-glm/glm/base.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 65eb891..35cf820 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -31,7 +31,21 @@ def initialize ds, y, opts={} .const_get("#{algorithm}").const_get("#{method}") .new(@data_set, @dependent, @opts) end - + + # Returns the coefficients of trained model + # + # @param [Symbol] as_a Specifies the form of output + # + # @return [Array, Hash] coefficients of the model + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, {constant: 1} + # glm.coefficients as_a = :hash + # # => + # # {:x1=>-0.3124937545689041, :x2=>2.286713333462646, :constant=>0.675603176233328} + # def coefficients as_a=:vector case as_a when :hash From a934381bbb183b9ea2917edcb3ce1d50c23bbd12 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Sun, 15 May 2016 07:54:59 +0000 Subject: [PATCH 2/9] change array to vector --- lib/statsample-glm/glm/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 35cf820..8a37cff 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -36,7 +36,7 @@ def initialize ds, y, opts={} # # @param [Symbol] as_a Specifies the form of output # - # @return [Array, Hash] coefficients of the model + # @return [Vector, Hash] coefficients of the model # # @example # require 'statsample-glm' From 8059121dcc15d4c506a9aace2e63a191213f65f6 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Sun, 15 May 2016 08:21:58 +0000 Subject: [PATCH 3/9] document standard error and residuals --- lib/statsample-glm/glm/base.rb | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 8a37cff..ecdbcc6 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -36,7 +36,7 @@ def initialize ds, y, opts={} # # @param [Symbol] as_a Specifies the form of output # - # @return [Vector, Hash] coefficients of the model + # @return [Vector, Hash, Array] coefficients of the model # # @example # require 'statsample-glm' @@ -63,6 +63,23 @@ def coefficients as_a=:vector end end + # Returns the standard error obtained using the model + # + # @param [Symbol] as_a Specifies the form of output + # + # @return [Vector, Hash, Array] standard error + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, {constant: 1} + # glm.standard_error + # # # + # # nil + # # 0 0.4130813039878828 + # # 1 0.7194644911927432 + # # 2 0.40380565497038895 + # def standard_error as_a=:vector case as_a when :hash @@ -88,6 +105,24 @@ def fitted_mean_values @regression.fitted_mean_values end + # Returns for every data point obtained using the model + # + # @return [Vector] all residuals in a vector + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, {constant: 1} + # glm.residuals + # # # + # # y + # # 0 -0.18632025624516532 + # # 1 -0.5146459448198846 + # # 2 0.15916476717451 + # # 3 -0.9241524337773334 + # # 4 0.2281471136368174 + # # ... ... + # def residuals @regression.residuals end From bb32b6c81704445edd0fc34749bebed46d5772a9 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Tue, 17 May 2016 06:11:21 +0000 Subject: [PATCH 4/9] update standard error definition --- lib/statsample-glm/glm/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index ecdbcc6..65f363a 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -63,7 +63,7 @@ def coefficients as_a=:vector end end - # Returns the standard error obtained using the model + # Returns the standard errors for the coefficient estimates # # @param [Symbol] as_a Specifies the form of output # From 5ec4b6f74910f29787a0ebaed371cde776ddbb8d Mon Sep 17 00:00:00 2001 From: lokeshh Date: Tue, 17 May 2016 06:15:52 +0000 Subject: [PATCH 5/9] update residual definition --- lib/statsample-glm/glm/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 65f363a..8920fb0 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -105,7 +105,7 @@ def fitted_mean_values @regression.fitted_mean_values end - # Returns for every data point obtained using the model + # Returns the residual for every data point # # @return [Vector] all residuals in a vector # From 254b994f2017ae0a153fbbf5432d9b2a3680396b Mon Sep 17 00:00:00 2001 From: lokeshh Date: Tue, 17 May 2016 06:42:37 +0000 Subject: [PATCH 6/9] document log_likelihood --- lib/statsample-glm/glm/base.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 8920fb0..55e33ca 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -131,6 +131,18 @@ def degree_of_freedom @regression.degree_of_freedom end + # Returns the optimal value of the log-likelihood function when using MLE algorithm. + # The optimal value is the value of the log-likelihood function at the MLE solution. + # + # @return [Numeric] the optimal value of log-likelihood function + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, constant: 1, algorithm: :mle + # glm.log_likelihood + # # => -21.4752278175261 + # def log_likelihood @regression.log_likelihood if @opts[:algorithm] == :mle end From bcf9800f547f8928ad2107f88fb03f35771e2658 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Tue, 17 May 2016 07:13:57 +0000 Subject: [PATCH 7/9] document degrees of freedom --- lib/statsample-glm/glm/base.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index 55e33ca..d64908e 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -127,6 +127,17 @@ def residuals @regression.residuals end + # Returns the degrees of freedom value. + # + # @return [Integer] the degrees of freedom + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, constant: 1 + # glm.degree_of_freedom + # # => 47 + # def degree_of_freedom @regression.degree_of_freedom end From 0be16b27433fce4dcd10327e14d0e92a8ab0fe13 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Tue, 17 May 2016 08:21:49 +0000 Subject: [PATCH 8/9] document fitted mean values --- lib/statsample-glm/glm/base.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index d64908e..e5d552c 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -101,6 +101,25 @@ def iterations @regression.iterations end + # Returns the values predicted by the coefficient estimates + # + # @return [Vector] vectors of predicted values + # + # @example + # require 'statsample-glm' + # data_set = Daru::DataFrame.from_csv "spec/data/logistic.csv" + # glm = Statsample::GLM.compute data_set, "y", :logistic, constant: 1 + # glm.fitted_mean_values + # # => + # # # + # # nil + # # 0 0.18632025624516532 + # # 1 0.5146459448198846 + # # 2 0.84083523282549 + # # 3 0.9241524337773334 + # # 4 0.7718528863631826 + # # ... ... + # def fitted_mean_values @regression.fitted_mean_values end From 950cccfed8ac40e559c0c9c4a08cb83418765bb5 Mon Sep 17 00:00:00 2001 From: lokeshh Date: Thu, 19 May 2016 05:34:26 +0000 Subject: [PATCH 9/9] update standard errors --- lib/statsample-glm/glm/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statsample-glm/glm/base.rb b/lib/statsample-glm/glm/base.rb index e5d552c..29e37f8 100644 --- a/lib/statsample-glm/glm/base.rb +++ b/lib/statsample-glm/glm/base.rb @@ -101,7 +101,7 @@ def iterations @regression.iterations end - # Returns the values predicted by the coefficient estimates + # Returns the values predicted by the model # # @return [Vector] vectors of predicted values #