"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

March 11, 2016

Day #2 - Multivariate Linear Regression - R

  • More than one predictor involved in this case
#x,y,z with random predictors
x = 1:20 + rnorm(100,sd=3)
y = 1:20 + rnorm(100,sd=2)
z = 1:20 + rnorm(100,sd=3)
#correlation between x and y
cor(x,y)
#correlation between y and z
cor(y,z)
#linear regression with two variables
model = lm(y~x+z)
#Equation is
#(Intercept) x z
# 1.8885 0.3965 0.3587
model
#y = 1.885 + 0.3965x + 0.3587z
err = residuals(model)
plot(model$fitted.values,err)
#This will look like normal distribution
hist(err)

Happy Learning!!!

No comments: