Something wrong when using goodness_of_fit

Hey All,

I am trying to analyze my fitted data using goodness_of_fit, but it does not seem to work with the dataframe I made. I get the error: goodness_of_fit cannot be plotted into a single axis.` I have a dataframe being input, so I don’t understand why it says there is only a single axis.

Here is my code:

## Fitting weibull model to simulated population
@time fit_Weibull = [fit(model_Weibull, pop_Weibull[i], param_Weibull) for i in 1:length(pop_Weibull)]

## Post processing
inspect_Weibull = reduce(vcat, DataFrame(inspect(id)) for id in fit_Weibull)
GoF_Weibull = reduce(vcat, DataFrame(goodness_of_fit(inspect_Weibull)))

you cannot post-process a DataFrame. It has to be of Type FittedPumasInspection. Try this (untested)

## Fitting weibull model to simulated population
@time fit_Weibull = [fit(model_Weibull, pop_Weibull[i], param_Weibull) for i in 1:length(pop_Weibull)]

## Post processing
inspect_Weibull = map(ft -> inspect(ft), fit_Weibull)
GoF_Weibull = map(insp -> goodness_of_fit(insp), inspect_Weibull) # will result in a vector of GOF

you can index in and check each GOF like this GoF_Weibull[1], GoF_Weibull[2] ...
if each of them happen to be just the figure, then you can try

report(GoF_Weibull, clean = false)

Thank you. This makes sense. The inspect lines works but I am getting a “Makie.convert_arguments” error in the goodness_of_fit line.

can you just try observations_vs_predictions instead of goodness_of_fit

Thanks for the suggestion. It still gives the same error though.
Here is the full code:

# Practice fitting Weibull model using Pumas
using Random, Pumas, PumasUtilities, CairoMakie, AlgebraOfGraphics, DataFramesMeta, DataFrames, CSV

## Read in simulated population of 6 formulations with fdiss (percent drug dissolved)
sim_Emax = CSV.read("/home/jrun/data/code/Practice/ExercisePK44_1/Data/Emaxpop.csv", DataFrame)

## Create pupulation
pop_Weibull = read_pumas(sim_Emax, observations=[:dv_fdiss], covariates=[:dtd50], event_data=false)

## Model definition Weibull
model_Weibull = @model begin
    @metadata begin
        desc = "Dissolution model Weibul"
        timeu = u"minute"
    end

    @param begin
        "Maximum percent drug dissolved (%)"
        θfdissmax ∈ RealDomain(lower=0)
        "Time required for 50 percent of the drug to dissolve (minutes)"
            θtd50 ∈ RealDomain(lower=0)
        "Additive RUV"
            σadd ∈ RealDomain(lower=0)
        "sigmoidicity factor"
               θB ∈ RealDomain(lower=0)
    end

    @covariates dtd50

    @pre begin
         fdissmax = θfdissmax
             td50 = θtd50 * (1 + dtd50)
                B = θB
    end

    @derived begin
        fdiss = @. fdissmax * (1 - exp((t/td50)*B))
        """
        Percent dissolved in vitro
        """
        dv_fdiss ~ @. Normal(fdiss, σadd)
        
    end
end

## Initial parameters
param_Weibull = (θfdissmax = 100.0, θtd50 = 10, σadd = 0.01, θB = 0.5)

## Fit Weibull model to simulated population from Emax model
@time fit_Weibull = [fit(model_Weibull, pop_Weibull[i], param_Weibull) for i in 1:length(pop_Weibull)]

## Post processing
inspect_Weibull = map(ft -> inspect(ft), fit_Weibull)
GoF_Weibull = map(insp -> observations_vs_predictions(insp), inspect_Weibull)

## Plot 
@chain inspect_Weibull begin
    @rsubset :time ∈ [1,5,10,15,30,60,90,120]
    data(_) *
    mapping(:time => "Time(minutes)",
        :dv_fdiss => "Percent dissolved",
        color = :dtd50 => nonnumeric => "TD50") *
    visual(ScatterLines, linewidth = 4, markersize = 12)
    draw(axis = (;xticks = 0:15:120, yticks = 0:10:100))
end

## Output
report((fit_Weibull[1], infer_Weibull[1], inspected_Weibull[1]), output="/home/jrun/data/code/Practice/ExercisePK44_1/Reports/Emaxgamma_report")

can you post the full error please? The entire error that comes in the REPL

ERROR: Makie.convert_arguments for the plot type Lines{Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Float64}} and its conversion trait PointBased() was unsuccessful.

The signature that could not be converted was:
::Vector{Float32}, ::Float64

Makie needs to convert all plot input arguments to types that can be consumed by the backends (typically Arrays with Float32 elements).
You can define a method for Makie.convert_arguments (a type recipe) for these types or their supertypes to make this set of arguments convertible (See Plot Recipes).

Alternatively, you can define Makie.convert_single_argument for single arguments which have types that are unknown to Makie but which can be converted to known types and fed back to the conversion pipeline.

The full error is much longer. let me know if you need that, though the REPL does not load the whole error message.

I would try two things: 1) hide the fdiss variable from output using := 2) properly specify weibull function. Change this:

to:

fdiss := @. fdissmax * (1 - exp(-(t/td50)^B))

Thank you for spotting that mistake.

@KVTobin can you provide that complete error message, thanks. There’s definitely something odd happening with the argument types internally, so a more complete error will help me better narrow down the issue.

It seems to be working now, but is giving the output as a vector of {Makie.FigureAxisPlot}. How do I visualize them?

You should be able to index into that vector to plot each directly in the vscode plot pane.

Understood. Thank you for all your help!