View source: R/estimate_model.R
estimate_model | R Documentation |
This function estimates the coefficients of a linear model specified by one or more independent variables. It checks for the presence of the specified independent variables in the dataset and whether the dataset has a sufficient number of observations. It returns the model's coefficients as either a numeric value (for a single independent variable) or a data frame (for multiple independent variables).
estimate_model(data, model, min_obs = 1)
data |
A data frame containing the dependent variable and one or more independent variables. |
model |
A character that describes the model to estimate (e.g.
|
min_obs |
The minimum number of observations required to estimate the model. Defaults to 1. |
A data frame with a row for each coefficient and column names corresponding to the independent variables.
stats::lm()
for details on the underlying linear model fitting used.
data <- data.frame(
ret_excess = rnorm(100),
mkt_excess = rnorm(100),
smb = rnorm(100),
hml = rnorm(100)
)
# Estimate model with a single independent variable
estimate_model(data, "ret_excess ~ mkt_excess")
# Estimate model with multiple independent variables
estimate_model(data, "ret_excess ~ mkt_excess + smb + hml")
# Estimate model without intercept
estimate_model(data, "ret_excess ~ mkt_excess - 1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.