Last chance! 50% off unlimited learning
Sale ends in
project(x, u, ...) singvals(A, data = parent.frame())
dot(u, v)
mat
and singvals
,
only the right-hand side is used. In project
, both
sides are used, but the left-hand side should be a single
quantitymat
returns a matrix singvals
gives singular values for each column in
the model matrix
project
returns the projection of x
onto
u
(or its length if u
and v
are
numeric vectors and type == "length"
)
dot
returns the dot product of u
and
v
project
(preferably pronounced
"PRO-ject" as in "projection") does either of two related
things: (1) Given two vectors as arguments, it will
project the first onto the second, returning the point in
the subspace of the second that is as close as possible
to the first vector. (2) Given a formula as an argument,
will work very much like lm()
, constructing a
model matrix from the right-hand side of the formula and
projecting the vector on the left-hand side onto the
subspace of that model matrix. In (2), rather than
returning the projected vector, project()
returns
the coefficients on each of the vectors in the model
matrix. UNLIKE lm()
, the intercept vector is NOT
included by default. If you want an intercept vector,
include +1
in your formula. mat
returns a model matrix
To demonstrate singularity, use singvals
.
linearModel
, which returns a function.a <- c(1,0,0); b <- c(1,2,3); c <- c(4,5,6); x <- rnorm(3)
dot(b,c) # dot product
# projection onto the 1 vector gives the mean vector
mean(x)
project(x, 1)
# return the length of the vector, rather than the vector itself
project(x, 1, type='length')
# Formula interface
mat(~a+b)
mat(~a+b+1)
mat(~length+sex, data=KidsFeet)
project(a~b)
project(width~length+sex, data=KidsFeet)
project(log(width) ~ I(length^2)+sin(length)+sex, data=KidsFeet)
singvals(~length*sex*width, data=KidsFeet)
Run the code above in your browser using DataLab