Not able to Stratify VPC

Hi…

I tried to stratify VPC using a Binary categorical Variable"Trial". i got the following error.

julia> pk_vpc = vpc(FM_result2,10;dv=:DV,stratify_by = [:Trial],ensemblealg=EnsembleThreads())
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{Int64,1}}}) at .\broadcast.jl:845
 [6] _vpc(::Array{Subject{NamedTuple{(:DV,),Tuple{Array{Float64,1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Int64,Int64}},1,NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Int64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},1}, ::QuantileRegressions.IP, ::Pumas.ContinuousVPC; dv::Symbol, idv::Symbol, stratify_by::Array{Symbol,1}, quantiles::Tuple{Float64,Float64,Float64}, bandwidth::Int64, numstrats::Array{Int64,1}) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\estimation\vpc.jl:114
 [7] _vpc(::PumasModel{ParamSet{NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},PDiagDomain{PDMats.PDiagMat{Float64,Array{Float64,1}}},RealDomain{Float64,Int64,Float64},VectorDomain{Array{TransformVariables.Infinity{false},1},Array{TransformVariables.Infinity{true},1},Array{Float64,1}}}}},var"#187#207",var"#188#208",var"#190#210",Pumas.LinearODE,var"#191#211",var"#199#219"}, ::Array{Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Int64,Int64}},1,NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Int64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}},1}, ::NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{Float64,Float64,Float64,Float64,PDMats.PDiagMat{Float64,Array{Float64,1}},Float64,Array{Float64,1}}}, ::Int64, ::QuantileRegressions.IP, ::Pumas.ContinuousVPC; dv::Symbol, idv::Symbol, stratify_by::Array{Symbol,1}, quantiles::Tuple{Float64,Float64,Float64}, level::Float64, ensemblealg::EnsembleThreads, bandwidth::Int64, numstrats::Array{Int64,1}, sim_idvs::Nothing, count_vals::Array{Float64,1}) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\estimation\vpc.jl:164
 [8] vpc(::PumasModel{ParamSet{NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},PDiagDomain{PDMats.PDiagMat{Float64,Array{Float64,1}}},RealDomain{Float64,Int64,Float64},VectorDomain{Array{TransformVariables.Infinity{false},1},Array{TransformVariables.Infinity{true},1},Array{Float64,1}}}}},var"#187#207",var"#188#208",var"#190#210",Pumas.LinearODE,var"#191#211",var"#199#219"}, ::Array{Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Int64,Int64}},1,NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Int64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}},1}, ::NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{Float64,Float64,Float64,Float64,PDMats.PDiagMat{Float64,Array{Float64,1}},Float64,Array{Float64,1}}}, ::Int64, ::QuantileRegressions.IP, ::Pumas.ContinuousVPC; dv::Symbol, stratify_by::Array{Symbol,1}, quantiles::Tuple{Float64,Float64,Float64}, level::Float64, ensemblealg::EnsembleThreads, bandwidth::Int64, numstrats::Array{Int64,1}, idv::Symbol, count_vals::Array{Float64,1}, sim_idvs::Nothing) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\estimation\vpc.jl:202
 [9] vpc(::Pumas.FittedPumasModel{PumasModel{ParamSet{NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},PDiagDomain{PDMats.PDiagMat{Float64,Array{Float64,1}}},RealDomain{Float64,Int64,Float64},VectorDomain{Array{TransformVariables.Infinity{false},1},Array{TransformVariables.Infinity{true},1},Array{Float64,1}}}}},var"#187#207",var"#188#208",var"#190#210",Pumas.LinearODE,var"#191#211",var"#199#219"},Array{Subject{NamedTuple{(:DV,),Tuple{Array{Union{Missing, Float64},1}}},Pumas.ConstantInterpolationStructArray{Array{Float64,1},StructArrays.StructArray{NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Float64,Int64,Int64}},1,NamedTuple{(:WT, :INITWT, :DFWT, :M, :SCR, :INITBMI, :DFBMI, :INITFFM, :DFFFM, :SCRD, :GA, :PMA, :AGEYRS, :BMI, :FFM, :ALBD, :TAD, :WG, :Trial),Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Float64,1},Array{Int64,1},Array{Int64,1}}},Int64},Symbol},Array{Pumas.Event{Float64,Float64,Float64,Float64,Float64,Float64,Nothing,Int64},1},Array{Float64,1}},1},Optim.MultivariateOptimizationResults{Optim.BFGS{LineSearches.InitialStatic{Float64},LineSearches.BackTracking{Float64,Int64},Pumas.var"#339#340"{NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}},Array{Float64,1}},Nothing,Optim.Flat},Float64,Array{Float64,1},Float64,Float64,Array{Optim.OptimizationState{Float64,Optim.BFGS{LineSearches.InitialStatic{Float64},LineSearches.BackTracking{Float64,Int64},Pumas.var"#339#340"{NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}},Array{Float64,1}},Nothing,Optim.Flat}},1},Bool},Pumas.FOCEI,Array{Array{Float64,1},1},NamedTuple{(:optimize_fn, :constantcoef, :omegas, :ensemblealg),Tuple{Pumas.DefaultOptimizeFN{Nothing,NamedTuple{(:show_trace, :store_trace, :extended_trace, :g_tol, :allow_f_increases),Tuple{Bool,Bool,Bool,Float64,Bool}}},NamedTuple{(:tvbio, :tvka),Tuple{Float64,Float64}},Tuple{},EnsembleThreads}},ParamSet{NamedTuple{(:tvka, :tvvc, :tvCL, :tvbio, :Ω, :σ, :θ),Tuple{Pumas.ConstDomain{Float64},RealDomain{Float64,Int64,Float64},RealDomain{Float64,Int64,Float64},Pumas.ConstDomain{Float64},PDiagDomain{PDMats.PDiagMat{Float64,Array{Float64,1}}},RealDomain{Float64,Int64,Float64},VectorDomain{Array{TransformVariables.Infinity{false},1},Array{TransformVariables.Infinity{true},1},Array{Float64,1}}}}}}, ::Int64, ::QuantileRegressions.IP, ::Pumas.ContinuousVPC; dv::Symbol, stratify_by::Array{Symbol,1}, quantiles::Tuple{Float64,Float64,Float64}, level::Float64, ensemblealg::EnsembleThreads, bandwidth::Int64, numstrats::Array{Int64,1}, idv::Symbol, count_vals::Array{Float64,1}, sim_idvs::Nothing) at C:\Users\julia\.julia\packages\Pumas\iIBBr\src\estimation\vpc.jl:280   
 [10] top-level scope at none:1

@sai_matcha do you have a time varying covariate in your data?

Yeah.
Weight, Albumin, Serum Creatinine. are time varying covariates in my data.

but only weight was included in current model.
now i tried to stratify with binary variable. which has 0 and 1.( these are not time varying)

Yeah, it looks like in the version you have of Pumas we are not handling cases with time varying covariate correctly. Can you try to run the below and let me know what the output is or share the model and data with me?

cvname = :Trial
numstrat = 4
sub_covariates = vcat([getproperty(subject.covariates(0.0), cvname) for subject in population]...)
println(sub_covariates)
unqcovariates = unique(sub_covariates)
println(unqcovariates)
    if length(unqcovariates) > numstrat
        boundvals = [quantile(unqcovariates,i/numstrat) for i in 1:numstrat]
        f_ = function(el)
            for i in 1:numstrat
                if el <= boundvals[i]
                    return boundvals[i]
                end
            end
        end
        sub_covariates = map(f_, sub_covariates)
    end

    covariates = vcat([[sub_covariates[j] for i in 1:(subject.covariates isa Pumas.ConstantInterpolationStructArray ? length(subject.covariates.u) : length(subject.time))] for (j,subject) in enumerate(population)]...)
println(covariates)

here population is your data