Learn R Programming

PoSIAdjRSquared (version 0.1.0)

fit_specified_size_subset_linear_models: Fit all linear models of a specified size

Description

This function fits all possible combinations of a pre-specified size of linear models and returns the selected model based on adjusted R^2.

Usage

fit_specified_size_subset_linear_models(y, X, size, intercept)

Value

k

Index set included in model k

best_model

The selected model fit (lm object)

phat

Index set included in the selected model

X_M_phat

The design matrix in the selected model

best_adj_r_squared

The adjusted R^2 value of the selected model

R_M_phat

The orthogonal projection matrix of the selected model

kappa_M_phat

Adjustment factor for model complexity kappa of the selected model

R_M_k

The orthogonal projection matrix of model k

kappa_M_k

Adjustment factor for model complexity kappa of model k

Arguments

y

Response vector of type "matrix" and dimension nx1

X

Design matrix of type "matrix" and dimension nxp

size

Size of type "integer" of the fitted models

intercept

Logical value: TRUE if fitted models should contain intercept, FALSE if not

References

Pirenne, S. and Claeskens, G. (2024). Exact Post-Selection Inference for Adjusted R Squared.

Examples

Run this code
  # Generate data
  Data <- datagen.norm(seed = 7, n = 100, p = 10, rho = 0, beta_vec = c(1,0.5,0,0.5,0,0,0,0,0,0))
  X <- Data$X
  y <- Data$y

  # Select model
  fit_specified_size_subset_linear_models(y, X, size = 9, intercept=FALSE)

Run the code above in your browser using DataLab