Error with DataFrame function when using output from predict function

Hi,
I am getting the following error when trying to convert the output from predict function to DataFrame()

pred = DataFrame(predict(modfit, obstimes = 1:1:2000))
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Float64
Closest candidates are:
  convert(::Type{T}, ::Static.StaticFloat64{N}) where {N, T<:AbstractFloat} at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Static/pkxBE/src/float.jl:26
  convert(::Type{T}, ::LLVM.GenericValue, ::LLVM.LLVMType) where T<:AbstractFloat at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/LLVM/WjSQG/src/execution.jl:39
  convert(::Type{T}, ::LLVM.ConstantFP) where T<:AbstractFloat at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/LLVM/WjSQG/src/core/value/constant.jl:111
  ...
Stacktrace:
  [1] setindex!(A::Vector{Float64}, x::Missing, i1::Int64)
    @ Base ./array.jl:903
  [2] DataFrame(subject::Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}; include_covariates::Bool, include_observations::Bool, include_events::Bool, extra_time::Vector{Float64})
    @ Pumas /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/MxXdQ/src/data_parsing/io.jl:1180
  [3] DataFrame(pred::Pumas.SubjectPrediction{NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}; include_covariates::Bool, include_observations::Bool, include_events::Bool)
    @ Pumas /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/MxXdQ/src/estimation/diagnostics.jl:229
  [4] (::Base.Broadcast.var"#41#42"{Base.Pairs{Symbol, Bool, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:include_covariates, :include_observations, :include_events), Tuple{Bool, Bool, Bool}}}, DataType})(args::Pumas.SubjectPrediction{NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}})
    @ Base.Broadcast ./broadcast.jl:1283
  [5] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
  [6] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
  [7] getindex
    @ ./broadcast.jl:597 [inlined]
  [8] copyto_nonleaf!(dest::Vector{DataFrame}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Tuple{Base.OneTo{Int64}}, Base.Broadcast.var"#41#42"{Base.Pairs{Symbol, Bool, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:include_covariates, :include_observations, :include_events), Tuple{Bool, Bool, Bool}}}, DataType}, Tuple{Base.Broadcast.Extruded{Vector{Pumas.SubjectPrediction{NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}}, Tuple{Bool}, Tuple{Int64}}}}, iter::Base.OneTo{Int64}, state::Int64, count::Int64)
    @ Base.Broadcast ./broadcast.jl:1055
  [9] copy
    @ ./broadcast.jl:907 [inlined]
 [10] materialize
    @ ./broadcast.jl:860 [inlined]
 [11] DataFrame(vpred::Vector{Pumas.SubjectPrediction{NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}}; include_covariates::Bool, include_observations::Bool, include_events::Bool)
    @ Pumas /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/MxXdQ/src/estimation/diagnostics.jl:272
 [12] DataFrame(vpred::Vector{Pumas.SubjectPrediction{NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, NamedTuple{(:CP, :CONC), Tuple{Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantInterpolationStructArray{Vector{Float64}, NamedTuple{(:logwt, :logecmo, :WT, :AGE_D, :ISMALE, :SCR, :GFR, :AGEYRS, :TYPE_MODELING, :IS_BLEEDING, :IS_CIRCUIT_CHANGE, :ECMO_DAYS, :Occassions, :IS_CIRCUIT_CHANGE_UPDATE, :IS_BLEEDING_UPDATE), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}, Vector{Int64}}}, Symbol}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}})
    @ Pumas /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/MxXdQ/src/estimation/diagnostics.jl:272
 [13] top-level scope
    @ ~/data/code/UFH_ECMO_UTAH/UFH_UTAH/ECMO_UTAH_NEW.jl:302

This function used to work before. Any idea what does this error mean?

Thanks

It’s unfortunately a bug that was introduced while fixing another bug. We’ll have this bug fixed in the next release. In the meantime, you might be able to work around the issue with the DataFrame constructor by extracting the predictions directly from the SubjectPrediction struct. The predict will return a Vector of SubjectPredictions. A SubjectPrediction has a pred and an ipred field for the population and individual predictions respectively.

1 Like