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

ERROR: MethodError: Cannot convert an object of type Tuple{Matrix{Float64}, ReMat{Float64, 1}} to an object of type Matrix{Float64} #696

Closed
ParadaCarleton opened this issue Jul 7, 2023 · 2 comments

Comments

@ParadaCarleton
Copy link

using Tables
using MixedModels
using CSVFiles

const GLMM = GeneralizedLinearMixedModel

data = load("ICARdata.csv") |> Tables.rows
regression = @formula(SEI ~ Age + Total + Sex + (1 | Education))
model = fit(GLMM, regression, data, Normal, LogitLink)

Results in:

ERROR: MethodError: Cannot `convert` an object of type Tuple{Matrix{Float64}, ReMat{Float64, 1}} to an object of type Matrix{Float64}

Closest candidates are:
  convert(::Type{Array{S, N}}, ::PooledArrays.PooledArray{T, R, N}) where {S, T, R, N}
   @ PooledArrays ~/.julia/packages/PooledArrays/DXlaI/src/PooledArrays.jl:499
  convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/80e5O/src/SizedArray.jl:88
  convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, M, TData} where {M, TData<:AbstractArray{T, M}}) where {T, S, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/80e5O/src/SizedArray.jl:82
  ...

Stacktrace:
 [1] StatsModels.ModelMatrix{Matrix{Float64}}(mf::StatsModels.ModelFrame{NamedTuple{(:SEI, :Age, :Total, :Sex, :Education), Tuple{Vector{Int64}, Vector{Float64}, …}}, GeneralizedLinearMixedModel})
   @ StatsModels ~/.julia/packages/StatsModels/Wzvuu/src/modelframe.jl:226
 [2] StatsModels.ModelMatrix(mf::StatsModels.ModelFrame{NamedTuple{(:SEI, :Age, :Total, :Sex, :Education), Tuple{Vector{Int64}, Vector{Float64}, …}}, GeneralizedLinearMixedModel})
   @ StatsModels ~/.julia/packages/StatsModels/Wzvuu/src/modelframe.jl:229
 [3] fit(::Type{GeneralizedLinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term, Tuple{StatsModels.Term, StatsModels.FunctionTerm{typeof(^), Vector{StatsModels.AbstractTerm}}, …}}, ::Tables.IteratorWrapper{TableTraitsUtils.TableIterator{NamedTuple{(Symbol(""), :Age, :Sex, :Education, :SEI, Symbol("MR.45"), Symbol("MR.46"), Symbol("MR.47"), Symbol("MR.55"), Symbol("LN.07"), Symbol("LN.33"), Symbol("LN.34"), Symbol("LN.58"), Symbol("VR.04"), Symbol("VR.16"), Symbol("VR.17"), Symbol("VR.19"), Symbol("R3D.03"), Symbol("R3D.04"), Symbol("R3D.06"), Symbol("R3D.08"), :Total), Tuple{Int64, Float64, …}}, Tuple{Vector{Int64}, Vector{Float64}, …}}}, ::Type, ::Vararg{Type}; contrasts::Dict{Symbol, Any}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ StatsModels ~/.julia/packages/StatsModels/Wzvuu/src/statsmodel.jl:86
 [4] fit(::Type{GeneralizedLinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term, Tuple{StatsModels.Term, StatsModels.FunctionTerm{typeof(^), Vector{StatsModels.AbstractTerm}}, …}}, ::Tables.IteratorWrapper{TableTraitsUtils.TableIterator{NamedTuple{(Symbol(""), :Age, :Sex, :Education, :SEI, Symbol("MR.45"), Symbol("MR.46"), Symbol("MR.47"), Symbol("MR.55"), Symbol("LN.07"), Symbol("LN.33"), Symbol("LN.34"), Symbol("LN.58"), Symbol("VR.04"), Symbol("VR.16"), Symbol("VR.17"), Symbol("VR.19"), Symbol("R3D.03"), Symbol("R3D.04"), Symbol("R3D.06"), Symbol("R3D.08"), :Total), Tuple{Int64, Float64, …}}, Tuple{Vector{Int64}, Vector{Float64}, …}}}, ::Type, ::Type)
   @ StatsModels ~/.julia/packages/StatsModels/Wzvuu/src/statsmodel.jl:78
 [5] top-level scope
   @ REPL[29]:1
@palday
Copy link
Member

palday commented Jul 7, 2023

What happens if you do

model = fit(GLMM, regression, data, Normal(), LogitLink())

? In other words, you need to pass instances, not types.

@ParadaCarleton
Copy link
Author

What happens if you do

model = fit(GLMM, regression, data, Normal(), LogitLink())

? In other words, you need to pass instances, not types.

Works then, thanks! Yeah, this seems to be a problem with error messages.

@palday palday closed this as completed Jul 7, 2023
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