splitForm: Combine right-hand sides of an arbitrary number of formulas

Description Usage Arguments Details Value Author(s) Examples

Description

Parse a formula into fixed formula and random effect terms, treating 'special' terms (of the form foo(x|g[,m])) appropriately

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
addForm(...)

splitForm(
  formula,
  defaultTerm = "us",
  allowFixedOnly = TRUE,
  allowNoSpecials = TRUE,
  debug = FALSE
)

noSpecials(term, delete = TRUE, debug = FALSE)

Arguments

...

arguments to pass through to addForm0

formula

a formula containing special random effect terms

defaultTerm

default type for non-special RE terms

allowFixedOnly

(logical) are formulas with no RE terms OK?

allowNoSpecials

(logical) are formulas with only standard RE terms OK?

debug

debugging mode (print stuff)?

term

language object

Details

Taken from Steve Walker's lme4ord, ultimately from the flexLambda branch of lme4 <https://github.com/stevencarlislewalker/lme4ord/blob/master/R/formulaParsing.R>. Mostly for internal use.

Value

a list containing elements fixedFormula; reTrmFormulas list of x | g formulas for each term; reTrmAddArgs list of function+additional arguments, i.e. list() (non-special), foo() (no additional arguments), foo(addArgs) (additional arguments); reTrmClasses (vector of special functions/classes, as character)

Author(s)

Steve Walker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
splitForm(~x+y)                     ## no specials or RE
splitForm(~x+y+(f|g))               ## no specials
splitForm(~x+y+diag(f|g))           ## one special
splitForm(~x+y+(diag(f|g)))         ## 'hidden' special
splitForm(~x+y+(f|g)+cs(1|g))       ## combination
splitForm(~x+y+(1|f/g))             ## 'slash'; term
splitForm(~x+y+(1|f/g/h))             ## 'slash'; term
splitForm(~x+y+(1|(f/g)/h))             ## 'slash'; term
splitForm(~x+y+(f|g)+cs(1|g)+cs(a|b,stuff))  ## complex special
splitForm(~(((x+y))))               ## lots of parentheses
splitForm(~1+rr(f|g,n=2))

noSpecials(y~1+us(1|f))
noSpecials(y~1+us(1|f),delete=FALSE)
noSpecials(y~us(1|f))
noSpecials(y~us(1|f), delete=FALSE)
noSpecials(y~us(1|f), debug=TRUE)
noSpecials(y~us+1)  ## should *not* delete unless head of a function
noSpecials(~us+1)   ## should work on a one-sided formula!

Example output

$fixedFormula
~x + y

$reTrmFormulas
NULL

$reTrmAddArgs
NULL

$reTrmClasses
NULL

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
f | g


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()


$reTrmClasses
[1] "us"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
f | g


$reTrmAddArgs
$reTrmAddArgs[[1]]
diag()


$reTrmClasses
[1] "diag"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
f | g


$reTrmAddArgs
$reTrmAddArgs[[1]]
diag()


$reTrmClasses
[1] "diag"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
f | g

$reTrmFormulas[[2]]
1 | g


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()

$reTrmAddArgs[[2]]
cs()


$reTrmClasses
[1] "us" "cs"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
1 | f

$reTrmFormulas[[2]]
1 | f:g


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()

$reTrmAddArgs[[2]]
us()


$reTrmClasses
[1] "us" "us"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
1 | f

$reTrmFormulas[[2]]
1 | f:g

$reTrmFormulas[[3]]
1 | f:g:h


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()

$reTrmAddArgs[[2]]
us()

$reTrmAddArgs[[3]]
us()


$reTrmClasses
[1] "us" "us" "us"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
1 | f

$reTrmFormulas[[2]]
1 | f:g

$reTrmFormulas[[3]]
1 | f:g:h


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()

$reTrmAddArgs[[2]]
us()

$reTrmAddArgs[[3]]
us()


$reTrmClasses
[1] "us" "us" "us"

$fixedFormula
~x + y

$reTrmFormulas
$reTrmFormulas[[1]]
f | g

$reTrmFormulas[[2]]
1 | g

$reTrmFormulas[[3]]
$reTrmFormulas[[3]][[1]]
a | b



$reTrmAddArgs
$reTrmAddArgs[[1]]
us()

$reTrmAddArgs[[2]]
cs()

$reTrmAddArgs[[3]]
cs(stuff)


$reTrmClasses
[1] "us" "cs" "cs"

$fixedFormula
~(((x + y)))

$reTrmFormulas
NULL

$reTrmAddArgs
NULL

$reTrmClasses
NULL

$fixedFormula
~1

$reTrmFormulas
$reTrmFormulas[[1]]
f | g


$reTrmAddArgs
$reTrmAddArgs[[1]]
us()


$reTrmClasses
[1] "us"

y ~ 1
y ~ 1 + (1 | f)
y ~ 1
y ~ (1 | f)
y ~ us(1 | f)
[1] "not special"
y
us(1 | f)
y ~ 1
y ~ us + 1
~us + 1

glmmTMB documentation built on July 20, 2021, 9:06 a.m.