as.basis | R Documentation |
Convert a formula or factor to basis functions
as.basis(object, ...) ## S3 method for class 'formula' as.basis(object, data = NULL, remove_intercept = FALSE, ui = NULL, ci = NULL, negative = FALSE, scale = FALSE, Matrix = FALSE, prefix = "", ...) ## S3 method for class 'factor_var' as.basis(object, ...) ## S3 method for class 'ordered_var' as.basis(object, ...) ## S3 method for class 'factor' as.basis(object, ...) ## S3 method for class 'ordered' as.basis(object, ...)
object |
a formula or an object of class |
data |
either a |
remove_intercept |
a logical indicating if any intercept term shall be removed |
ui |
a matrix defining constraints |
ci |
a vector defining constraints |
negative |
a logical indicating negative basis functions |
scale |
a logical indicating a scaling of each column of the
model matrix to the unit interval (based on observations in |
Matrix |
a logical requesting a sparse model matrix, that is, a
|
prefix |
character prefix for model matrix column names (allows disambiguation of parameter names). |
... |
additional arguments to |
as.basis
returns a function for the evaluation of
the basis functions with corresponding model.matrix
and predict
methods.
Unordered factors (classes factor
and factor_var
) use a dummy coding and
ordered factor (classes ordered
or ordered_var
) lead to a treatment contrast
to the last level and removal of the intercept term with monotonicity constraint.
Additional arguments (...
) are ignored for ordered factors.
Linear constraints on parameters parm
are defined by ui %*% parm >= ci
.
## define variables and basis functions v <- c(numeric_var("x"), factor_var("y", levels = LETTERS[1:3])) fb <- as.basis(~ x + y, data = v, remove_intercept = TRUE, negative = TRUE, contrasts.arg = list(y = "contr.sum")) ## evaluate basis functions model.matrix(fb, data = as.data.frame(v, n = 10)) ## basically the same as (but wo intercept and times -1) model.matrix(~ x + y, data = as.data.frame(v, n = 10)) ### factor xf <- gl(3, 1) model.matrix(as.basis(xf), data = data.frame(xf = xf)) ### ordered xf <- gl(3, 1, ordered = TRUE) model.matrix(as.basis(xf), data = data.frame(xf = unique(xf)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.