Create formula is a tool to automatically create a formula object from a provided variable and output names. Reduces the time required to manually input variables for modeling. Output can be used in linear regression, random forest, neural network etc. Create formula becomes useful when modeling data with multiple features. Reduces the time required for modeling and implementation :
create.formula( outcome.name, input.names = NULL, input.patterns = NULL, dat = NULL, interactions = NULL, force.main.effects = TRUE, reduce = FALSE, max.input.categories = 20, max.outcome.categories.to.search = 4, order.as = "as.specified", include.backtick = "as.needed", format.as = "formula", variables.to.exclude = NULL, include.intercept = TRUE )
outcome.name | A character value specifying the name of the formula's outcome variable. In this version, only a single outcome may be ed. The first entry of outcome.name will be used to build the formula. |
---|---|
input.names | The names of the variables with the full names delineated. User can specify '.' or 'all' to e all the column variables. |
input.patterns | es additional input variables. The user may enter patterns -- e.g. to e every variable with a name that es the pattern. Multiple patterns may be ed as a character vector. However, each pattern may not contain spaces and is otherwise subject to the same limits on patterns as used in the grep function. |
dat | User can specify a data.frame object that will be used to remove any variables that are not listed in names(dat. As default it is set as NULL. In this case, the formula is created simply from the outcome.name and input.names. |
interactions | A list of character vectors. Each character vector es the names of the variables that form a single interaction. Specifying interactions = list(c("x", "y"), c("x", "z"), c("y", "z"), c("x", "y", "z")) would lead to the interactions x*y + x*z + y*z + x*y*z. |
force.main.effects | This is a logical value. When TRUE, the intent is that any term ed as an interaction (of multiple variables) must also be listed individually as a main effect. |
reduce | A logical value. When dat is not NULL and reduce is TRUE, additional quality checks are performed to examine the input variables. Any input variables that exhibit a lack of contrast will be excluded from the model. This search is global by default but may be conducted separately in subsets of the outcome variables by specifying max.outcome.categories.to.search. Additionally, any input variables that exhibit too many contrasts, as defined by max.input.categories, will also be excluded. |
max.input.categories | Limits the maximum number of variables that will be employed in the formula. As default it is set at 20, but users can still change at his/her convenience. |
max.outcome.categories.to.search | A numeric value. The create.formula function es a feature that identifies input variables exhibiting a lack of contrast. When reduce = TRUE, these variables are automatically excluded from the resulting formula. This search may be expanded to subsets of the outcome when the number of unique measured values of the outcome is no greater than max.outcome.categories.to.search. In this case, each subset of the outcome will be separately examined, and any inputs that exhibit a lack of contrast within at least one subset will be excluded. |
order.as | User can specify the order the input variables in the formula in a variety of ways for patterns: increasing for increasing alphabet order, decreasing for decreasing alphabet order, column.order for as they appear in data, and as.specified for maintaining the user's specified order. |
include.backtick | Add backticks if needed. As default it is set as 'as.needed', which add backticks when only it is needed. The other option is 'all'. The use of include.backtick = "all" is limited to cases in which the output is generated as a character variable. When the output is generated as a formula object, then R automatically removes all unnecessary backticks. That is, it is only compatible when format.as != formula. |
format.as | The data type of the output. If not set as "formula", then a character vector will be returned. |
variables.to.exclude | A character vector. Any variable specified in variables.to.exclude will be dropped from the formula, both in the individual inputs and in any associated interactions. This step supersedes the inclusion of any variables specified for inclusion in the other parameters. |
include.intercept | A logical value. When FALSE, the intercept will be removed from the formula. |
Return as the data type of the output. If not set as "formula", then a character vector will be returned. The input.names and names of variables matching the input.patterns will be concatenated to form the full list of input variables.
n <- 10 dd <- data.table::data.table(w = rnorm(n= n), x = rnorm(n = n), pixel_1 = rnorm(n = n)) dd[, pixel_2 := 0.3 * pixel_1 + rnorm(n)]#> w x pixel_1 pixel_2 #> 1: -1.400043517 -0.55369938 0.46815442 1.0758095 #> 2: 0.255317055 0.62898204 0.36295126 0.2853740 #> 3: -2.437263611 2.06502490 -1.30454355 -0.1476776 #> 4: -0.005571287 -1.63098940 0.73777632 1.8448818 #> 5: 0.621552721 0.51242695 1.88850493 0.6785896 #> 6: 1.148411606 -1.86301149 -0.09744510 -0.1632305 #> 7: -1.821817661 -0.52201251 -0.93584735 -2.1908417 #> 8: -0.247325302 -0.05260191 -0.01595031 -0.2840223 #> 9: -0.244199607 0.54299634 -0.82678895 -0.5614827 #> 10: -0.282705449 -0.91407483 -1.51239965 0.6135880#> w x pixel_1 pixel_2 y #> 1: -1.400043517 -0.55369938 0.46815442 1.0758095 0.8576202 #> 2: 0.255317055 0.62898204 0.36295126 0.2853740 4.1653886 #> 3: -2.437263611 2.06502490 -1.30454355 -0.1476776 6.0661737 #> 4: -0.005571287 -1.63098940 0.73777632 1.8448818 -2.5033379 #> 5: 0.621552721 0.51242695 1.88850493 0.6785896 10.0296258 #> 6: 1.148411606 -1.86301149 -0.09744510 -0.1632305 -7.1784363 #> 7: -1.821817661 -0.52201251 -0.93584735 -2.1908417 -9.7527566 #> 8: -0.247325302 -0.05260191 -0.01595031 -0.2840223 -0.3011961 #> 9: -0.244199607 0.54299634 -0.82678895 -0.5614827 -0.7701556 #> 10: -0.282705449 -0.91407483 -1.51239965 0.6135880 -9.7921176#> $formula #> y ~ x + pixel_1 + pixel_2 #> <environment: 0x000000001904d188> #> #> $inclusion.table #> variable exclude.null.quantity class order specified.from #> 1: x FALSE numeric 1 input.names #> 2: pixel_1 FALSE numeric 2 input.patterns #> 3: pixel_2 FALSE numeric 3 input.patterns #> exclude.user.specified exclude.matches.outcome.name include.variable #> 1: FALSE FALSE TRUE #> 2: FALSE FALSE TRUE #> 3: FALSE FALSE TRUE #> #> $interactions.table #> Empty data.table (0 rows and 2 cols): interactions,include.interaction #>