easystats / parameters

:bar_chart: Computation and processing of models' parameters
https://easystats.github.io/parameters/
GNU General Public License v3.0
416 stars 37 forks source link

parameters.marginaleffects - preserve attributes from original input #948

Closed DominiqueMakowski closed 4 months ago

DominiqueMakowski commented 4 months ago

Doesn't work:

  model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)

  means <- marginaleffects::predictions(model, newdata=insight::get_data(model), by="Species")
  attr(means, "SOMETHING") <- "Yes"
  attributes(parameters::parameters(means))$SOMETHING 
#> NULL

Created on 2024-02-11 with reprex v2.0.2

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (3649723) 59.36% compared to head (702261f) 59.37%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #948 +/- ## ======================================= Coverage 59.36% 59.37% ======================================= Files 187 187 Lines 14093 14095 +2 ======================================= + Hits 8367 8369 +2 Misses 5726 5726 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

DominiqueMakowski commented 4 months ago

and I can't seem to trace where it gets overwritten again 🤔

vincentarelbundock commented 4 months ago

As far as I can tell, parameters never preserves the attributes of the model object. Try

mod <- lm(mpg ~ wt * factor(cyl), data = dat)
attr(mod, "SOMETHING") <- "yes"
attributes(parameters::parameters(mod))$SOMETHING 
DominiqueMakowski commented 4 months ago

Mmh fair. I don't need this, it was mostly for convenience reasons in modelbased but I can do without