bbolker / bbolker/reformulas

Helper function to obtain fixed effect and grouping factor?

Open
#9 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
7
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Given that `reformulas` takes formulas of random-effects components and processes them, I'm surprised there is not an explicit function to obtain fixed effects and grouping factors (only). I tested a little bit to get something to work, but I feel like this should already be built in...

```
formula <- angle ~ recipe * temperature + (1|recipe:replicate)

# getting grouping factor
group_vars <- reformulas::findbars(formula)
group_vars <- unique(
unlist(lapply(group_vars, function(term) all.vars(term[[3]]))))
group_vars
```
```
[1] "recipe" "replicate"
```

```
# getting fixed effects (only)
bars <- reformulas::RHSForm(formula)
fixed_vars <- all.vars(bars)
# trying to get rid of possible grouping factors (that appear in both areas)
fixed_vars <- setdiff(fixed_vars, group_vars)
fixed_vars
```
```
[1] "temperature"
```

Of course, do let me know if there's in fact an easier way and I might have missed something...

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the existing reformulas::findbars and RHSForm entry points and tracing them with the example formula in the issue. Clarify the intended helper's return values for fixed effects and grouping factors, then verify that the documented example produces the expected separation.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.