# Something wrong when using goodness\_of\_fit

**URL:** <https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712>\
**Category:** Basic Usage\
**Created:** [June 27, 2022, 3:36pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712 "2022-06-27T15:36:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 3:36pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/1 "2022-06-27T15:36:09Z")

</div>

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:

```auto
## 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)))

```

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [June 27, 2022, 4:44pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/2 "2022-06-27T16:44:46Z")

</div>

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

```julia
## 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

```julia
report(GoF_Weibull, clean = false)

```

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 5:02pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/3 "2022-06-27T17:02:34Z")

</div>

Thank you. This makes sense. The inspect lines works but I am getting a “Makie.convert\_arguments” error in the goodness\_of\_fit line.

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [June 27, 2022, 6:05pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/4 "2022-06-27T18:05:05Z")

</div>

can you just try `observations_vs_predictions` instead of `goodness_of_fit`

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 6:19pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/5 "2022-06-27T18:19:26Z")

</div>

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

```auto
# 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")

```

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [June 27, 2022, 6:40pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/6 "2022-06-27T18:40:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 6:43pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/7 "2022-06-27T18:43:21Z")

</div>

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](http://makie.juliaplots.org/stable/documentation/recipes/index.html)).

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.

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 6:44pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/8 "2022-06-27T18:44:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rahulub3r](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/rahulub3r/32/182_2.png) [@Rahulub3r](https://discourse.pumas.ai/u/Rahulub3r)\
**Post date:** [June 27, 2022, 7:30pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/9 "2022-06-27T19:30:23Z")

</div>

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

> [@KVTobin](#):
>
> `fdiss = @. fdissmax * (1 - exp((t/td50)*B))`

to:

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

```

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 27, 2022, 7:37pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/10 "2022-06-27T19:37:07Z")

</div>

Thank you for spotting that mistake.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/michael/32/818_2.png) [@Michael](https://discourse.pumas.ai/u/Michael)\
**Post date:** [June 28, 2022, 7:22am UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/11 "2022-06-28T07:22:17Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 28, 2022, 3:19pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/12 "2022-06-28T15:19:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/michael/32/818_2.png) [@Michael](https://discourse.pumas.ai/u/Michael)\
**Post date:** [June 28, 2022, 3:27pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/13 "2022-06-28T15:27:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KVTobin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/kvtobin/32/292_2.png) [@KVTobin](https://discourse.pumas.ai/u/KVTobin)\
**Post date:** [June 28, 2022, 3:41pm UTC](https://discourse.pumas.ai/t/something-wrong-when-using-goodness-of-fit/712/14 "2022-06-28T15:41:51Z")

</div>

Understood. Thank you for all your help!
