GLM.jl
GLM.jl copied to clipboard
`glm` fails with Float32 offset and data
I recently ran into an issue where the glm
function failed in the following code:
using GLM
n = 10
data = (X = rand(n) .+ 0.5, y = rand(n))
offset = Float32.(rand(n))
GLM.glm(@GLM.formula(y ~ 0 + X), data, Binomial(); offset = offset)
with the error
MethodError: no method matching GLM.GlmResp(::Vector{…}, ::Binomial{…}, ::LogitLink, ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…}
This is presumably because the offset is of a different numeric type than the other data. However, even without an offset and switching the data to Float32 like so:
data = (X = Float32.(rand(n) .+ 0.5), y = Float32.(rand(n)))
GLM.glm(@GLM.formula(y ~ 0 + X), data, Binomial())
the code above still throws an error, namely:
MethodError: no method matching delbeta!(::GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{…}}, ::Vector{Float32}, ::Vector{Float32})
Given that the method works when all variables are left as Float64 and the non-descriptive error message, it seems this may not be intentional behavior.