bbolker / bbolker/reformulas

handle (e.g.) `factor(x)` in RE formulas

Open
#5 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

```r
library(reformulas)
dd <- expand.grid(z=factor(1:3), temp = 1:5)
dd$y <- rnorm(nrow(dd))
form <- y ~ 1 + (1|z:factor(temp))
fr <- model.frame(subbars(form), data = dd)
mkReTrms(findbars(form), fr)
```

This fails in `mkBlist`. The problem is that model frame gets 'factor(temp)' as a column name, not 'temp', so can't evaluate "factor(temp)" in

```
eval(substitute(makeFac(fac), list(fac = ff0)), frloc)
```

Not sure how to get around this - this is a new instance of the long-standing problem that the model frame has names and values corresponding to modified/transformed variables (`log(x)`, `factor(x)`, etc.), rather than the original variable (`x`).

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the example using subbars(), model.frame(), and mkReTrms(), then inspect where mkBlist evaluates makeFac(fac) against the model frame. Compare the factor(temp) column name with the expression being evaluated. Done means the supplied random-effects formula completes successfully for transformed terms such as factor(temp).

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.