Learn R Programming

PoSIAdjRSquared (version 0.1.0)

construct_test_statistic: Construct test statistic

Description

This function constructs the OLS estimator of the j'th selected coefficient in the selected model. The functions also returns some useful vectors for post-selection inference (a and b).

Usage

construct_test_statistic(j, X_M_phat, y, phat, Sigma, intercept)

Value

etaj

Vector of type "matrix" and dimension nx1: useful in orthogonal decomposition of y (see Lemma 1 for details)

etajTy

The OLS estimator of the j'th selected coefficient in the selected model of type "matrix" and dimension 1x1

a

Residual vector of type "matrix" and dimension nx1 (see Lemma 1 for details)

b

Vector of type "matrix" and dimension nx1: useful in orthogonal decomposition of y (see Lemma 1 for details)

Arguments

j

The index of type "integer" of the regression coefficient

X_M_phat

The design matrix in the selected model

y

Response vector of type "matrix" and dimension nx1

phat

Index set included in the selected model

Sigma

The variance covariance matrix of dimension nxn of the error in the model

intercept

Logical value: TRUE if the selected model contains an 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
  n <- 100
  Data <- datagen.norm(seed = 7, n, 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
  result <- fit_all_subset_linear_models(y, X, intercept=FALSE)
  phat <- result$phat
  X_M_phat <- result$X_M_phat

  # Estimate Sigma from residuals of full model
  full_model <- lm(y ~ 0 + X)
  sigma_hat <- sd(resid(full_model))
  Sigma <- diag(n)*(sigma_hat)^2

  # Construct test statistic
  construct_test_statistic(j = 5, X_M_phat, y, phat, Sigma, intercept=FALSE)

Run the code above in your browser using DataLab