Sufficient statistics for various models.
RegressionSuf(X = NULL,
y = NULL,
xtx = crossprod(X),
xty = crossprod(X, y),
yty = sum(y^2),
n = length(y),
xbar = colMeans(X)) GaussianSuf(y)
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.
The predictor matrix for a regression problem.
The data, or the regression response variable.
The cross product of the design matrix. "X transpose X."
The cross product of the design matrix with the response vector. "X transpose y."
The sum of the squares of the response vector. "y transpose y."
The sample size.
A vector giving the average of each column in the predictor matrix.
Steven L. Scott steve.the.bayesian@gmail.com
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