Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLM fails when Matrix contains a single column #515

Closed
dpabon opened this issue Feb 24, 2023 · 2 comments
Closed

GLM fails when Matrix contains a single column #515

dpabon opened this issue Feb 24, 2023 · 2 comments

Comments

@dpabon
Copy link

dpabon commented Feb 24, 2023

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 0

[38e38edf] GLM v1.8.1
[a93c6f00] DataFrames v1.3.6

Here a MWE where ols2 fail:

using DataFrames
using GLM

X1 = rand(100,1)
X2 = rand(100,1)
Y1 = rand(100,1)
data_f = DataFrame(X1 = vec(X1), Y1 = vec(Y1))

ols = GLM.lm(@formula(Y1 ~ X1), data_f) # works as expected

ols2 = GLM.lm(X1,Y1) # Fail!!

error:

ERROR: MethodError: no method matching fit(::Type{LinearModel}, ::Matrix{Float64}, ::Matrix{Float64}, ::Nothing)
Closest candidates are:
  fit(::Type{T}, ::FormulaTerm, ::Any, ::Any...; contrasts, kwargs...) where T<:RegressionModel at ~/.julia/packages/StatsModels/fK0P3/src/statsmodel.jl:78
  fit(::Type{StatsBase.Histogram}, ::Any...; kwargs...) at ~/.julia/packages/StatsBase/XgjIN/src/hist.jl:407
  fit(::Type{LinearModel}, ::AbstractMatrix{<:Real}, ::AbstractVector{<:Real}, ::Union{Nothing, Bool}; wts, dropcollinear) at ~/.julia/packages/GLM/zj7GL/src/lm.jl:134
  ...
Stacktrace:
 [1] lm(X::Matrix{Float64}, y::Matrix{Float64}, allowrankdeficient_dep::Nothing; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ GLM ~/.julia/packages/GLM/zj7GL/src/lm.jl:157
 [2] lm(X::Matrix{Float64}, y::Matrix{Float64}, allowrankdeficient_dep::Nothing) (repeats 2 times)
   @ GLM ~/.julia/packages/GLM/zj7GL/src/lm.jl:157
 [3] top-level scope
   @ Untitled-1:11
@andreasnoack
Copy link
Member

Your response has to be a Vector, i.e. ols2 = GLM.lm(X1, vec(Y1))

@andreasnoack
Copy link
Member

Please follow up, if needed, on https://discourse.julialang.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants