From 539caa78313eda483b55d7d9a4225982a67b91c6 Mon Sep 17 00:00:00 2001 From: pdeffebach Date: Fri, 3 Jan 2020 21:58:16 -0500 Subject: [PATCH 1/2] Initial commit --- src/statsmodel.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/statsmodel.jl b/src/statsmodel.jl index be5cd250..e013f111 100644 --- a/src/statsmodel.jl +++ b/src/statsmodel.jl @@ -196,3 +196,25 @@ function Base.show(io::IO, model::TableModels) end end end + +function getparams(model::TableModels, t) + m = model.mf.f.rhs.terms + i = 1 + for x in m + if (t isa CategoricalTerm || t isa ContinuousTerm) && + (x isa CategoricalTerm || x isa ContinuousTerm) + x.sym == t.sym && break + elseif t isa InteractionTerm && x isa InteractionTerm + xterms = map(s -> s.sym, x.terms) + tterms = map(s -> s.sym, t.terms) + xterms == tterms && break + elseif t isa InterceptTerm{true} && x isa InterceptTerm{true} + break + else + error("Not supported yet") + end + i += 1 + + end + return (coefname = coefnames(model)[i], coef = coef(model)[i], stderror = stderror(model)[i]) +end \ No newline at end of file From 1364d831f3405fe5a17b268c134160f20d14a00f Mon Sep 17 00:00:00 2001 From: pdeffebach Date: Sat, 4 Jan 2020 12:27:32 -0500 Subject: [PATCH 2/2] Just barely working --- src/statsmodel.jl | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/statsmodel.jl b/src/statsmodel.jl index e013f111..467ec078 100644 --- a/src/statsmodel.jl +++ b/src/statsmodel.jl @@ -197,24 +197,35 @@ function Base.show(io::IO, model::TableModels) end end -function getparams(model::TableModels, t) +""" + getparams(model::TableModels, t::AbstractTerm) + +Returns a named tuple of parameters corresponding to `t`. + +Examples: + +julia> t = (y = rand(100), x = rand(100), b = rand(Bool, 100)); +julia> m = lm(@formula(y ~ x + x & b), t); +julia> getparams(m, Term(:x)) + +""" +function getparams(model::TableModels, t::AbstractTerm) m = model.mf.f.rhs.terms i = 1 for x in m - if (t isa CategoricalTerm || t isa ContinuousTerm) && - (x isa CategoricalTerm || x isa ContinuousTerm) - x.sym == t.sym && break - elseif t isa InteractionTerm && x isa InteractionTerm + @show typeof(x) + if t isa InteractionTerm && x isa InteractionTerm xterms = map(s -> s.sym, x.terms) tterms = map(s -> s.sym, t.terms) xterms == tterms && break elseif t isa InterceptTerm{true} && x isa InterceptTerm{true} break + elseif x isa CategoricalTerm || x isa ContinuousTerm + x.sym == t.sym && break else - error("Not supported yet") + nothing end i += 1 - end return (coefname = coefnames(model)[i], coef = coef(model)[i], stderror = stderror(model)[i]) end \ No newline at end of file