This function fits a linear regression model using the given data and formula, and returns the coefficients.

lm_coefficients(data, formula, standardize = FALSE, each = TRUE)

Arguments

data

A data frame containing the response variable and predictors.

formula

A formula specifying the structure of the linear regression model.

standardize

Whether to standardize the data before fitting the model.

each

each variable do a lm or whole multi-lm

Value

coefficients The coefficients of the linear regression model.

Examples

data <- data.frame(
  response = c(2, 4, 6, 7, 9),
  x1 = c(1, 2, 3, 4, 5),
  x2 = c(2, 3, 6, 8, 9),
  x3 = c(3, 6, 5, 12, 12)
)
coefficients_df <- lm_coefficients(data, response ~ x1 + x2 + x3)
print(coefficients_df)
#>   variable coefficient Std. Error   t value     Pr(>|t|)        r2    adj_r2
#> 1       x1   1.7000000  0.1000000 17.000000 0.0004433435 0.7604719 0.6806292
#> 2       x2   0.8655914  0.1090837  7.935111 0.0041737124 0.9545220 0.9393627
#> 3       x3   0.5664740  0.1835507  3.086200 0.0538736477 0.9897260 0.9863014
#>       type
#> 1 positive
#> 2 positive
#> 3 positive
plot(coefficients_df)