JuliaStats / GLM.jl

Generalized linear models in Julia
Other
584 stars 114 forks source link

Method 1 and 2 produce different results for the same data #516

Closed dpabon closed 1 year ago

dpabon commented 1 year ago
using DataFrames
using GLM

new_x = rand(100,3)
new_y = rand(100)

GLM.lm(new_x, new_y)

Produce:

LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}:

Coefficients:
───────────────────────────────────────────────────────────────
        Coef.  Std. Error     t  Pr(>|t|)  Lower 95%  Upper 95%
───────────────────────────────────────────────────────────────
x1  0.295717    0.096847   3.05    0.0029   0.103502   0.487931
x2  0.462823    0.0882726  5.24    <1e-06   0.287627   0.63802
x3  0.0857036   0.0956069  0.90    0.3722  -0.10405    0.275457
───────────────────────────────────────────────────────────────
data_f = DataFrame(x1 = new_x[:,1], x2 = new_x[:,2], x3 = new_x[:,3], y = new_y)

ols = GLM.lm(@formula(y ~ x1 + x2), data_f)

Produce:

StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

y ~ 1 + x1 + x2

Coefficients:
──────────────────────────────────────────────────────────────────────────
                  Coef.  Std. Error     t  Pr(>|t|)   Lower 95%  Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept)  0.374513     0.0745926  5.02    <1e-05   0.226467    0.522558
x1           0.00540252   0.100866   0.05    0.9574  -0.194789    0.205594
x2           0.170571     0.0973294  1.75    0.0828  -0.0226013   0.363743
──────────────────────────────────────────────────────────────────────────
dpabon commented 1 year ago

I forgot to define x3 on data_f = DataFrame(x1 = new_x[:,1], x2 = new_x[:,2], y = new_y) edited accordingly

andreasnoack commented 1 year ago

@dpabon Please direct these usability questions to https://discourse.julialang.org/