Learn R Programming

mosaic (version 0.5-1)

project: Projections

Description

Compute projections onto the span of a vector or a model space.

Usage

project(x, u, data, ...)

## S3 method for class 'formula,ANY': project( x, u=NULL, data=parent.frame(), ...)

## S3 method for class 'numeric,ANY': project(x, u = rep(1, length(x)), type = c("vector", "length"), ...)

## S3 method for class 'matrix,ANY': project(x, u, data=parent.frame())

Arguments

x
a vector or formula. Left-hand sides of formulas should be a single quantity
u
a vector
data
a data frame.
type
one of length or vector determining the type of the returned value
...
additional arguments

Value

  • project returns the projection of x onto u (or its length if u and v are numeric vectors and type == "length")

Details

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.

Examples

Run this code
a <- c(1,0,0); b <- c(1,2,3); c <- c(4,5,6); x <- rnorm(3)
# 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')
project(a~b)
project(width~length+sex, data=KidsFeet)
project(log(width) ~ I(length^2)+sin(length)+sex, data=KidsFeet)

Run the code above in your browser using DataLab