These functions provide a formula based interface to the construction of matrices from data and for fitting. You can use them both for numerical vectors and for functions of variables in data frames. These functions are intended to support teaching basic linear algebra with a particular connection to statistics.

mat(formula, data = parent.frame(), A = formula)

singvals(formula, data = parent.frame(), A = formula)

Arguments

formula

a formula. In mat and singvals, only the right-hand side is used.

data

a data frame from which to pull out numerical values for the variables in the formula

A

an alias for formula for backward compatibility.

mat returns a model matrix

To demonstrate singularity, use singvals.

Value

mat returns a matrix

singvals gives singular values for each column in the model matrix

See also

project()

linearModel(), which returns a function.

Examples

a <- c(1,0,0); b <- c(1,2,3); c <- c(4,5,6); x <- rnorm(3)
# Formula interface
mat(~a+b)
#>      a b
#> [1,] 1 1
#> [2,] 0 2
#> [3,] 0 3
mat(~a+b+1)
#>      (Intercept) a b
#> [1,]           1 1 1
#> [2,]           1 0 2
#> [3,]           1 0 3
if (require(mosaicData)) {
mat(~length+sex, data=KidsFeet)
singvals(~length*sex*width, data=KidsFeet)
}
#> [1] 1.574862e+03 6.256393e+02 9.268586e+00 3.460037e+00 2.539537e+00
#> [6] 9.789860e-01 1.240576e-02 7.446299e-03