Skip to content

Instantly share code, notes, and snippets.

@rpietro
Created August 19, 2013 01:59
Show Gist options
  • Select an option

  • Save rpietro/6265207 to your computer and use it in GitHub Desktop.

Select an option

Save rpietro/6265207 to your computer and use it in GitHub Desktop.
explaining regression through matrix multiplication
set.seed(123)
dependent <- rnorm(100)
set.seed(1234)
independent <- dependent*(rnorm(100))
identity <- rep(1, 100)
identity
independent2 <- cbind (identity, independent2)
independent2
tindependent2_independent2 <- t(independent2)%*%independent2
tindependent2_independent2
tindependent2_dependent <- t(independent2)%*%dependent
tindependent2_dependent
x <- solve(tindependent2_independent2)
x
coefficients <- x %*% tindependent2_dependent
coefficients
lm(dependent ~ independent)
@chupvl
Copy link

chupvl commented Aug 20, 2013

you have a typo here independent2 <- cbind (identity, independent2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment