ERROR: DimensionMismatch

Hi
I have used the below code

phen2 = CSV.read("D:\\PUMASdatasets\\basemodel1.csv",missingstring = "NA")
a2 = names(phen2)
pumdf2 = read_pumas(phen2, observations = [:DV], id = :ID, time = :TIME, amt = :AMT, rate = :RATE, cmt = :CMT,
                    covariates = [:WT])

when i check the result, i got below error

julia> DataFrame(pumdf2)
ERROR: DimensionMismatch("array could not be broadcast to match destination")
Stacktrace:
 [1] check_broadcast_shape at .\broadcast.jl:520 [inlined]
 [2] check_broadcast_axes at .\broadcast.jl:523 [inlined]
 [3] instantiate at .\broadcast.jl:269 [inlined]
 [4] materialize! at .\broadcast.jl:848 [inlined]
 [5] materialize!(::DataFrames.LazyNewColDataFrame{Symbol}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(identity),Tuple{Array{Float64,1}}}) at .\broadcast.jl:845
 [6] _add_covariates(::DataFrame, ::Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT,),Tuple{Float64}},1,NamedTuple{(:WT,),Tuple{Array{Float64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}}) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\data_parsing\io.jl:753
 [7] DataFrame(::Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT,),Tuple{Float64}},1,NamedTuple{(:WT,),Tuple{Array{Float64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}}; include_covariates::Bool, include_observations::Bool, include_events::Bool) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\data_parsing\io.jl:727
 [8] (::Pumas.var"#55#56"{Bool,Bool,Bool})(::Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT,),Tuple{Float64}},1,NamedTuple{(:WT,),Tuple{Array{Float64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}}) at .\none:0
 [9] iterate(::Base.Generator{Array{Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},T2,Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}} where T2,1},Pumas.var"#55#56"{Bool,Bool,Bool}}, ::Int64) at .\generator.jl:47
 [10] #DataFrame#54 at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\data_parsing\io.jl:822 [inlined]
 [11] DataFrame(::Array{Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},T2,Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}} where T2,1}) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\data_parsing\io.jl:822
 [12] top-level scope at none:1

It is working properly when i change the covariate.
(Both the covariates have same length)

pumdf2 = read_pumas(phen2, observations = [:DV], id = :ID, time = :TIME, amt = :AMT, rate = :RATE, cmt = :CMT,
                    covariates = [:INITWT])
julia> DataFrame(pumdf2)
3485×16 DataFrame
│ Row  │ id     │ time    │ evid  │ DV       │ amt      │ dose    │ tad     │ cmt    │ rate     │ duration  │ ss    │ ii       │ base_time │ rate_dir │ route   │ INITWT  │
│      │ String │ Float64 │ Int64 │ Float64? │ Float64? │ Float64 │ Float64 │ Int64? │ Float64? │ Float64?  │ Int64 │ Float64? │ Float64?  │ Int8?    │ Nothing │ Float64 │
├──────┼────────┼─────────┼───────┼──────────┼──────────┼─────────┼─────────┼────────┼──────────┼───────────┼───────┼──────────┼───────────┼──────────┼─────────┼─────────┤
│ 1    │ 1      │ 0.0     │ 1     │ missing  │ 475.0    │ 475.0   │ 0.0     │ 2      │ 2910.88  │ 0.163181  │ 0     │ 0.0      │ 0.0       │ 1        │         │ 24.257  │
│ 2    │ 1      │ 10.25   │ 1     │ missing  │ 60.0     │ 60.0    │ 0.0     │ 1      │ 0.0      │ 0.0       │ 0     │ 0.0      │ 10.25     │ 1        │         │ 24.257  │
│ 3    │ 1      │ 21.28   │ 1     │ missing  │ 60.0     │ 60.0    │ 0.0     │ 1      │ 0.0      │ 0.0       │ 0     │ 0.0      │ 21.28     │ 1        │         │ 24.257  │
│ 4    │ 1      │ 34.0    │ 1     │ missing  │ 60.0     │ 60.0    │ 0.0     │ 1      │ 0.0      │ 0.0       │ 0     │ 0.0      │ 34.0      │ 1        │         │ 24.257  │
⋮
│ 3481 │ 178    │ 94.82   │ 1     │ missing  │ 4.0      │ 4.0     │ 0.0     │ 2      │ 292.87   │ 0.0136579 │ 0     │ 0.0      │ 94.82     │ 1        │         │ 2.55    │
│ 3482 │ 178    │ 102.9   │ 0     │ 1.4      │ missing  │ 4.0     │ 8.08    │ 2      │ missing  │ missing   │ 0     │ missing  │ missing   │ missing  │         │ 2.55    │
│ 3483 │ 178    │ 102.98  │ 1     │ missing  │ 4.0      │ 4.0     │ 0.0     │ 2      │ 341.4    │ 0.0117165 │ 0     │ 0.0      │ 102.98    │ 1        │         │ 2.55    │
│ 3484 │ 178    │ 110.68  │ 1     │ missing  │ 4.0      │ 4.0     │ 0.0     │ 2      │ 341.4    │ 0.0117165 │ 0     │ 0.0      │ 110.68    │ 1        │         │ 2.55    │
│ 3485 │ 178    │ 120.15  │ 1     │ missing  │ 4.0      │ 4.0     │ 9.47    │ 2      │ 341.4    │ 0.0117165 │ 0     │ 0.0      │ 120.15    │ 1        │         │ 2.55    │

Can someone help me to figure out this?

Thank you

I have noticed one more thing. DataFrame of read_pumas file gives dimention error if covariate is changing with time. And it gives proper dataframe if covariate is time constant.

I am changing my question now :sweat_smile:.

How can i handle time varying covariates in pumas?

Thank you.

Pumas is generally able to handle time-varying covariates. However, there is a bug in our DataFrame constructor when the time-varying covariates are observed at the same time both as an observation row (evid==0) and a dose row (evid > 0). It should be fixed in the next release of Pumas. Meanwhile, it might be sufficient if you change one of the values to missing.

1 Like