# # Problem on EPage 204 # Exercise 4.3 EPage 161 # library(car) save_figs = FALSE source('../../Data/data_loaders.R') DF = load_appendix_steel_production_data() if( save_figs ){ postscript("../../WriteUp/Graphics/Chapter5/ex_5_5_scatter_plot.eps", onefile=FALSE, horizontal=FALSE) } #pairs(DF) scatterplotMatrix(DF) if( save_figs ){ dev.off() } m = lm( PROD ~ WID + DENS + STR, data=DF ) print(summary(m)) # Part (a): # print('Variance inflation factors:') print(vif(m)) # Form the standardized predictors: # DFs = scale(DF) DFs = data.frame(DFs) XTX = cor(DF) print('Correlation matrix:') print(XTX) ES = eigen(XTX[ 1:3, 1:3 ]) print('Eigenvalues') print(ES$values) ES$vectors[, 1] = -ES$vectors[, 1] # change the sign of all components of the first eigenvector # Part (b): # # Compute the primcipal components (and a scatter plot of them): # Z = as.matrix(DFs[ , 1:3 ]) %*% ES$vectors colnames(Z) = c('Z1', 'Z2', 'Z3') print(summary(Z)) if( save_figs ){ postscript("../../WriteUp/Graphics/Chapter5/ex_5_5_scatter_plot_of_Z.eps", onefile=FALSE, horizontal=FALSE) } pairs(Z, xlim=c(-3, +3), ylim=c(-3, +3)) if( save_figs ){ dev.off() } print(Z[8, ]) # Part (c): # m = lm( PROD ~ WID + DENS + STR, data=DF[-8,] ) print(summary(m)) print('Variance inflation factors (w/o case 8):') print(vif(m)) XTX = cor(DF[-8,]) print('Correlation matrix (w/o case 8):') print(XTX) E8 = eigen(XTX[ 1:3, 1:3 ]) print('Eigenvalues (w/o case 8):') print(ES$values) ES$vectors[, 1] = -ES$vectors[, 1] # change the sign of all components of the first eigenvector # Part (d): # m = lm( PROD ~ WID + STR, data=DF ) print('full dataset') print(summary(m)) m = lm( PROD ~ WID + STR, data=DF[-8,] ) print('w/o case 8') print(summary(m))