Modeled after lme4:::expandSlash, by Doug Bates. However,
all formula operators that apply to factors (*
, /
, +
)
are applicable: the results are expanded into a list of independent (additive)
random effect terms
expandDoubleVert(term)
RHSForm(formula) <- value
sumTerms(termList)
reOnly(f, response = FALSE, bracket = TRUE, doublevert_split = TRUE)
makeOp(x, y, op = NULL)
addForm0(f1, f2)
addForm(...)
expandAllGrpVar(bb)
findbars_x(
term,
debug = FALSE,
specials = character(0),
default.special = "us",
target = "|",
expand_doublevert_method = c("diag_special", "split")
)
findbars(term)
inForm(form, value)
extractForm(term, value)
dropHead(term, value)
drop.special(x, value = quote(offset), preserve = NULL)
replaceForm(term, target, repl)
expression/formula
a formula object
term to remove from formula
a list of formula terms
a formula
include response variable?
bracket-protect terms?
(logical) TRUE for lme4 back-compatibility; FALSE to make double vertical bars into diag()
eterms
formula
a formula term (or an operator)
an operator
formula #1
formula #2
arguments to pass through to addForm0
a list of naked grouping variables, i.e. 1 | f
(logical) debug?
list of special terms
character: special to use for parenthesized terms - i.e. random effects terms with unspecified structure
method for handling ||
operator: split into separate terms or replace by diag
? Inherited from previous call where it was specified.
atom (not a call or an expression): NULL
special, i.e. foo(...) where "foo" is in specials: return term
parenthesized term: if the head of the head is | (i.e. it is of the form (xx|gg), then convert it to the default special type; we won't allow pathological cases like ((xx|gg)) ... can we detect them?
(integer) retain the specified occurrence of "value"
a list of expressions
f <- y ~ 1 + x
RHSForm(f) <- quote(2+x^2)
print(f)
#> y ~ 2 + x^2
#> <environment: 0x56443f2a6610>
reOnly(~ 1 + x + y + (1|f) + (1|g))
#> ~(us(1 | f)) + (us(1 | g))
addForm0(y~x,~1)
#> y ~ x + 1
#> <environment: 0x56443f2a6610>
addForm0(~x,~y)
#> ~x + y
#> <environment: 0x56443f2a6610>
ff <- findbars_x(y~1+(x|f/g))
expandAllGrpVar(ff)
#> [[1]]
#> us(x | g:f)
#>
#> [[2]]
#> us(x | f)
#>
expandAllGrpVar(quote(1|(f/g)/h))
#> [[1]]
#> 1 | h:g:f
#>
#> [[2]]
#> 1 | g:f
#>
#> [[3]]
#> 1 | f
#>
expandAllGrpVar(quote(1|f/g/h))
#> [[1]]
#> 1 | h:g:f
#>
#> [[2]]
#> 1 | g:f
#>
#> [[3]]
#> 1 | f
#>
expandAllGrpVar(quote(1|f*g))
#> [[1]]
#> 1 | f
#>
#> [[2]]
#> 1 | g
#>
#> [[3]]
#> 1 | f:g
#>
expandAllGrpVar(quote(1|f+g))
#> [[1]]
#> 1 | f
#>
#> [[2]]
#> 1 | g
#>
expandAllGrpVar(quote(a+b|f+g+h*i))
#> [[1]]
#> a + b | f
#>
#> [[2]]
#> a + b | g
#>
#> [[3]]
#> a + b | h
#>
#> [[4]]
#> a + b | i
#>
#> [[5]]
#> a + b | h:i
#>
expandAllGrpVar(quote(s(log(d), k = 4)))
#> [[1]]
#> s(log(d), k = 4)
#>
expandAllGrpVar(quote(s(log(d+1))))
#> [[1]]
#> s(log(d + 1))
#>
splitForm(quote(us(x,n=2)))
#> $fixedFormula
#> ~1
#> <environment: 0x56444055d718>
#>
#> $reTrmFormulas
#> $reTrmFormulas[[1]]
#> x
#>
#>
#> $reTrmAddArgs
#> $reTrmAddArgs[[1]]
#> us(n = 2)
#>
#>
#> $reTrmClasses
#> [1] "us"
#>
findbars_x(~ 1 + (x + y || g), expand_doublevert_method = "diag_special")
#> [[1]]
#> diag(x + y | g)
#>
findbars_x(~ 1 + (x + y || g), expand_doublevert_method = "split")
#> [[1]]
#> us(1 | g)
#>
#> [[2]]
#> us(0 + x | g)
#>
#> [[3]]
#> us(0 + y | g)
#>
findbars_x(~ 1 + (1 | f) + (1 | g))
#> [[1]]
#> us(1 | f)
#>
#> [[2]]
#> us(1 | g)
#>
findbars_x(~ 1 + (1 | f) + (1 | g))
#> [[1]]
#> us(1 | f)
#>
#> [[2]]
#> us(1 | g)
#>
findbars_x(~ 1 + (1|h) + (x + y || g), expand_doublevert_method = "split")
#> [[1]]
#> us(1 | h)
#>
#> [[2]]
#> us(1 | g)
#>
#> [[3]]
#> us(0 + x | g)
#>
#> [[4]]
#> us(0 + y | g)
#>
findbars_x(~ 1 + (1|Subject))
#> [[1]]
#> us(1 | Subject)
#>
findbars_x(~ (1||Subject))
#> [[1]]
#> diag(1 | Subject)
#>
findbars_x(~ (1|Subject))
#> [[1]]
#> us(1 | Subject)
#>
findbars_x(~ (1|Subject), default.special = NULL)
#> [[1]]
#> 1 | Subject
#>
findbars_x(~ 1 + x)
#> NULL
findbars_x(~ s(x, bs = "tp"))
#> NULL
findbars_x(y ~ a + log(b) + s(x, bs = "tp") + s(y, bs = "gp"),
target = "s", default.special = NULL)
#> [[1]]
#> s(x, bs = "tp")
#>
#> [[2]]
#> s(y, bs = "gp")
#>
inForm(z~.,quote(.))
#> [1] TRUE
inForm(z~y,quote(.))
#> [1] FALSE
inForm(z~a+b+c,quote(c))
#> [1] TRUE
inForm(z~a+b+(d+e),quote(c))
#> [1] FALSE
f <- ~ a + offset(x)
f2 <- z ~ a
inForm(f,quote(offset))
#> [1] TRUE
inForm(f2,quote(offset))
#> [1] FALSE
extractForm(~a+offset(b),quote(offset))
#> [[1]]
#> offset(b)
#>
extractForm(~c,quote(offset))
#> NULL
extractForm(~a+offset(b)+offset(c),quote(offset))
#> [[1]]
#> offset(b)
#>
#> [[2]]
#> offset(c)
#>
extractForm(~offset(x),quote(offset))
#> [[1]]
#> offset(x)
#>
dropHead(~a+offset(b),quote(offset))
#> a + b
dropHead(~a+poly(x+z,3)+offset(b),quote(offset))
#> a + poly(x + z, 3) + b
drop.special(x~a + b+ offset(z))
#> x ~ a + b
#> <environment: 0x56443f2a6610>
replaceForm(quote(a(b+x*c(y,z))),quote(y),quote(R))
#> a(b + x * c(R, z))
ss <- ~(1 | cask:batch) + (1 | batch)
replaceForm(ss,quote(cask:batch),quote(batch:cask))
#> ~(1 | batch:cask) + (1 | batch)
replaceForm(ss, quote(`:`), quote(`%:%`))
#> ~(1 | cask %:% batch) + (1 | batch)