| Title: | Scalable Model Averageing Kit |
|---|---|
| Description: | Supports frequentist model averaging on linear regression problems via the scalable method of Zhu et. al. (2022) <doi:10.1080/07350015.2022.2116442>. The scalable model averaging technique projects to singular vectors, performs one linear regression per singular vector, then combines the estimates to optimize either Mallows' criterion, or the jackknife estimate of error. |
| Authors: | Steven E. Pav [aut, cre] (ORCID: <https://orcid.org/0000-0002-4197-6195>) |
| Maintainer: | Steven E. Pav <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-10-24 11:27:16 UTC |
| Source: | https://github.com/cran/smak |
Augment a smam model.
## S3 method for class 'smam' augment(x, data = NULL, newdata = NULL, se_fit = FALSE, ...)## S3 method for class 'smam' augment(x, data = NULL, newdata = NULL, se_fit = FALSE, ...)
x |
an object of type |
data |
A base::data.frame or |
newdata |
A |
se_fit |
Logical indicating whether or not a |
... |
arguments for generic consistency. |
Returns a table with predicted fits from a SMA model.
An augmented data frame with added fields:
The fitted values of the regression model.
Steven E. Pav [email protected]
Extract Coefficients from smam
## S3 method for class 'smam' coef(object, ...)## S3 method for class 'smam' coef(object, ...)
object |
an object for which the extraction of model coefficients is meaningful. |
... |
Additional arguments passed to or from other methods |
A named numeric vector of coefficients.
Steven E. Pav [email protected]
Performs the model-free feature screening procedure of Zhu et al. for regression problems with many features.
sirs( y, X, thresholding = c("hard", "soft"), N = NULL, d_prop = 1, ties_pragma = c("ignore", "half_value") )sirs( y, X, thresholding = c("hard", "soft"), N = NULL, d_prop = 1, ties_pragma = c("ignore", "half_value") )
y |
vector of response data, of length |
X |
a |
thresholding |
the method for performing thresholding of the
|
N |
the number of variables to select for hard thresholding. Defaults
to |
d_prop |
for soft thresholding controls the number of noise variables
added to the set. We add |
ties_pragma |
the method for dealing with ties in the |
Performs a model-free screening procedure.
First each column of is z-scored to get zero mean unit variance
variables. Then the is computed for each of the columns of
against . The kth element of this vector is computed as
Then we select indices based on the values of this ,
based on the thresholding:
Select a fixed number of variates, based on the ordering of
.
Variates are selected if they are larger than the maximum of
computed on purely noise variates.
A sorted vector of the indices of which columns of X would be
selected, with values in .
Steven E. Pav [email protected]
Zhu, Liping, Li, Lexin, Li, Runze, and Zhu, Lixing. 2011. “Model-Free Feature Screening for Ultrahigh Dimensional Data." J Am Stat Assoc. 106 (496): 1464-1475. doi:10.1198/jasa.2011.tm10563.
set.seed(1234) X <- matrix(rnorm(200*500),ncol=500) beta <- 2 * round(rnorm(ncol(X), sd=0.2)) * runif(ncol(X)) sum(abs(beta) > 0) true_vars <- which(abs(beta) > 0) y <- rnorm(nrow(X), mean=X %*% beta) soft_vals <- sirs(y, X, thresholding='soft') all(soft_vals %in% true_vars) hard_vals <- sirs(y, X, thresholding='hard') all(true_vars %in% hard_vals)set.seed(1234) X <- matrix(rnorm(200*500),ncol=500) beta <- 2 * round(rnorm(ncol(X), sd=0.2)) * runif(ncol(X)) sum(abs(beta) > 0) true_vars <- which(abs(beta) > 0) y <- rnorm(nrow(X), mean=X %*% beta) soft_vals <- sirs(y, X, thresholding='soft') all(soft_vals %in% true_vars) hard_vals <- sirs(y, X, thresholding='hard') all(true_vars %in% hard_vals)
Scalable Model Averaging.
We consider the basic problem of regressing a scalar against a vector of
independent variables .
There is a long history of practitioners applying some form of variable selection to select
a subset of the vector to use in the regression modeling,
as a way to avoid overfitting and improve generalization to out-of-sample data.
Besides the intractability of testing all subsets of the variables in ,
variable selection is often a precursor to questionable statistical practice.
As an alternative to variable selection, Hjort and Claeskens introduced
Frequentist Model Averaging.
The idea behind FMA is to average together the regression coefficients
built on different subsets of the , with weights determined
typically by one of two methods, Mallows model averaging or Jackknife model averaging.
While FMA supplies a stronger theoretical basis than variable selection,
it does not solve the computational issues.
Enter _Scalable Model Averaging_.
Under this technique one first computes the singular value decomposition of the
matrix of observed independent variables, .
Then one performs regressions of the against each of the left singular values of the ,
then performs model averaging on only those regressions.
Zhu et al. show how to do this, and prove that the performance is equivalent
to the computationally intractable version run on all regressions.
This package implements that process of performing SVD then regression and weight selection. The regressions produce model fits, but not estimates of uncertainty of the coefficients or total model error. For that one would have to rely on, for example, bootstrapping.
smak is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
This package is maintained as a hobby.
Steven E. Pav [email protected]
Maintainer: Steven E. Pav [email protected] (ORCID)
Zhu, Rong, Haiying Wang, Xinyu Zhang, and Hua Liang. 2023. “A Scalable Frequentist Model Averaging Method.” Journal of Business & Economic Statistics 41 (4): 1228–37. doi:10.1080/07350015.2022.2116442.
Useful links:
News for package ‘smak’
first CRAN release.
A user friendly interface to the scalable frequentist model averaging regression procedure.
smam( formula, data, weights = NULL, na.action = na.omit, method = c("jackknife", "mallows"), ... ) ## S3 method for class 'smam' predict(object, newdata, na.action = na.pass, ...) ## S3 method for class 'smam' print(x, ...)smam( formula, data, weights = NULL, na.action = na.omit, method = c("jackknife", "mallows"), ... ) ## S3 method for class 'smam' predict(object, newdata, na.action = na.pass, ...) ## S3 method for class 'smam' print(x, ...)
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
weights |
an optional vector of weights, or the string or bare name of the
weights in the |
na.action |
How to deal with missing values in |
method |
the method to be used; for fitting, currently only
|
... |
other arguments. |
object |
Object of class inheriting from |
newdata |
a |
x |
an object used to select a method. |
Performs the scalable model averaging procedure to estimate linear
regression of against .
We find vector of coefficients such that is
approximately equal to .
An object of class smam.
Steven E. Pav [email protected]
nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) y <- rnorm(nrow(X), mean=X %*% beta, sd=1) # now the pretty frontend data <- cbind(data.frame(outcome=y),as.data.frame(X)) fmla <- outcome ~ V1 + V2 + V3 + V4 + V5 fitm <- smam(fmla,data) # with weights data$wts <- runif(nrow(data),min=1,max=2) fitw <- smam(fmla,data,weights=wts)nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) y <- rnorm(nrow(X), mean=X %*% beta, sd=1) # now the pretty frontend data <- cbind(data.frame(outcome=y),as.data.frame(X)) fmla <- outcome ~ V1 + V2 + V3 + V4 + V5 fitm <- smam(fmla,data) # with weights data$wts <- runif(nrow(data),min=1,max=2) fitw <- smam(fmla,data,weights=wts)
Auxiliary function for smam fitting.
smam.control( wide_pragma = c("SIRS", "SIRSu", "alpha", "fixed_k", "error"), tall_pragma = c("tolerance", "none"), alpha = 0.99, k = 100 )smam.control( wide_pragma = c("SIRS", "SIRSu", "alpha", "fixed_k", "error"), tall_pragma = c("tolerance", "none"), alpha = 0.99, k = 100 )
wide_pragma |
what to do if X has more columns than rows, see Details. |
tall_pragma |
what to do if X has as many rows as columns or more, see Details. |
alpha |
the |
k |
the number of singular values kept for the “fixed_k” wide pragma. |
The control argument of smam is by default
passed to the control argument of smamfit, which uses its
selements as arguments to smam.control: the latter provides
defaults and sanity checking.
The wide pragma controls how fitting deals with wide matrices .
Implements the SIRS procedure of Zhu et al. on .
Implements the SIRS procedure on the left singular values
.
Performs SVD, then keeps the singular values that account for
at least of the total sum of singular values. Always keeps at
least one column, however.
Keep a fixed number of singular values.
Throws an error.
The tall pragma controls how fitting deals with tall matrices .
Takes all singular values.
Keeps singular values up to machine epsilon ratio to the largest singular value.
A list.
Steven E. Pav [email protected]
Zhu, Rong, Haiying Wang, Xinyu Zhang, and Hua Liang. 2023. “A Scalable Frequentist Model Averaging Method.” Journal of Business & Economic Statistics 41 (4): 1228–37. doi:10.1080/07350015.2022.2116442.
Zhu, Liping, Li, Lexin, Li, Runze, and Zhu, Lixing. 2011. “Model-Free Feature Screening for Ultrahigh Dimensional Data." J Am Stat Assoc. 106 (496): 1464-1475. doi:10.1198/jasa.2011.tm10563.
Fits the scalable model averaging model to a regression problem.
smamfit( y, X, method = c("jackknife", "mallows"), wt = NULL, sigma2 = NULL, Xnames = NULL, return.U = FALSE, return.X = TRUE, return.fitted = TRUE, control = list(...), formula = NULL, ... )smamfit( y, X, method = c("jackknife", "mallows"), wt = NULL, sigma2 = NULL, Xnames = NULL, return.U = FALSE, return.X = TRUE, return.fitted = TRUE, control = list(...), formula = NULL, ... )
y |
vector of response data, of length |
X |
a |
method |
the selection method for the weights, either Jackknife model averaging or Mallows' model averaging. |
wt |
an optional vector of length |
sigma2 |
an optional squared variance to be used in Mallows' model averaging. If not given, estimated from the data. |
Xnames |
an optional vector of the names of the columns of X. If null
or not given, defaults to |
return.U |
a Boolean for whether the matrix U should be returned in the output. |
return.X |
a Boolean for whether the matrix X should be returned in the output. |
return.fitted |
a Boolean for whether the yhat fitted values should be returned in the output. |
control |
a list of parameters for controlling the the fitting process.
This is passed to |
formula |
an optional formula which will be saved in the object for prediction step later. |
... |
other arguments, which are essentially passed on to |
Finds a vector of coefficients such that is
approximately equal to . Does this by computing a singular
value decomposition of , then performs linear regressions
of the column of the left singular vectors against , then
takes a weighted combination of those.
Supports both the Mallows Model Averaging and Jackknife Model Averaging approaches.
An object of class smam.
smak is free software.
Steven E. Pav [email protected]
Zhu, Rong, Haiying Wang, Xinyu Zhang, and Hua Liang. 2023. “A Scalable Frequentist Model Averaging Method.” Journal of Business & Economic Statistics 41 (4): 1228–37. doi:10.1080/07350015.2022.2116442.
the friendly interface smam.
nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) eta <- X %*% beta y <- rnorm(nrow(X), mean=X %*% beta, sd=1) mod0 <- smamfit(y=y,X=X) summary(mod0)nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) eta <- X %*% beta y <- rnorm(nrow(X), mean=X %*% beta, sd=1) mod0 <- smamfit(y=y,X=X) summary(mod0)
Tidy a smam model.
## S3 method for class 'smam' tidy(x, ...)## S3 method for class 'smam' tidy(x, ...)
x |
an object of type |
... |
arguments for generic consistency. |
Returns a table with information on the fit coefficients from the scalable model averaging model. At the moment, no standard errors are computed.
A tidy data frame with fields
The name of the estimated parameter. Betas typically come before gammas.
The estimated parameter.
Steven E. Pav [email protected]
nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) eta <- X %*% beta y <- rnorm(nrow(X), mean=X %*% beta, sd=1) mod0 <- smamfit(y=y,X=X) print(tidy(mod0))nobs <- 100 nfeat <- 5 set.seed(1234) X <- matrix(rnorm(nobs * nfeat),ncol=nfeat) beta <- rnorm(nfeat) eta <- X %*% beta y <- rnorm(nrow(X), mean=X %*% beta, sd=1) mod0 <- smamfit(y=y,X=X) print(tidy(mod0))