Description Usage Arguments Details Value Examples
View source: R/boot-empirical.R
fit_reg
fits an OLS or GLM on the input dataset.
1 |
mod_fit |
An object of class |
data |
A tibble or data frame containing the dataset on which the model will be trained. |
weights |
A character corresponding to the name of the weights feature name in the data. |
The model specification obtained from mod_fit
, of
class lm
or glm
, is
fitted on data
. The user can choose to fit a weighted
regression using the argument weights
.
A tibble containing the estimated coefficients (term
) of
the regressors (term
).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## Not run:
set.seed(457468)
# Estimate ols from a bootstraped dataset
n <- 1e3
X <- stats::rnorm(n, 0, 1)
y <- 2 + X * 1 + stats::rnorm(n, 0, 1)
lm_fit <- stats::lm(y ~ X)
boot <- comp_boot_emp_samples(model.frame(lm_fit))$data[[1]]
mod <- fit_reg(lm_fit, boot)
# Display the output
print(mod)
#' # Estimate OLS from a dataset with weights
n <- 1e3
X <- stats::rnorm(n, 0, 1)
y <- 2 + X * 1 + stats::rnorm(n, 0, 1)
mod_fit <- lm(y ~ X)
# fit weighted regression
reg_df <- tibble::tibble(y = y, X = X, weights = 1:length(X))
mod <- fit_reg(mod_fit, reg_df, "weights")
print(mod)
# fit unweighted regression
mod <- fit_reg(mod_fit, reg_df)
print(mod)
# compare this output with the output from lm
coef(lm(y ~ X, reg_df))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.