Learn R Programming

Boom (version 0.9.15)

sufstat.Rd: Sufficient Statistics

Description

Sufficient statistics for various models.

Usage

RegressionSuf(X = NULL,
                y = NULL,
                xtx = crossprod(X),
                xty = crossprod(X, y),
                yty = sum(y^2),
                n = length(y),
                xbar = colMeans(X),
                ybar = mean(y))

GaussianSuf(y)

Value

The returned value is a function containing the sufficient statistics for a regression model. Arguments are checked to ensure they have legal values. List names match the names expected by underlying C++ code.

Arguments

X

The predictor matrix for a regression problem.

y

The data, or the regression response variable.

xtx

The cross product of the design matrix. "X transpose X."

xty

The cross product of the design matrix with the response vector. "X transpose y."

yty

The sum of the squares of the response vector. "y transpose y."

n

The sample size.

xbar

A vector giving the average of each column in the predictor matrix.

ybar

The (scalar) mean of the response variable y.

Author

Steven L. Scott steve.the.bayesian@gmail.com

Examples

Run this code

  X <- cbind(1, matrix(rnorm(3 * 100), ncol = 3))
  y <- rnorm(100)

  ## Sufficient statistics can be computed from raw data, if it is
  ## available.
  suf1 <- RegressionSuf(X, y)

  ## The individual components can also be computed elsewhere, and
  ## provided as arguments.  If n is very large, this can be a
  ## substantial coomputational savings.
  suf2 <- RegressionSuf(xtx = crossprod(X),
                        xty = crossprod(X, y),
                        yty = sum(y^2),
                        n = 100,
                        xbar = colMeans(X))

Run the code above in your browser using DataLab