View source: R/FormulaSelection.R
FormulaSelection.default | R Documentation |
For use with output from ModelMatrix
or data frames derived from such output.
It is a generic function which means that methods for other input objects can be added.
## Default S3 method:
FormulaSelection(x, formula, intercept = NA, logical = FALSE)
FormulaSelection(x, formula, intercept = NA, logical = FALSE)
formula_selection(x, formula, intercept = NA, logical = FALSE)
x |
Model matrix or a data frame |
formula |
Formula representing the limitation or character string(s) to be converted to a formula (see details) |
intercept |
Parameter that specifies whether a possible intercept term (overall total) should be included in the output.
Default is |
logical |
When |
The selection is based on startCol
or startRow
attribute in input x
.
With formula as character:
~
is included:
Input is converted by as.formula
and default intercept is TRUE
.
~
is not included:
Internally, input data is converted to a formula by adding ~
and possibly +
's when the length is >1
.
Default intercept is FALSE
unless "1"
or "(Intercept)"
(is changed internally to "1"
) is included.
Limited model matrix or a data frame
formula_selection
and FormulaSelection
are identical
z <- SSBtoolsData("sprt_emp_withEU")
z$age[z$age == "Y15-29"] <- "young"
z$age[z$age == "Y30-64"] <- "old"
x <- ModelMatrix(z, formula = ~age * year)
FormulaSelection(x, "age")
FormulaSelection(x, ~year)
FormulaSelection(x, ~year:age)
# x1, x2, x3, x4 and x4 are identical
x1 <- FormulaSelection(x, ~age)
x2 <- FormulaSelection(x, "~age")
x3 <- FormulaSelection(x, "age", intercept = TRUE)
x4 <- FormulaSelection(x, c("1", "age"))
x5 <- FormulaSelection(x, c("(Intercept)", "age"))
a <- ModelMatrix(z, formula = ~age * geo + year, crossTable = TRUE)
b <- cbind(as.data.frame(a$crossTable),
sum = (t(a$modelMatrix) %*% z$ths_per)[, 1],
max = DummyApply(a$modelMatrix,
z$ths_per, max))
rownames(b) <- NULL
attr(b, "startRow") <- attr(a$modelMatrix, "startCol", exact = TRUE)
FormulaSelection(b, ~geo * age)
FormulaSelection(b, "age:geo")
FormulaSelection(b, ~year - 1)
FormulaSelection(b, ~geo:age, logical = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.