beacon-biosignals / Effects.jl

Effects Prediction for Regression Models
MIT License
19 stars 4 forks source link

y~age+sex, dict has only one of them #29

Closed behinger closed 2 years ago

behinger commented 2 years ago
using DataFrames, Effects, GLM, StatsModels, Random

growthdata = DataFrame(; age=[13:20; 13:20],
                       sex=repeat(["male", "female"], inner=8),
                       weight=[range(100, 155; length=8); range(100, 125; length=8)] .+ randn( 16))

mod_uncentered = lm(@formula(weight ~ 1 + sex + age), growthdata)

effects(Dict(:sex=>["male","female"]), mod_uncentered)

results in

ERROR: type NamedTuple has no field age
Stacktrace:
  [1] getindex
    @ ./namedtuple.jl:118 [inlined]
  [2] modelcols
    @ ~/.julia/packages/StatsModels/m1jYD/src/terms.jl:494 [inlined]
  [3] #34
[...]

But e.g. effects(Dict(:sex=>["male","female"],:age=>[0,0]), mod_uncentered) works. If I add the interaction, weight ~ 1 + sex*age it works as well with my initial effects-dict.

Conceptually, I dont think I need to specify both sex&age in the dict.


I might have narrowed it down to a "<" needing to be a "<=", but then again, I again have no Idea what I'm doing ;-) https://github.com/beacon-biosignals/Effects.jl/blob/12b7d587009fd8fa9f975f2d1a59bc43d52f53d1/src/typical.jl#L68

(I can o.c. do the pull request, would be fun if that is the only change :-D)