Description Usage Arguments Details Value Examples
View source: R/model-diagnostics.R
diag_fit_reg_rwgt_single
provides estimate for GLM and OLS under
reweighting of one regressor. The function returns a set of estimates
for each bootstrapped data set and each center of reweighting.
1 2 3 4 5 6 | diag_fit_reg_rwgt_single(
mod_fit,
term_to_rwgt,
boot_samples,
term_to_rwgt_centers
)
|
mod_fit |
An object of class |
term_to_rwgt |
A character corresponding to the regressor to be reweighted. |
boot_samples |
A list of bootstrapped data sets. Each data set in the column "data" must include a column "n_obs" which contains the order of each observation as in the original data. |
term_to_rwgt_centers |
A vector of numeric values corresponding to the centers used for the reweighting. |
The GLM or OLS model extracted from mod_fit
is fitted on each
bootstrapped data set in boot_samples
under the reweighting of every
reweighting center in term_to_rwgt_centers
of the regressor
specified by term_to_rwgt
. The weight for the j-th regressor
with center c_{k}(j) and the i-th observation is proportional to
\exp\{-(X(j)_i - X(j))^2 / (2 * \hat{σ}(X(j))))\} where
\hat{σ} is the standard deviation of X(j).
A tibble containing the number of the bootstrapped data set
(b
), the value of the reweighting centers (term_rwgt_center
),
and estimates of the regression coefficients (term
and
estimate
).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Not run:
set.seed(12323)
# Get OLS estimates under reweighting of regressor X1
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)
boot_samples <- comp_boot_emp_samples(reg_df, B = 100)
ols_rwgt_X1 <- diag_fit_reg_rwgt_single(mod_fit, "X1", boot_samples, c(-1, 0, 1, 2))
# Display the output
print(ols_rwgt_X1)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.