-
Notifications
You must be signed in to change notification settings - Fork 116
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
linear model with Float32 #260
Comments
The code probably needs some tweaks to be more generic. PR welcome. |
@kleinschmidt Is it on purpose that the model matrix promotes to It's worth noticing that |
I don't know actually...I suspect it was just a sensible default. I think it could be overridden by specifying I'm not super inclined to do the deep dive in the current StatsModels code to fix this though given that (inshallah) that's going to be replaced by Terms 2.0 (JuliaStats/StatsModels.jl#71). |
It's also hard to handle this in a sufficiently general way since you might have a categorical variable that gets expanded according to a contrasts matrix; that defaults to Float64, so you'd somehow have to figure out to un-promote that to Float32 in the case when the only continuous variables are Float32s. |
Also to clarify what @andreasnoack said: this is an issue with StatsModels (which handles the formula), not with GLM. |
I just encountered the same issue. This problem occurs when reading data from Stata's |
Glad the other lm function with no formula works with Float32. I would not put the function with formula on doc if it doesn' t work with such a basic data type. Is it a good time to fix this? |
I guess the question is, what should GLM do when it gets a I'd suggest something like a promotion (or at least an eltype check) in Line 129 in 468d0f8
|
Ahahaha yes here's exactly what I was talking about...statsmodels doctests picked up this (lack of Bool-to-Float64 conversion): https://github.com/JuliaStats/StatsModels.jl/actions/runs/5095234337/jobs/9159967200?pr=294#step:5:305 |
Looks like this might be even worse at this point julia> df = DataFrame(x = randn(Float32, 10), y = randn(Float32, 10))
10×2 DataFrame
Row │ x y
│ Float32 Float32
─────┼───────────────────────
1 │ -0.945676 -0.132859
2 │ -0.0802135 0.180285
3 │ -1.86329 -0.291655
4 │ -0.705064 -0.633368
5 │ 1.63913 -1.11767
6 │ -0.494249 1.19169
7 │ -1.91468 -0.221668
8 │ -1.32549 -0.136988
9 │ 0.302089 -0.940081
10 │ 0.351315 -0.532551
julia> lm(@formula(y ~ x), df)
ERROR: MethodError: no method matching delbeta!(::GLM.DensePredChol{Float64, CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}, ::Vector{Float32}) but the underlying issue might be JuliaStats/StatsModels.jl#293 |
There might be a separate issue related to offsets, see #562 |
Hi GLM,
I am trying to use the lm function with the following command:
mydata = DataFrame(X=MyDataType.(1:3), Y=MyDataType.(11:13)); lm(@formula(Y ~ 1 + X), mydata)
This works fine with
MyDataType = Float64
orInt32
andInt64
but withFloat32
I get the following error:My environment is the following:
The text was updated successfully, but these errors were encountered: