Extract Regression Coefficients of Linear Model in R (Example) | Create Matrix Using summary & lm

Описание к видео Extract Regression Coefficients of Linear Model in R (Example) | Create Matrix Using summary & lm

How to create a data object containing regression coefficients of a linear regression model in the R programming language. More details: https://statisticsglobe.com/extract-r...
R code of this video:

set.seed(87634) # Create random example data
x1 <- rnorm(1000)
x2 <- rnorm(1000) + 0.3 * x1
x3 <- rnorm(1000) + 0.1 * x1 + 0.2 * x2
x4 <- rnorm(1000) + 0.2 * x1 - 0.3 * x3
x5 <- rnorm(1000) - 0.1 * x2 + 0.1 * x4
y <- rnorm(1000) + 0.1 * x1 - 0.2 * x2 + 0.1 * x3 + 0.1 * x4 - 0.2 * x5
data <- data.frame(y, x1, x2, x3, x4, x5)

summary(lm(y ~ ., data)) # Estimate model

matrix_coef <- summary(lm(y ~ ., data))$coefficients # Extract coefficients in matrix
matrix_coef # Return matrix of coefficients

my_estimates <- matrix_coef[ , 1] # Matrix manipulation to extract estimates
my_estimates # Print estimates

Follow me on Social Media:
Twitter:   / joachimschork  
Facebook:   / statisticsglobecom  
Reddit:   / joachimschork  
Pinterest: https://www.pinterest.de/JoachimSchork

Комментарии

Информация по комментариям в разработке