groupfs {selectiveInference} | R Documentation |
Select a model with forward stepwise.
Description
This function implements forward selection of linear models almost identically to step
with direction = "forward"
. The reason this is a separate function from fs
is that groups of variables (e.g. dummies encoding levels of a categorical variable) must be handled differently in the selective inference framework.
Usage
groupfs(x, y, index, maxsteps, sigma = NULL, k = 2, intercept = TRUE,
center = TRUE, normalize = TRUE, aicstop = 0, verbose = FALSE)
Arguments
x |
Matrix of predictors (n by p). |
y |
Vector of outcomes (length n). |
index |
Group membership indicator of length p. Check that |
maxsteps |
Maximum number of steps for forward stepwise. |
sigma |
Estimate of error standard deviation for use in AIC criterion. This determines the relative scale between RSS and the degrees of freedom penalty. Default is NULL corresponding to unknown sigma. When NULL, |
k |
Multiplier of model size penalty, the default is |
intercept |
Should an intercept be included in the model? Default is TRUE. Does not count as a step. |
center |
Should the columns of the design matrix be centered? Default is TRUE. |
normalize |
Should the design matrix be normalized? Default is TRUE. |
aicstop |
Early stopping if AIC increases. Default is 0 corresponding to no early stopping. Positive integer values specify the number of times the AIC is allowed to increase in a row, e.g. with |
verbose |
Print out progress along the way? Default is FALSE. |
Value
An object of class "groupfs" containing information about the sequence of models in the forward stepwise algorithm. Call the function groupfsInf
on this object to compute selective p-values.
See Also
Examples
x = matrix(rnorm(20*40), nrow=20)
index = sort(rep(1:20, 2))
y = rnorm(20) + 2 * x[,1] - x[,4]
fit = groupfs(x, y, index, maxsteps = 5)
out = groupfsInf(fit)
out