diag_fit_reg_rwgt returns estimates for GLM and OLS under reweighting of multiple regressors. The function estimates a set of coefficients for several configurations of the reweighting of the reweighting of each regressor.

diag_fit_reg_rwgt(
  mod_fit,
  terms_to_rwgt,
  B = 100,
  m = NULL,
  grid_centers = NULL,
  grid_method = "quantiles",
  n_grid = 9
)

Arguments

mod_fit

An object of class lm or glm to fit on the data. This object should contain the formula, the data, and, in case of glm, the family.

terms_to_rwgt

A vector of characters corresponding to the names of the regressors to be reweighted.

B

An integer corresponding to the number of bootstrap repetitions or number of bootstrap samples to be drawn. Default is set to 100.

m

An integer corresponding to the number of observations to be sampled with replacement from the data set in each bootstrap repetition. Default is set to the size of the data set.

grid_centers

A data frame containing the names of the regressors as columns and the corresponding reweighting centers. Each column corresponds to a different regressor, whose name is specified in the name of the column. Default is set to NULL.

grid_method

A character which specifies the method used to construct the grid of reweighting centers. The grid can consist either of evenly spaced values between the maximum and the minimum (grid_method='regular') or based on the quantiles between the first and the ninth deciles (grid_method='quantiles'). Default is set to 'quantile'.

n_grid

An integer corresponding to the number of reweighting centers for the grid. Default is set to 9.

Value

A tibble containing the number of the bootstrapped data set (b), the size of each bootstrapped data set (m), the value of the reweighting centers (term_rwgt_center) and the name of the regressor under reweighting (term_rwgt), and the estimates of the regression coefficients (term and estimate).

Details

The model extracted from mod_fit is fitted on B data sets sampled via m-out-of-n empirical bootstrap using weighted regression where the predictors to be reweighted are specified in terms_to_rwgt and have reweighting centers given by grid_centers. Using the default parameters, the function will compute the estimates for a grid based on the second to first to the ninth deciles of each regressor.

Examples

if (FALSE) { set.seed(1321312) # Get OLS estimates under reweighting of all regressors with default grid n <- 1e3 X1 <- stats::rnorm(n, 0, 1) X2 <- stats::rnorm(n, 0, 3) y <- 2 + X1 + X2 * 0.3 + stats::rnorm(n, 0, 1) reg_df <- tibble::tibble(y = y, X1 = X1, X2 = X2, n_obs = 1:length(X1)) mod_fit <- stats::lm(y ~ X1 + X2, reg_df) ols_rwgt <- diag_fit_reg_rwgt(mod_fit, c("X1", "X2")) # Display the output print(ols_rwgt) # Get OLS estimates under reweighting of all regressors by feeding grid of centers into the function ols_rwgt_grid_fixed <- diag_fit_reg_rwgt(mod_fit, "X1", grid_centers = data.frame(X1 = c(0, 1))) #' # Display the output print(ols_rwgt_grid_fixed) }