Skip to content

Instantly share code, notes, and snippets.

@v0dro
Last active August 29, 2015 14:06
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 v0dro/8cfbd46136b26c95bacd to your computer and use it in GitHub Desktop.
Save v0dro/8cfbd46136b26c95bacd to your computer and use it in GitHub Desktop.
Problem in statsample-glm
require 'statsample'
ds = Statsample::CSV.read('/home/sameer/github_repos/statsample/test/fixtures/test_binomial.csv')"
lr = Statsample::Regression::Binomial::Logit.new(ds,'y')"
require 'statsample-glm'
@glm = Statsample::Regression.glm(Statsample::Dataset.new({'a'=>ds.vector('a'), 'b'=> ds.vector('b'), 'c' => ds.vector('c')}), ds.vector('y'), :binomial)
@glm.coefficients
# => Vector(type:scale, n:3)[0.4033525715642599,1.6683355279170868,-1.1911705910766943]",
lr.coeffs
# => {"a"=>0.3270424372821127, "b"=>0.8147074802641313, "c"=>-0.4030572793782994}
## As you can see, the co-efficients don't match.
# Note : The GLM results from R match those from statsample but do not match those of statsample-glm. Here is my R code.
> csv = read.csv("/home/sameer/github_repos/statsample/test/fixtures/test_binomial.csv")
> attach(csv)
> glm(y ~ +a+b+c, family = binomial)
# => Output
Call: glm(formula = y ~ +a + b + c, family = binomial)
Coefficients:
(Intercept) a b c
-5.3658 0.3270 0.8147 -0.4031
Degrees of Freedom: 199 Total (i.e. Null); 196 Residual
Null Deviance: 277.1
Residual Deviance: 77.73 AIC: 85.73
# Note: The coeffs reported by statsample::regression as same as above while those from statsample-glm are [0.4033525715642599,1.6683355279170868,-1.1911705910766943], which are incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment