Here is what I did:
1) I divided the mtcars dataset into a training set (80%) and a validation set (20%).
2) I built a simple linear model predicting mileage (mpg) based on displacement (disp).
3) I built a multi-linear model predicting mileage (mpg) based on displacement, horsepower and weight (disp + hp + wt).
Here is the R code I used:
set.seed(123)
trainingRowIndex <- sample(1:nrow(mtcars), 0.8*nrow(mtcars))
trainingSet <- mtcars[trainingRowIndex, ]
validationSet <- mtcars[-trainingRowIndex, ]
# Build simple linear model (disp only)
lmMtcars <- lm(mpg ~ disp, data=trainingSet)
summary (lmMtcars)
# Build multi-linear model (disp + hp + wt)
mlmMtcars <- lm(mpg ~ disp + hp + wt , data=trainingSet)
summary (mlmMtcars)
In the simple linear model, the disp has a p-value of 2.33e-07 (basically meaning that it is a good predictor). However, in the multi-linear model, disp has a p-value of 0.87220 (meaning that it is not a good predictor). I would expect disp to be a rather good predictor for mgp as there is a strong (negative) correlation between the two (=-0.8475514).
Why is the disp p-value not significant in the case of the multi-linear model? Is there something wrong with my code or do I miss something here?
Thanks,