Return all possible model subsets based on specified model scopes.

e_model_all_subsets_formula(
  x_var_names = NULL,
  y_var_name = NULL,
  var_formula = NULL,
  max_scope = c("always", "FO", "TWI", "PQ", "SO", "one_TWI", "only_TWI", "only_PQ",
    "only_SO", "only_one_TWI")[3],
  sw_return = c("both", "formula", "table")[1]
)

Arguments

x_var_names

a character list of variable names or list of character lists. If a list of multiple formulas or character lists is provided, then each is subject to the max_scope independently, or each can have it's own max_scope.

y_var_name

a character string

var_formula

NOT YET IMPLEMENTED

max_scope

one of or a list (corresponding to x_var_names) of "always" to always keep this full list (no binary subsets), "FO" for first-order (main) effects, "TWI" for two-way interactions, "PQ" for pure quadratic terms (squares of the "FO"), "SO" for all terms in "FO", "TWI", and "PQ", and "one_TWI" for two-way interactions with only the first in the list. The options that start with "only_" must be used with the same x_var_names variables as a subset in an "always" list. For example, c("a", "b") specified as both "always" and "only_TWI" will always keep the main effects performing selection only on the TWIs.

sw_return

return a list of "formula", or a "table" of x-variable combinations, or a list of "both"

Value

         a list of functions

Examples

# Two-way interaction model, return formulas
e_model_all_subsets_formula(
    x_var_names = c("a", "b", "c")
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = "TWI"
  , sw_return   = c("both", "formula", "table")[2]
  )
#> [[1]]
#> z ~ 1
#> <environment: 0x000001b768c361f0>
#> 
#> [[2]]
#> z ~ a
#> <environment: 0x000001b768c30000>
#> 
#> [[3]]
#> z ~ b
#> <environment: 0x000001b768c4df68>
#> 
#> [[4]]
#> z ~ a + b
#> <environment: 0x000001b768c59e78>
#> 
#> [[5]]
#> z ~ a + b + a:b
#> <environment: 0x000001b768c69d00>
#> 
#> [[6]]
#> z ~ c
#> <environment: 0x000001b768856838>
#> 
#> [[7]]
#> z ~ a + c
#> <environment: 0x000001b76886e7a8>
#> 
#> [[8]]
#> z ~ a + c + a:c
#> <environment: 0x000001b768864560>
#> 
#> [[9]]
#> z ~ b + c
#> <environment: 0x000001b76887e2e8>
#> 
#> [[10]]
#> z ~ b + c + b:c
#> <environment: 0x000001b768893ea0>
#> 
#> [[11]]
#> z ~ a + b + c
#> <environment: 0x000001b7688901b0>
#> 
#> [[12]]
#> z ~ a + b + c + a:b
#> <environment: 0x000001b7688ac4f8>
#> 
#> [[13]]
#> z ~ a + b + c + a:c
#> <environment: 0x000001b7688c0720>
#> 
#> [[14]]
#> z ~ a + b + c + a:b + a:c
#> <environment: 0x000001b7688b6858>
#> 
#> [[15]]
#> z ~ a + b + c + b:c
#> <environment: 0x000001b7688da790>
#> 
#> [[16]]
#> z ~ a + b + c + a:b + b:c
#> <environment: 0x000001b7688e2958>
#> 
#> [[17]]
#> z ~ a + b + c + a:c + b:c
#> <environment: 0x000001b7688e69b0>
#> 
#> [[18]]
#> z ~ a + b + c + a:b + a:c + b:c
#> <environment: 0x000001b768902ac8>
#> 
# Two-way interaction model, return table of x-variable combinations
e_model_all_subsets_formula(
    x_var_names = c("a", "b", "c")
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = "TWI"
  , sw_return   = c("both", "formula", "table")[3]
  )
#>    a b c  a:b  a:c  b:c
#> 1        <NA> <NA> <NA>
#> 2  a     <NA> <NA> <NA>
#> 3    b   <NA> <NA> <NA>
#> 4  a b        <NA> <NA>
#> 5  a b    a:b <NA> <NA>
#> 6      c <NA> <NA> <NA>
#> 7  a   c <NA>      <NA>
#> 8  a   c <NA>  a:c <NA>
#> 9    b c <NA> <NA>     
#> 10   b c <NA> <NA>  b:c
#> 11 a b c               
#> 12 a b c  a:b          
#> 13 a b c       a:c     
#> 14 a b c  a:b  a:c     
#> 15 a b c            b:c
#> 16 a b c  a:b       b:c
#> 17 a b c       a:c  b:c
#> 18 a b c  a:b  a:c  b:c

# Two variables always in the model with a second-order model of two others
e_model_all_subsets_formula(
    x_var_names = list(c("a", "b"), c("c", "d"))
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = list("always", "SO")
  , sw_return   = c("both", "formula", "table")[3]
  )
#>    a b c d I(c^2) I(d^2)  c:d
#> 1  a b       <NA>   <NA> <NA>
#> 2  a b c            <NA> <NA>
#> 3  a b c   I(c^2)   <NA> <NA>
#> 4  a b   d   <NA>        <NA>
#> 5  a b   d   <NA> I(d^2) <NA>
#> 6  a b c d                   
#> 7  a b c d                c:d
#> 8  a b c d I(c^2)            
#> 9  a b c d I(c^2)         c:d
#> 10 a b c d        I(d^2)     
#> 11 a b c d        I(d^2)  c:d
#> 12 a b c d I(c^2) I(d^2)     
#> 13 a b c d I(c^2) I(d^2)  c:d
# One variable in two-way interactions with the other variables
e_model_all_subsets_formula(
    x_var_names = list(c("a", "b", "c", "d"))
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = list("one_TWI")
  , sw_return   = c("both", "formula", "table")[3]
  )
#>    a b c d  a:b  a:c  a:d
#> 1  a       <NA> <NA> <NA>
#> 2  a b          <NA> <NA>
#> 3  a b      a:b <NA> <NA>
#> 4  a   c   <NA>      <NA>
#> 5  a   c   <NA>  a:c <NA>
#> 6  a b c             <NA>
#> 7  a b c    a:b      <NA>
#> 8  a b c         a:c <NA>
#> 9  a b c    a:b  a:c <NA>
#> 10 a     d <NA> <NA>     
#> 11 a     d <NA> <NA>  a:d
#> 12 a b   d      <NA>     
#> 13 a b   d  a:b <NA>     
#> 14 a b   d      <NA>  a:d
#> 15 a b   d  a:b <NA>  a:d
#> 16 a   c d <NA>          
#> 17 a   c d <NA>  a:c     
#> 18 a   c d <NA>       a:d
#> 19 a   c d <NA>  a:c  a:d
#> 20 a b c d               
#> 21 a b c d  a:b          
#> 22 a b c d       a:c     
#> 23 a b c d  a:b  a:c     
#> 24 a b c d            a:d
#> 25 a b c d  a:b       a:d
#> 26 a b c d       a:c  a:d
#> 27 a b c d  a:b  a:c  a:d
# Four variables always in the model (a, b, c, d)
#   with selection only on the two second-order variables (c, d),
#   with TWI on the two variables (e, f)
e_model_all_subsets_formula(
    x_var_names = list(c("a", "b", "c", "d"), c("c", "d"), c("e", "f"))
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = list("always", "only_SO", "TWI")
  , sw_return   = c("both", "formula", "table")[3]
  )
#>    a b c d c:d I(c^2) I(d^2) e f  e:f
#> 1  a b c d                       <NA>
#> 2  a b c d c:d                   <NA>
#> 3  a b c d     I(c^2)            <NA>
#> 4  a b c d c:d I(c^2)            <NA>
#> 5  a b c d            I(d^2)     <NA>
#> 6  a b c d c:d        I(d^2)     <NA>
#> 7  a b c d     I(c^2) I(d^2)     <NA>
#> 8  a b c d c:d I(c^2) I(d^2)     <NA>
#> 9  a b c d                   e   <NA>
#> 10 a b c d c:d               e   <NA>
#> 11 a b c d     I(c^2)        e   <NA>
#> 12 a b c d c:d I(c^2)        e   <NA>
#> 13 a b c d            I(d^2) e   <NA>
#> 14 a b c d c:d        I(d^2) e   <NA>
#> 15 a b c d     I(c^2) I(d^2) e   <NA>
#> 16 a b c d c:d I(c^2) I(d^2) e   <NA>
#> 17 a b c d                     f <NA>
#> 18 a b c d c:d                 f <NA>
#> 19 a b c d     I(c^2)          f <NA>
#> 20 a b c d c:d I(c^2)          f <NA>
#> 21 a b c d            I(d^2)   f <NA>
#> 22 a b c d c:d        I(d^2)   f <NA>
#> 23 a b c d     I(c^2) I(d^2)   f <NA>
#> 24 a b c d c:d I(c^2) I(d^2)   f <NA>
#> 25 a b c d                   e f     
#> 26 a b c d c:d               e f     
#> 27 a b c d     I(c^2)        e f     
#> 28 a b c d c:d I(c^2)        e f     
#> 29 a b c d            I(d^2) e f     
#> 30 a b c d c:d        I(d^2) e f     
#> 31 a b c d     I(c^2) I(d^2) e f     
#> 32 a b c d c:d I(c^2) I(d^2) e f     
#> 33 a b c d                   e f  e:f
#> 34 a b c d c:d               e f  e:f
#> 35 a b c d     I(c^2)        e f  e:f
#> 36 a b c d c:d I(c^2)        e f  e:f
#> 37 a b c d            I(d^2) e f  e:f
#> 38 a b c d c:d        I(d^2) e f  e:f
#> 39 a b c d     I(c^2) I(d^2) e f  e:f
#> 40 a b c d c:d I(c^2) I(d^2) e f  e:f
if (FALSE) {
# Large example showing all options
e_model_all_subsets_formula(
    x_var_names = list(letters[1:2], letters[4:5], letters[7:8], letters[10:11], letters[13:14])
  , y_var_name  = "z"
  , var_formula = NULL
  , max_scope   = list("always", "FO", "TWI", "PQ", "SO")
  , sw_return   = c("both", "formula", "table")[3]
  )
}