Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

variance-covariance matrix in R

$
0
0

I have the data frame below and from there I've calculated the matrix b from the betas of coefficients of my linear regression model. How do I create the variance-covariance matrix in R, or s^2_b?

y <- c(42, 33, 75, 28, 91, 55)
int <- c(1, 1, 1, 1, 1, 1)
x1 <- c(7, 4, 16, 3, 21, 8)
x2 <- c(33, 41, 7, 49, 5, 31)
df <- data.frame(y, x1, x2)
mod1 <- lm(y ~ x1 + x2, data = df)

# b
iint <- summary(mod1)$coefficients[[1]]
xx1 <- summary(mod1)$coefficients[[2]]
xx2 <- summary(mod1)$coefficients[[3]]
b <- matrix(c(iint, xx1, xx2), nrow=3)

# matrices of x and y
Y <- matrix(df$y)
X <- matrix(c(1, 1, 1, 1, 1, 1, 7, 4, 16, 3, 21, 8, 33, 41, 7, 49, 5, 31), nrow=6)

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>