# \[ANN\] NestedTerms.jl - concept

**URL:** <https://discourse.julialang.org/t/ann-nestedterms-jl-concept/112051>\
**Category:** Statistics\
**Created:** [March 24, 2024, 8:54pm UTC](https://discourse.julialang.org/t/ann-nestedterms-jl-concept/112051 "2024-03-24T20:54:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)\
**Post date:** [March 24, 2024, 8:54pm UTC](https://discourse.julialang.org/t/ann-nestedterms-jl-concept/112051/1 "2024-03-24T20:54:03Z")

</div>

[NestedTerms.jl](https://github.com/PharmCat/NestedTerms.jl) is a concept package for correct nested terms fitting .

## Install

```julia
import Pkg
Pkg.add(url = "https://github.com/PharmCat/NestedTerms.jl.git")

```

## Example

```julia-auto
using NestedTerms
using StatsModels, CSV, DataFrames, CategoricalArrays

rds = CSV.File(joinpath(dirname(pathof(NestedTerms)), "..", "test", "csv", "rds12x2.csv")) |> DataFrame # DataFrame with nested factor Subject(Sequence)

transform!(rds, :Sequence => categorical, renamecols=false)
transform!(rds, :Subject => categorical, renamecols=false)

# Nested term exploit function term in @formula macros
formula = @formula(Var ~ (Subject in Sequence))

# Replace FunctionTerm to NestedTerm
formula = NestedTerms.process_nt(formula)

# Make schema and apply_schema 
sch = schema(formula, rds)
as = apply_schema(formula, sch) $ upper level factor not added to the formula (but it shoud be there)

# Get model matrix for nested term 
rmf, lmf = modelcols(as, rds)

```

## Unsolvable problems

Can’t get real `coefnames` and `levels` until `modelcols` not called. `apply_schema` not able to modify NestedTerm because have no appropriate information.

## Question!

Is any way to workaround to get information about data or one more modification should be added after `apply_schema(formula, sch)`?
