library(kableExtra)
library(tidyverse)Ans:
N<- round(runif(1, 6, 100))
n <- 10000
X <- runif(n,1,N)
hist(X)mu <- (N+1)/2
sigma <- (N+1)/2
Y <- rnorm(n,mu,sigma)
hist(Y)
abline(v=(N+1)/2, col = "red")Calculate as a minimum the below probabilities a through c. Assume the small letter “x” is estimated as the median of the X variable, and the small letter “y” is estimated as the 1st quartile of the Y variable. Interpret the meaning of all probabilities.
x <- median(X)
round(x,2)## [1] 49.35
y <- quantile(Y,0.25)[[1]]
round(y,2)## [1] 17.01
1.a. P(X>x | X>y) - Probability that X is greater than its median given that X is greater than the first quartile of Y.
\(P(X>x|X>y)=\frac { P(X>x,X>y) }{ P(X>y) }\)
# Probability expression for X greater than mean(x) given that X greater than the 1st quartile of Y(y)
# Numerator: Sum of all random numbers X greater than the mean and Q1 of Y divided by all possible X
prob_num <- sum(X>x & X>y)/n
# Denominator: Sum of all X greater than y divided by all X
prob_den <- sum(X>y)/n
prob = round(prob_num/prob_den, 2)
cat('Probability: ',prob)## Probability: 0.6
1.b. P(X>x, Y>y) - Probability that X is greater than its median as well as greater than the first quartile of Y.
# Probablity of X greater than the mean and Y greater than 1st quartile
prob = round(sum(X>x & Y>y)/n, 2)
cat('Probability: ',prob)## Probability: 0.37
1.c. \(P(X<x|X>y)\) - Probability that X is lesser than its median given that X is greater than the first quartile of Y.
\(P(X<x|X>y)=\frac { P(X<x,X>y) }{ P(X>y) }\)
# Probability expression for X lesser than mean(x) given that X greater than the 1st quartile of Y(y)
# Numerator: Sum of all random numbers X lesser than the mean but greater than Q1 of Y divided by all possible X
prob_num <- sum(X<x & X>y)/n
# Denominator: Sum of all X greater than y divided by all X
prob_den <- sum(X>y)/n
prob = round(prob_num/prob_den, 2)
cat('Probability: ',prob)## Probability: 0.4
Investigate whether P(X>x and Y>y)=P(X>x)P(Y>y) by building a table and evaluating the marginal and joint probabilities.
matrix<-matrix( c(sum(X>x & Y<y),sum(X>x & Y>y), sum(X<x & Y<y),sum(X<x & Y>y)), nrow = 2,ncol = 2)
matrix<-cbind(matrix,c(matrix[1,1]+matrix[1,2],matrix[2,1]+matrix[2,2]))
matrix<-rbind(matrix,c(matrix[1,1]+matrix[2,1],matrix[1,2]+matrix[2,2],matrix[1,3]+matrix[2,3]))
contingency<-as.data.frame(matrix)
names(contingency) <- c("X>x","X<x", "Total")
row.names(contingency) <- c("Y<y","Y>y", "Total")
contingency %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| X>x | X<x | Total | |
|---|---|---|---|
| Y<y | 1252 | 1248 | 2500 |
| Y>y | 3748 | 3752 | 7500 |
| Total | 5000 | 5000 | 10000 |
prob_matrix<-matrix/matrix[3,3]
contingency_p<-as.data.frame(prob_matrix)
names(contingency_p) <- c("X>x","X<x", "Total")
row.names(contingency_p) <- c("Y<y","Y>y", "Total")
round(contingency_p,2) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| X>x | X<x | Total | |
|---|---|---|---|
| Y<y | 0.13 | 0.12 | 0.25 |
| Y>y | 0.37 | 0.38 | 0.75 |
| Total | 0.50 | 0.50 | 1.00 |
round(prob_matrix[3,1]*prob_matrix[2,3],3)## [1] 0.375
round(prob_matrix[2,1],digits = 3)## [1] 0.375
round(prob_matrix[3,1]*prob_matrix[2,3],3)==round(prob_matrix[2,1],digits = 3)## [1] TRUE
Since the results are so similar we would conclude that X and Y are indeed independent.
Check to see if independence holds by using Fisher’s Exact Test and the Chi Square Test. What is the difference between the two? Which is most appropriate?
Ans:
fisher.test(matrix,simulate.p.value=TRUE)##
## Fisher's Exact Test for Count Data with simulated p-value (based
## on 2000 replicates)
##
## data: matrix
## p-value = 1
## alternative hypothesis: two.sided
chisq.test(matrix, correct=TRUE)##
## Pearson's Chi-squared test
##
## data: matrix
## X-squared = 0.0085333, df = 4, p-value = 1
Fisher’s Exact Test for Independence is known to be more accurate than Chi Square Test and recommended to be used when we have small sample sizes (typically less than 1000). The Chi Square Test is used when the cell sizes are large. Since, in our case we are dealing with a distribution of 10,000 random numbers, it would be appropriate to use Chi Square test.
5 points. Descriptive and Inferential Statistics. Provide univariate descriptive statistics and appropriate plots for the training data set. Provide a scatterplot matrix for at least two of the independent variables and the dependent variable. Derive a correlation matrix for any three quantitative variables in the dataset. Test the hypotheses that the correlations between each pairwise set of variables is 0 and provide an 80% confidence interval. Discuss the meaning of your analysis. Would you be worried about familywise error? Why or why not?
5 points. Linear Algebra and Correlation. Invert your correlation matrix from above. (This is known as the precision matrix and contains variance inflation factors on the diagonal.) Multiply the correlation matrix by the precision matrix, and then multiply the precision matrix by the correlation matrix. Conduct LU decomposition on the matrix.
5 points. Calculus-Based Probability & Statistics. Many times, it makes sense to fit a closed form distribution to data. Select a variable in the Kaggle.com training dataset that is skewed to the right, shift it so that the minimum value is absolutely above zero if necessary. Then load the MASS package and run fitdistr to fit an exponential probability density function. (See https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/fitdistr.html ). Find the optimal value of \(\lambda\) for this distribution, and then take 1000 samples from this exponential distribution using this value (e.g., rexp(1000, \(\lambda\)???)). Plot a histogram and compare it with a histogram of your original variable. Using the exponential pdf, find the 5th and 95th percentiles using the cumulative distribution function (CDF). Also generate a 95% confidence interval from the empirical data, assuming normality. Finally, provide the empirical 5th percentile and 95th percentile of the data. Discuss.
10 points. Modeling. Build some type of multiple regression model and submit your model to the competition board. Provide your complete model summary and results with analysis. Report your Kaggle.com user name and score.
library(ggplot2)
library(dplyr)
library(plotly)
library(MASS)
library(corrplot)
library(RColorBrewer)
library(GGally)
library(ggResidpanel)The following data source and metadata dictionary files were downloaded from the Kaggle Competition site to my GitHub project directory -
The train.csv file is loaded into a R data frame ‘housing_pr_train’ -
housing_pr_train <- read.csv('https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-605/House%20Price%20Analysis/Data%20Source/house-prices-advanced-regression-techniques/train.csv',sep = ',')
## Sample Data
head(housing_pr_train) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| Id | MSSubClass | MSZoning | LotFrontage | LotArea | Street | Alley | LotShape | LandContour | Utilities | LotConfig | LandSlope | Neighborhood | Condition1 | Condition2 | BldgType | HouseStyle | OverallQual | OverallCond | YearBuilt | YearRemodAdd | RoofStyle | RoofMatl | Exterior1st | Exterior2nd | MasVnrType | MasVnrArea | ExterQual | ExterCond | Foundation | BsmtQual | BsmtCond | BsmtExposure | BsmtFinType1 | BsmtFinSF1 | BsmtFinType2 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | Heating | HeatingQC | CentralAir | Electrical | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BsmtFullBath | BsmtHalfBath | FullBath | HalfBath | BedroomAbvGr | KitchenAbvGr | KitchenQual | TotRmsAbvGrd | Functional | Fireplaces | FireplaceQu | GarageType | GarageYrBlt | GarageFinish | GarageCars | GarageArea | GarageQual | GarageCond | PavedDrive | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | PoolQC | Fence | MiscFeature | MiscVal | MoSold | YrSold | SaleType | SaleCondition | SalePrice |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 60 | RL | 65 | 8450 | Pave | NA | Reg | Lvl | AllPub | Inside | Gtl | CollgCr | Norm | Norm | 1Fam | 2Story | 7 | 5 | 2003 | 2003 | Gable | CompShg | VinylSd | VinylSd | BrkFace | 196 | Gd | TA | PConc | Gd | TA | No | GLQ | 706 | Unf | 0 | 150 | 856 | GasA | Ex | Y | SBrkr | 856 | 854 | 0 | 1710 | 1 | 0 | 2 | 1 | 3 | 1 | Gd | 8 | Typ | 0 | NA | Attchd | 2003 | RFn | 2 | 548 | TA | TA | Y | 0 | 61 | 0 | 0 | 0 | 0 | NA | NA | NA | 0 | 2 | 2008 | WD | Normal | 208500 |
| 2 | 20 | RL | 80 | 9600 | Pave | NA | Reg | Lvl | AllPub | FR2 | Gtl | Veenker | Feedr | Norm | 1Fam | 1Story | 6 | 8 | 1976 | 1976 | Gable | CompShg | MetalSd | MetalSd | None | 0 | TA | TA | CBlock | Gd | TA | Gd | ALQ | 978 | Unf | 0 | 284 | 1262 | GasA | Ex | Y | SBrkr | 1262 | 0 | 0 | 1262 | 0 | 1 | 2 | 0 | 3 | 1 | TA | 6 | Typ | 1 | TA | Attchd | 1976 | RFn | 2 | 460 | TA | TA | Y | 298 | 0 | 0 | 0 | 0 | 0 | NA | NA | NA | 0 | 5 | 2007 | WD | Normal | 181500 |
| 3 | 60 | RL | 68 | 11250 | Pave | NA | IR1 | Lvl | AllPub | Inside | Gtl | CollgCr | Norm | Norm | 1Fam | 2Story | 7 | 5 | 2001 | 2002 | Gable | CompShg | VinylSd | VinylSd | BrkFace | 162 | Gd | TA | PConc | Gd | TA | Mn | GLQ | 486 | Unf | 0 | 434 | 920 | GasA | Ex | Y | SBrkr | 920 | 866 | 0 | 1786 | 1 | 0 | 2 | 1 | 3 | 1 | Gd | 6 | Typ | 1 | TA | Attchd | 2001 | RFn | 2 | 608 | TA | TA | Y | 0 | 42 | 0 | 0 | 0 | 0 | NA | NA | NA | 0 | 9 | 2008 | WD | Normal | 223500 |
| 4 | 70 | RL | 60 | 9550 | Pave | NA | IR1 | Lvl | AllPub | Corner | Gtl | Crawfor | Norm | Norm | 1Fam | 2Story | 7 | 5 | 1915 | 1970 | Gable | CompShg | Wd Sdng | Wd Shng | None | 0 | TA | TA | BrkTil | TA | Gd | No | ALQ | 216 | Unf | 0 | 540 | 756 | GasA | Gd | Y | SBrkr | 961 | 756 | 0 | 1717 | 1 | 0 | 1 | 0 | 3 | 1 | Gd | 7 | Typ | 1 | Gd | Detchd | 1998 | Unf | 3 | 642 | TA | TA | Y | 0 | 35 | 272 | 0 | 0 | 0 | NA | NA | NA | 0 | 2 | 2006 | WD | Abnorml | 140000 |
| 5 | 60 | RL | 84 | 14260 | Pave | NA | IR1 | Lvl | AllPub | FR2 | Gtl | NoRidge | Norm | Norm | 1Fam | 2Story | 8 | 5 | 2000 | 2000 | Gable | CompShg | VinylSd | VinylSd | BrkFace | 350 | Gd | TA | PConc | Gd | TA | Av | GLQ | 655 | Unf | 0 | 490 | 1145 | GasA | Ex | Y | SBrkr | 1145 | 1053 | 0 | 2198 | 1 | 0 | 2 | 1 | 4 | 1 | Gd | 9 | Typ | 1 | TA | Attchd | 2000 | RFn | 3 | 836 | TA | TA | Y | 192 | 84 | 0 | 0 | 0 | 0 | NA | NA | NA | 0 | 12 | 2008 | WD | Normal | 250000 |
| 6 | 50 | RL | 85 | 14115 | Pave | NA | IR1 | Lvl | AllPub | Inside | Gtl | Mitchel | Norm | Norm | 1Fam | 1.5Fin | 5 | 5 | 1993 | 1995 | Gable | CompShg | VinylSd | VinylSd | None | 0 | TA | TA | Wood | Gd | TA | No | GLQ | 732 | Unf | 0 | 64 | 796 | GasA | Ex | Y | SBrkr | 796 | 566 | 0 | 1362 | 1 | 0 | 1 | 1 | 1 | 1 | TA | 5 | Typ | 0 | NA | Attchd | 1993 | Unf | 2 | 480 | TA | TA | Y | 40 | 30 | 0 | 320 | 0 | 0 | NA | MnPrv | Shed | 700 | 10 | 2009 | WD | Normal | 143000 |
glimpse(housing_pr_train)## Observations: 1,460
## Variables: 81
## $ Id <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1...
## $ MSSubClass <int> 60, 20, 60, 70, 60, 50, 20, 60, 50, 190, 20, 60,...
## $ MSZoning <fct> RL, RL, RL, RL, RL, RL, RL, RL, RM, RL, RL, RL, ...
## $ LotFrontage <int> 65, 80, 68, 60, 84, 85, 75, NA, 51, 50, 70, 85, ...
## $ LotArea <int> 8450, 9600, 11250, 9550, 14260, 14115, 10084, 10...
## $ Street <fct> Pave, Pave, Pave, Pave, Pave, Pave, Pave, Pave, ...
## $ Alley <fct> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
## $ LotShape <fct> Reg, Reg, IR1, IR1, IR1, IR1, Reg, IR1, Reg, Reg...
## $ LandContour <fct> Lvl, Lvl, Lvl, Lvl, Lvl, Lvl, Lvl, Lvl, Lvl, Lvl...
## $ Utilities <fct> AllPub, AllPub, AllPub, AllPub, AllPub, AllPub, ...
## $ LotConfig <fct> Inside, FR2, Inside, Corner, FR2, Inside, Inside...
## $ LandSlope <fct> Gtl, Gtl, Gtl, Gtl, Gtl, Gtl, Gtl, Gtl, Gtl, Gtl...
## $ Neighborhood <fct> CollgCr, Veenker, CollgCr, Crawfor, NoRidge, Mit...
## $ Condition1 <fct> Norm, Feedr, Norm, Norm, Norm, Norm, Norm, PosN,...
## $ Condition2 <fct> Norm, Norm, Norm, Norm, Norm, Norm, Norm, Norm, ...
## $ BldgType <fct> 1Fam, 1Fam, 1Fam, 1Fam, 1Fam, 1Fam, 1Fam, 1Fam, ...
## $ HouseStyle <fct> 2Story, 1Story, 2Story, 2Story, 2Story, 1.5Fin, ...
## $ OverallQual <int> 7, 6, 7, 7, 8, 5, 8, 7, 7, 5, 5, 9, 5, 7, 6, 7, ...
## $ OverallCond <int> 5, 8, 5, 5, 5, 5, 5, 6, 5, 6, 5, 5, 6, 5, 5, 8, ...
## $ YearBuilt <int> 2003, 1976, 2001, 1915, 2000, 1993, 2004, 1973, ...
## $ YearRemodAdd <int> 2003, 1976, 2002, 1970, 2000, 1995, 2005, 1973, ...
## $ RoofStyle <fct> Gable, Gable, Gable, Gable, Gable, Gable, Gable,...
## $ RoofMatl <fct> CompShg, CompShg, CompShg, CompShg, CompShg, Com...
## $ Exterior1st <fct> VinylSd, MetalSd, VinylSd, Wd Sdng, VinylSd, Vin...
## $ Exterior2nd <fct> VinylSd, MetalSd, VinylSd, Wd Shng, VinylSd, Vin...
## $ MasVnrType <fct> BrkFace, None, BrkFace, None, BrkFace, None, Sto...
## $ MasVnrArea <int> 196, 0, 162, 0, 350, 0, 186, 240, 0, 0, 0, 286, ...
## $ ExterQual <fct> Gd, TA, Gd, TA, Gd, TA, Gd, TA, TA, TA, TA, Ex, ...
## $ ExterCond <fct> TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, ...
## $ Foundation <fct> PConc, CBlock, PConc, BrkTil, PConc, Wood, PConc...
## $ BsmtQual <fct> Gd, Gd, Gd, TA, Gd, Gd, Ex, Gd, TA, TA, TA, Ex, ...
## $ BsmtCond <fct> TA, TA, TA, Gd, TA, TA, TA, TA, TA, TA, TA, TA, ...
## $ BsmtExposure <fct> No, Gd, Mn, No, Av, No, Av, Mn, No, No, No, No, ...
## $ BsmtFinType1 <fct> GLQ, ALQ, GLQ, ALQ, GLQ, GLQ, GLQ, ALQ, Unf, GLQ...
## $ BsmtFinSF1 <int> 706, 978, 486, 216, 655, 732, 1369, 859, 0, 851,...
## $ BsmtFinType2 <fct> Unf, Unf, Unf, Unf, Unf, Unf, Unf, BLQ, Unf, Unf...
## $ BsmtFinSF2 <int> 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0,...
## $ BsmtUnfSF <int> 150, 284, 434, 540, 490, 64, 317, 216, 952, 140,...
## $ TotalBsmtSF <int> 856, 1262, 920, 756, 1145, 796, 1686, 1107, 952,...
## $ Heating <fct> GasA, GasA, GasA, GasA, GasA, GasA, GasA, GasA, ...
## $ HeatingQC <fct> Ex, Ex, Ex, Gd, Ex, Ex, Ex, Ex, Gd, Ex, Ex, Ex, ...
## $ CentralAir <fct> Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, ...
## $ Electrical <fct> SBrkr, SBrkr, SBrkr, SBrkr, SBrkr, SBrkr, SBrkr,...
## $ X1stFlrSF <int> 856, 1262, 920, 961, 1145, 796, 1694, 1107, 1022...
## $ X2ndFlrSF <int> 854, 0, 866, 756, 1053, 566, 0, 983, 752, 0, 0, ...
## $ LowQualFinSF <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ GrLivArea <int> 1710, 1262, 1786, 1717, 2198, 1362, 1694, 2090, ...
## $ BsmtFullBath <int> 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, ...
## $ BsmtHalfBath <int> 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ FullBath <int> 2, 2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 3, 1, 2, 1, 1, ...
## $ HalfBath <int> 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, ...
## $ BedroomAbvGr <int> 3, 3, 3, 3, 4, 1, 3, 3, 2, 2, 3, 4, 2, 3, 2, 2, ...
## $ KitchenAbvGr <int> 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, ...
## $ KitchenQual <fct> Gd, TA, Gd, Gd, Gd, TA, Gd, TA, TA, TA, TA, Ex, ...
## $ TotRmsAbvGrd <int> 8, 6, 6, 7, 9, 5, 7, 7, 8, 5, 5, 11, 4, 7, 5, 5,...
## $ Functional <fct> Typ, Typ, Typ, Typ, Typ, Typ, Typ, Typ, Min1, Ty...
## $ Fireplaces <int> 0, 1, 1, 1, 1, 0, 1, 2, 2, 2, 0, 2, 0, 1, 1, 0, ...
## $ FireplaceQu <fct> NA, TA, TA, Gd, TA, NA, Gd, TA, TA, TA, NA, Gd, ...
## $ GarageType <fct> Attchd, Attchd, Attchd, Detchd, Attchd, Attchd, ...
## $ GarageYrBlt <int> 2003, 1976, 2001, 1998, 2000, 1993, 2004, 1973, ...
## $ GarageFinish <fct> RFn, RFn, RFn, Unf, RFn, Unf, RFn, RFn, Unf, RFn...
## $ GarageCars <int> 2, 2, 2, 3, 3, 2, 2, 2, 2, 1, 1, 3, 1, 3, 1, 2, ...
## $ GarageArea <int> 548, 460, 608, 642, 836, 480, 636, 484, 468, 205...
## $ GarageQual <fct> TA, TA, TA, TA, TA, TA, TA, TA, Fa, Gd, TA, TA, ...
## $ GarageCond <fct> TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, TA, ...
## $ PavedDrive <fct> Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, Y, ...
## $ WoodDeckSF <int> 0, 298, 0, 0, 192, 40, 255, 235, 90, 0, 0, 147, ...
## $ OpenPorchSF <int> 61, 0, 42, 35, 84, 30, 57, 204, 0, 4, 0, 21, 0, ...
## $ EnclosedPorch <int> 0, 0, 0, 272, 0, 0, 0, 228, 205, 0, 0, 0, 0, 0, ...
## $ X3SsnPorch <int> 0, 0, 0, 0, 0, 320, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
## $ ScreenPorch <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 176, 0, 0, 0...
## $ PoolArea <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ PoolQC <fct> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
## $ Fence <fct> NA, NA, NA, NA, NA, MnPrv, NA, NA, NA, NA, NA, N...
## $ MiscFeature <fct> NA, NA, NA, NA, NA, Shed, NA, Shed, NA, NA, NA, ...
## $ MiscVal <int> 0, 0, 0, 0, 0, 700, 0, 350, 0, 0, 0, 0, 0, 0, 0,...
## $ MoSold <int> 2, 5, 9, 2, 12, 10, 8, 11, 4, 1, 2, 7, 9, 8, 5, ...
## $ YrSold <int> 2008, 2007, 2008, 2006, 2008, 2009, 2007, 2009, ...
## $ SaleType <fct> WD, WD, WD, WD, WD, WD, WD, WD, WD, WD, WD, New,...
## $ SaleCondition <fct> Normal, Normal, Normal, Abnorml, Normal, Normal,...
## $ SalePrice <int> 208500, 181500, 223500, 140000, 250000, 143000, ...
Provide univariate descriptive statistics and appropriate plots for the training data set. Provide a scatterplot matrix for at least two of the independent variables and the dependent variable. Derive a correlation matrix for any three quantitative variables in the dataset. Test the hypotheses that the correlations between each pairwise set of variables is 0 and provide an 80% confidence interval. Discuss the meaning of your analysis. Would you be worried about familywise error? Why or why not?
** Ans:**
summary(housing_pr_train)## Id MSSubClass MSZoning LotFrontage
## Min. : 1.0 Min. : 20.0 C (all): 10 Min. : 21.00
## 1st Qu.: 365.8 1st Qu.: 20.0 FV : 65 1st Qu.: 59.00
## Median : 730.5 Median : 50.0 RH : 16 Median : 69.00
## Mean : 730.5 Mean : 56.9 RL :1151 Mean : 70.05
## 3rd Qu.:1095.2 3rd Qu.: 70.0 RM : 218 3rd Qu.: 80.00
## Max. :1460.0 Max. :190.0 Max. :313.00
## NA's :259
## LotArea Street Alley LotShape LandContour
## Min. : 1300 Grvl: 6 Grvl: 50 IR1:484 Bnk: 63
## 1st Qu.: 7554 Pave:1454 Pave: 41 IR2: 41 HLS: 50
## Median : 9478 NA's:1369 IR3: 10 Low: 36
## Mean : 10517 Reg:925 Lvl:1311
## 3rd Qu.: 11602
## Max. :215245
##
## Utilities LotConfig LandSlope Neighborhood Condition1
## AllPub:1459 Corner : 263 Gtl:1382 NAmes :225 Norm :1260
## NoSeWa: 1 CulDSac: 94 Mod: 65 CollgCr:150 Feedr : 81
## FR2 : 47 Sev: 13 OldTown:113 Artery : 48
## FR3 : 4 Edwards:100 RRAn : 26
## Inside :1052 Somerst: 86 PosN : 19
## Gilbert: 79 RRAe : 11
## (Other):707 (Other): 15
## Condition2 BldgType HouseStyle OverallQual
## Norm :1445 1Fam :1220 1Story :726 Min. : 1.000
## Feedr : 6 2fmCon: 31 2Story :445 1st Qu.: 5.000
## Artery : 2 Duplex: 52 1.5Fin :154 Median : 6.000
## PosN : 2 Twnhs : 43 SLvl : 65 Mean : 6.099
## RRNn : 2 TwnhsE: 114 SFoyer : 37 3rd Qu.: 7.000
## PosA : 1 1.5Unf : 14 Max. :10.000
## (Other): 2 (Other): 19
## OverallCond YearBuilt YearRemodAdd RoofStyle
## Min. :1.000 Min. :1872 Min. :1950 Flat : 13
## 1st Qu.:5.000 1st Qu.:1954 1st Qu.:1967 Gable :1141
## Median :5.000 Median :1973 Median :1994 Gambrel: 11
## Mean :5.575 Mean :1971 Mean :1985 Hip : 286
## 3rd Qu.:6.000 3rd Qu.:2000 3rd Qu.:2004 Mansard: 7
## Max. :9.000 Max. :2010 Max. :2010 Shed : 2
##
## RoofMatl Exterior1st Exterior2nd MasVnrType MasVnrArea
## CompShg:1434 VinylSd:515 VinylSd:504 BrkCmn : 15 Min. : 0.0
## Tar&Grv: 11 HdBoard:222 MetalSd:214 BrkFace:445 1st Qu.: 0.0
## WdShngl: 6 MetalSd:220 HdBoard:207 None :864 Median : 0.0
## WdShake: 5 Wd Sdng:206 Wd Sdng:197 Stone :128 Mean : 103.7
## ClyTile: 1 Plywood:108 Plywood:142 NA's : 8 3rd Qu.: 166.0
## Membran: 1 CemntBd: 61 CmentBd: 60 Max. :1600.0
## (Other): 2 (Other):128 (Other):136 NA's :8
## ExterQual ExterCond Foundation BsmtQual BsmtCond BsmtExposure
## Ex: 52 Ex: 3 BrkTil:146 Ex :121 Fa : 45 Av :221
## Fa: 14 Fa: 28 CBlock:634 Fa : 35 Gd : 65 Gd :134
## Gd:488 Gd: 146 PConc :647 Gd :618 Po : 2 Mn :114
## TA:906 Po: 1 Slab : 24 TA :649 TA :1311 No :953
## TA:1282 Stone : 6 NA's: 37 NA's: 37 NA's: 38
## Wood : 3
##
## BsmtFinType1 BsmtFinSF1 BsmtFinType2 BsmtFinSF2
## ALQ :220 Min. : 0.0 ALQ : 19 Min. : 0.00
## BLQ :148 1st Qu.: 0.0 BLQ : 33 1st Qu.: 0.00
## GLQ :418 Median : 383.5 GLQ : 14 Median : 0.00
## LwQ : 74 Mean : 443.6 LwQ : 46 Mean : 46.55
## Rec :133 3rd Qu.: 712.2 Rec : 54 3rd Qu.: 0.00
## Unf :430 Max. :5644.0 Unf :1256 Max. :1474.00
## NA's: 37 NA's: 38
## BsmtUnfSF TotalBsmtSF Heating HeatingQC CentralAir
## Min. : 0.0 Min. : 0.0 Floor: 1 Ex:741 N: 95
## 1st Qu.: 223.0 1st Qu.: 795.8 GasA :1428 Fa: 49 Y:1365
## Median : 477.5 Median : 991.5 GasW : 18 Gd:241
## Mean : 567.2 Mean :1057.4 Grav : 7 Po: 1
## 3rd Qu.: 808.0 3rd Qu.:1298.2 OthW : 2 TA:428
## Max. :2336.0 Max. :6110.0 Wall : 4
##
## Electrical X1stFlrSF X2ndFlrSF LowQualFinSF
## FuseA: 94 Min. : 334 Min. : 0 Min. : 0.000
## FuseF: 27 1st Qu.: 882 1st Qu.: 0 1st Qu.: 0.000
## FuseP: 3 Median :1087 Median : 0 Median : 0.000
## Mix : 1 Mean :1163 Mean : 347 Mean : 5.845
## SBrkr:1334 3rd Qu.:1391 3rd Qu.: 728 3rd Qu.: 0.000
## NA's : 1 Max. :4692 Max. :2065 Max. :572.000
##
## GrLivArea BsmtFullBath BsmtHalfBath FullBath
## Min. : 334 Min. :0.0000 Min. :0.00000 Min. :0.000
## 1st Qu.:1130 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:1.000
## Median :1464 Median :0.0000 Median :0.00000 Median :2.000
## Mean :1515 Mean :0.4253 Mean :0.05753 Mean :1.565
## 3rd Qu.:1777 3rd Qu.:1.0000 3rd Qu.:0.00000 3rd Qu.:2.000
## Max. :5642 Max. :3.0000 Max. :2.00000 Max. :3.000
##
## HalfBath BedroomAbvGr KitchenAbvGr KitchenQual
## Min. :0.0000 Min. :0.000 Min. :0.000 Ex:100
## 1st Qu.:0.0000 1st Qu.:2.000 1st Qu.:1.000 Fa: 39
## Median :0.0000 Median :3.000 Median :1.000 Gd:586
## Mean :0.3829 Mean :2.866 Mean :1.047 TA:735
## 3rd Qu.:1.0000 3rd Qu.:3.000 3rd Qu.:1.000
## Max. :2.0000 Max. :8.000 Max. :3.000
##
## TotRmsAbvGrd Functional Fireplaces FireplaceQu GarageType
## Min. : 2.000 Maj1: 14 Min. :0.000 Ex : 24 2Types : 6
## 1st Qu.: 5.000 Maj2: 5 1st Qu.:0.000 Fa : 33 Attchd :870
## Median : 6.000 Min1: 31 Median :1.000 Gd :380 Basment: 19
## Mean : 6.518 Min2: 34 Mean :0.613 Po : 20 BuiltIn: 88
## 3rd Qu.: 7.000 Mod : 15 3rd Qu.:1.000 TA :313 CarPort: 9
## Max. :14.000 Sev : 1 Max. :3.000 NA's:690 Detchd :387
## Typ :1360 NA's : 81
## GarageYrBlt GarageFinish GarageCars GarageArea GarageQual
## Min. :1900 Fin :352 Min. :0.000 Min. : 0.0 Ex : 3
## 1st Qu.:1961 RFn :422 1st Qu.:1.000 1st Qu.: 334.5 Fa : 48
## Median :1980 Unf :605 Median :2.000 Median : 480.0 Gd : 14
## Mean :1979 NA's: 81 Mean :1.767 Mean : 473.0 Po : 3
## 3rd Qu.:2002 3rd Qu.:2.000 3rd Qu.: 576.0 TA :1311
## Max. :2010 Max. :4.000 Max. :1418.0 NA's: 81
## NA's :81
## GarageCond PavedDrive WoodDeckSF OpenPorchSF EnclosedPorch
## Ex : 2 N: 90 Min. : 0.00 Min. : 0.00 Min. : 0.00
## Fa : 35 P: 30 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.00
## Gd : 9 Y:1340 Median : 0.00 Median : 25.00 Median : 0.00
## Po : 7 Mean : 94.24 Mean : 46.66 Mean : 21.95
## TA :1326 3rd Qu.:168.00 3rd Qu.: 68.00 3rd Qu.: 0.00
## NA's: 81 Max. :857.00 Max. :547.00 Max. :552.00
##
## X3SsnPorch ScreenPorch PoolArea PoolQC
## Min. : 0.00 Min. : 0.00 Min. : 0.000 Ex : 2
## 1st Qu.: 0.00 1st Qu.: 0.00 1st Qu.: 0.000 Fa : 2
## Median : 0.00 Median : 0.00 Median : 0.000 Gd : 3
## Mean : 3.41 Mean : 15.06 Mean : 2.759 NA's:1453
## 3rd Qu.: 0.00 3rd Qu.: 0.00 3rd Qu.: 0.000
## Max. :508.00 Max. :480.00 Max. :738.000
##
## Fence MiscFeature MiscVal MoSold
## GdPrv: 59 Gar2: 2 Min. : 0.00 Min. : 1.000
## GdWo : 54 Othr: 2 1st Qu.: 0.00 1st Qu.: 5.000
## MnPrv: 157 Shed: 49 Median : 0.00 Median : 6.000
## MnWw : 11 TenC: 1 Mean : 43.49 Mean : 6.322
## NA's :1179 NA's:1406 3rd Qu.: 0.00 3rd Qu.: 8.000
## Max. :15500.00 Max. :12.000
##
## YrSold SaleType SaleCondition SalePrice
## Min. :2006 WD :1267 Abnorml: 101 Min. : 34900
## 1st Qu.:2007 New : 122 AdjLand: 4 1st Qu.:129975
## Median :2008 COD : 43 Alloca : 12 Median :163000
## Mean :2008 ConLD : 9 Family : 20 Mean :180921
## 3rd Qu.:2009 ConLI : 5 Normal :1198 3rd Qu.:214000
## Max. :2010 ConLw : 5 Partial: 125 Max. :755000
## (Other): 9
I have categorized all the Numeric variables present in the data set into ‘Discrete’ and ‘Continuous’. Similarly Categorical variables into ‘Ordinal’ and ‘Nominal’.
num_discrete <- c('BsmtFullBath','BsmtHalfBath','FullBath','HalfBath','BedroomAbvGr','KitchenAbvGr','TotRmsAbvGrd',
'Fireplaces','GarageCars','GarageYrBlt','YearBuilt','YearRemodAdd','YrSold','MoSold')
num_continuous <- c('LotFrontage','LotArea','MasVnrArea','BsmtFinSF1','BsmtFinSF2','BsmtUnfSF','TotalBsmtSF','1stFlrSF',
'2ndFlrSF','LowQualFinSF','GrLivArea','GarageArea','WoodDeckSF','OpenPorchSF','EnclosedPorch',
'3SsnPorch','ScreenPorch','PoolArea','MiscVal','SalePrice')
cat_ordinal <- c('LotShape','Utilities','LandSlope','OverallQual','OverallCond','ExterQual','ExterCond',
'BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2','HeatingQC','CentralAir',
'Electrical','KitchenQual','Functional','FireplaceQu','GarageFinish','GarageQual','GarageCond',
'PavedDrive','PoolQC','Fence')
cat_nominal <- c('MSSubClass','MSZoning','Street','Alley','LandContour','LotConfig','Neighborhood',
'Condition1','Condition2','BldgType','HouseStyle','RoofStyle','RoofMatl','Exterior1st',
'Exterior2nd','MasVnrType','Foundation','Heating','GarageType','MiscFeature',
'SaleType','SaleCondition')Consolidate similar variables like No. of Bathrooms - BsmtFullBath, BsmtHalfBath, FullBath, HalfBath etc. into a single variable Baths.
# Those variables tell almost the same information, so let's add them.
housing_pr_train$Baths <- housing_pr_train$BsmtFullBath + 0.5*housing_pr_train$BsmtHalfBath + housing_pr_train$FullBath + 0.5*housing_pr_train$HalfBath
# Derive CentralAirScore as discrete variable
housing_pr_train$CentralAirScore <- ifelse(housing_pr_train$CentralAir == "N", 0, 1)
# Remove redundant variables
housing_pr_train <- subset(housing_pr_train, select = -c(Id,BsmtFullBath,BsmtHalfBath,FullBath,HalfBath))
# Remove Variable with 'NA' values
housing_pr_train <- housing_pr_train %>% subset(select = -c(LotFrontage,MasVnrArea,GarageYrBlt))For building the scatterplot matrix with the dependant variable (SalePrice), I have chosen following independent variables - LotArea, TotRmsAbvGrd, Total No. of Bathrooms(Baths), GrLivArea, GarageCars etc.
train_subset <- subset(housing_pr_train,select = c(LotArea,TotRmsAbvGrd,Baths,GrLivArea,OverallQual,SalePrice))
p <- ggpairs(data=train_subset, # data.frame with variables
columns=1:6, # columns to plot, default to all.
title="House Prices data") # title of the plot
ggplotly(p)From the Scatterplot matrix above, Overall Quality can be inferred as an influential variable for the SalePrice of a house.
train_subset$OverallQual_factor <- factor(train_subset$OverallQual)
p <- ggplot(train_subset, aes(x=OverallQual, y=SalePrice, fill=OverallQual_factor, group=OverallQual_factor)) +
geom_boxplot() +
ggtitle("Sale Price Vs. Overall Quality")
ggplotly(p)From the Scatterplot matrix above, No. of Bathrooms is also identified as an influential variable for the SalePrice of a house.
train_subset$OverallQual_factor <- factor(train_subset$OverallQual)
p <- ggplot(train_subset, aes(x=Baths, y=SalePrice, fill=Baths, group=Baths)) +
geom_boxplot() +
ggtitle("Sale Price Vs. No. of Bathrooms")
ggplotly(p)housing_pr_train_num <- housing_pr_train %>% select_if(is.numeric)
corrMatrix <- round(cor(housing_pr_train_num),4)
corrMatrix %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MSSubClass | 1.0000 | -0.1398 | 0.0326 | -0.0593 | 0.0279 | 0.0406 | -0.0698 | -0.0656 | -0.1408 | -0.2385 | -0.2518 | 0.3079 | 0.0465 | 0.0749 | -0.0234 | 0.2817 | 0.0404 | -0.0456 | -0.0401 | -0.0987 | -0.0126 | -0.0061 | -0.0120 | -0.0438 | -0.0260 | 0.0083 | -0.0077 | -0.0136 | -0.0214 | -0.0843 | 0.1510 | -0.1018 |
| LotArea | -0.1398 | 1.0000 | 0.1058 | -0.0056 | 0.0142 | 0.0138 | 0.2141 | 0.1112 | -0.0026 | 0.2608 | 0.2995 | 0.0510 | 0.0048 | 0.2631 | 0.1197 | -0.0178 | 0.1900 | 0.2714 | 0.1549 | 0.1804 | 0.1717 | 0.0848 | -0.0183 | 0.0204 | 0.0432 | 0.0777 | 0.0381 | 0.0012 | -0.0143 | 0.2638 | 0.2048 | 0.0498 |
| OverallQual | 0.0326 | 0.1058 | 1.0000 | -0.0919 | 0.5723 | 0.5507 | 0.2397 | -0.0591 | 0.3082 | 0.5378 | 0.4762 | 0.2955 | -0.0304 | 0.5930 | 0.1017 | -0.1839 | 0.4275 | 0.3968 | 0.6007 | 0.5620 | 0.2389 | 0.3088 | -0.1139 | 0.0304 | 0.0649 | 0.0652 | -0.0314 | 0.0708 | -0.0273 | 0.7910 | 0.5411 | 0.2720 |
| OverallCond | -0.0593 | -0.0056 | -0.0919 | 1.0000 | -0.3760 | 0.0737 | -0.0462 | 0.0402 | -0.1368 | -0.1711 | -0.1442 | 0.0289 | 0.0255 | -0.0797 | 0.0130 | -0.0870 | -0.0576 | -0.0238 | -0.1858 | -0.1515 | -0.0033 | -0.0326 | 0.0704 | 0.0255 | 0.0548 | -0.0020 | 0.0688 | -0.0035 | 0.0439 | -0.0779 | -0.1740 | 0.1190 |
| YearBuilt | 0.0279 | 0.0142 | 0.5723 | -0.3760 | 1.0000 | 0.5929 | 0.2495 | -0.0491 | 0.1490 | 0.3915 | 0.2820 | 0.0103 | -0.1838 | 0.1990 | -0.0707 | -0.1748 | 0.0956 | 0.1477 | 0.5379 | 0.4790 | 0.2249 | 0.1887 | -0.3873 | 0.0314 | -0.0504 | 0.0049 | -0.0344 | 0.0124 | -0.0136 | 0.5229 | 0.5243 | 0.3818 |
| YearRemodAdd | 0.0406 | 0.0138 | 0.5507 | 0.0737 | 0.5929 | 1.0000 | 0.1285 | -0.0678 | 0.1811 | 0.2911 | 0.2404 | 0.1400 | -0.0624 | 0.2874 | -0.0406 | -0.1496 | 0.1917 | 0.1126 | 0.4206 | 0.3716 | 0.2057 | 0.2263 | -0.1939 | 0.0453 | -0.0387 | 0.0058 | -0.0103 | 0.0215 | 0.0357 | 0.5071 | 0.4437 | 0.2989 |
| BsmtFinSF1 | -0.0698 | 0.2141 | 0.2397 | -0.0462 | 0.2495 | 0.1285 | 1.0000 | -0.0501 | -0.4953 | 0.5224 | 0.4459 | -0.1371 | -0.0645 | 0.2082 | -0.1074 | -0.0810 | 0.0443 | 0.2600 | 0.2241 | 0.2970 | 0.2043 | 0.1118 | -0.1023 | 0.0265 | 0.0620 | 0.1405 | 0.0036 | -0.0157 | 0.0144 | 0.3864 | 0.4816 | 0.1665 |
| BsmtFinSF2 | -0.0656 | 0.1112 | -0.0591 | 0.0402 | -0.0491 | -0.0678 | -0.0501 | 1.0000 | -0.2093 | 0.1048 | 0.0971 | -0.0993 | 0.0148 | -0.0096 | -0.0157 | -0.0408 | -0.0352 | 0.0469 | -0.0383 | -0.0182 | 0.0679 | 0.0031 | 0.0365 | -0.0300 | 0.0889 | 0.0417 | 0.0049 | -0.0152 | 0.0317 | -0.0114 | 0.0517 | 0.0399 |
| BsmtUnfSF | -0.1408 | -0.0026 | 0.3082 | -0.1368 | 0.1490 | 0.1811 | -0.4953 | -0.2093 | 1.0000 | 0.4154 | 0.3180 | 0.0045 | 0.0282 | 0.2403 | 0.1666 | 0.0301 | 0.2506 | 0.0516 | 0.2142 | 0.1833 | -0.0053 | 0.1290 | -0.0025 | 0.0208 | -0.0126 | -0.0351 | -0.0238 | 0.0349 | -0.0413 | 0.2145 | -0.1045 | 0.0201 |
| TotalBsmtSF | -0.2385 | 0.2608 | 0.5378 | -0.1711 | 0.3915 | 0.2911 | 0.5224 | 0.1048 | 0.4154 | 1.0000 | 0.8195 | -0.1745 | -0.0332 | 0.4549 | 0.0504 | -0.0689 | 0.2856 | 0.3395 | 0.4346 | 0.4867 | 0.2320 | 0.2473 | -0.0955 | 0.0374 | 0.0845 | 0.1261 | -0.0185 | 0.0132 | -0.0150 | 0.6136 | 0.4145 | 0.2080 |
| X1stFlrSF | -0.2518 | 0.2995 | 0.4762 | -0.1442 | 0.2820 | 0.2404 | 0.4459 | 0.0971 | 0.3180 | 0.8195 | 1.0000 | -0.2026 | -0.0142 | 0.5660 | 0.1274 | 0.0681 | 0.4095 | 0.4105 | 0.4393 | 0.4898 | 0.2355 | 0.2117 | -0.0653 | 0.0561 | 0.0888 | 0.1315 | -0.0211 | 0.0314 | -0.0136 | 0.6059 | 0.3906 | 0.1470 |
| X2ndFlrSF | 0.3079 | 0.0510 | 0.2955 | 0.0289 | 0.0103 | 0.1400 | -0.1371 | -0.0993 | 0.0045 | -0.1745 | -0.2026 | 1.0000 | 0.0634 | 0.6875 | 0.5029 | 0.0593 | 0.6164 | 0.1946 | 0.1839 | 0.1383 | 0.0922 | 0.2080 | 0.0620 | -0.0244 | 0.0406 | 0.0815 | 0.0162 | 0.0352 | -0.0287 | 0.3193 | 0.3752 | -0.0118 |
| LowQualFinSF | 0.0465 | 0.0048 | -0.0304 | 0.0255 | -0.1838 | -0.0624 | -0.0645 | 0.0148 | 0.0282 | -0.0332 | -0.0142 | 0.0634 | 1.0000 | 0.1347 | 0.1056 | 0.0075 | 0.1312 | -0.0213 | -0.0945 | -0.0676 | -0.0254 | 0.0183 | 0.0611 | -0.0043 | 0.0268 | 0.0622 | -0.0038 | -0.0222 | -0.0289 | -0.0256 | -0.0412 | -0.0501 |
| GrLivArea | 0.0749 | 0.2631 | 0.5930 | -0.0797 | 0.1990 | 0.2874 | 0.2082 | -0.0096 | 0.2403 | 0.4549 | 0.5660 | 0.6875 | 0.1347 | 1.0000 | 0.5213 | 0.1001 | 0.8255 | 0.4617 | 0.4672 | 0.4690 | 0.2474 | 0.3302 | 0.0091 | 0.0206 | 0.1015 | 0.1702 | -0.0024 | 0.0502 | -0.0365 | 0.7086 | 0.5952 | 0.0937 |
| BedroomAbvGr | -0.0234 | 0.1197 | 0.1017 | 0.0130 | -0.0707 | -0.0406 | -0.1074 | -0.0157 | 0.1666 | 0.0504 | 0.1274 | 0.5029 | 0.1056 | 0.5213 | 1.0000 | 0.1986 | 0.6766 | 0.1076 | 0.0861 | 0.0653 | 0.0469 | 0.0938 | 0.0416 | -0.0245 | 0.0443 | 0.0707 | 0.0078 | 0.0465 | -0.0360 | 0.1682 | 0.2349 | 0.0079 |
| KitchenAbvGr | 0.2817 | -0.0178 | -0.1839 | -0.0870 | -0.1748 | -0.1496 | -0.0810 | -0.0408 | 0.0301 | -0.0689 | 0.0681 | 0.0593 | 0.0075 | 0.1001 | 0.1986 | 1.0000 | 0.2560 | -0.1239 | -0.0506 | -0.0644 | -0.0901 | -0.0701 | 0.0373 | -0.0246 | -0.0516 | -0.0145 | 0.0623 | 0.0266 | 0.0317 | -0.1359 | 0.0383 | -0.2468 |
| TotRmsAbvGrd | 0.0404 | 0.1900 | 0.4275 | -0.0576 | 0.0956 | 0.1917 | 0.0443 | -0.0352 | 0.2506 | 0.2856 | 0.4095 | 0.6164 | 0.1312 | 0.8255 | 0.6766 | 0.2560 | 1.0000 | 0.3261 | 0.3623 | 0.3378 | 0.1660 | 0.2342 | 0.0042 | -0.0067 | 0.0594 | 0.0838 | 0.0248 | 0.0369 | -0.0345 | 0.5337 | 0.4603 | 0.0345 |
| Fireplaces | -0.0456 | 0.2714 | 0.3968 | -0.0238 | 0.1477 | 0.1126 | 0.2600 | 0.0469 | 0.0516 | 0.3395 | 0.4105 | 0.1946 | -0.0213 | 0.4617 | 0.1076 | -0.1239 | 0.3261 | 1.0000 | 0.3008 | 0.2691 | 0.2000 | 0.1694 | -0.0248 | 0.0113 | 0.1845 | 0.0951 | 0.0014 | 0.0464 | -0.0241 | 0.4669 | 0.3317 | 0.1863 |
| GarageCars | -0.0401 | 0.1549 | 0.6007 | -0.1858 | 0.5379 | 0.4206 | 0.2241 | -0.0383 | 0.2142 | 0.4346 | 0.4393 | 0.1839 | -0.0945 | 0.4672 | 0.0861 | -0.0506 | 0.3623 | 0.3008 | 1.0000 | 0.8825 | 0.2263 | 0.2136 | -0.1514 | 0.0358 | 0.0505 | 0.0209 | -0.0431 | 0.0405 | -0.0391 | 0.6404 | 0.4836 | 0.2337 |
| GarageArea | -0.0987 | 0.1804 | 0.5620 | -0.1515 | 0.4790 | 0.3716 | 0.2970 | -0.0182 | 0.1833 | 0.4867 | 0.4898 | 0.1383 | -0.0676 | 0.4690 | 0.0653 | -0.0644 | 0.3378 | 0.2691 | 0.8825 | 1.0000 | 0.2247 | 0.2414 | -0.1218 | 0.0351 | 0.0514 | 0.0610 | -0.0274 | 0.0280 | -0.0274 | 0.6234 | 0.4516 | 0.2307 |
| WoodDeckSF | -0.0126 | 0.1717 | 0.2389 | -0.0033 | 0.2249 | 0.2057 | 0.2043 | 0.0679 | -0.0053 | 0.2320 | 0.2355 | 0.0922 | -0.0254 | 0.2474 | 0.0469 | -0.0901 | 0.1660 | 0.2000 | 0.2263 | 0.2247 | 1.0000 | 0.0587 | -0.1260 | -0.0328 | -0.0742 | 0.0734 | -0.0096 | 0.0210 | 0.0223 | 0.3244 | 0.2882 | 0.1460 |
| OpenPorchSF | -0.0061 | 0.0848 | 0.3088 | -0.0326 | 0.1887 | 0.2263 | 0.1118 | 0.0031 | 0.1290 | 0.2473 | 0.2117 | 0.2080 | 0.0183 | 0.3302 | 0.0938 | -0.0701 | 0.2342 | 0.1694 | 0.2136 | 0.2414 | 0.0587 | 1.0000 | -0.0931 | -0.0058 | 0.0743 | 0.0608 | -0.0186 | 0.0713 | -0.0576 | 0.3159 | 0.2869 | 0.0259 |
| EnclosedPorch | -0.0120 | -0.0183 | -0.1139 | 0.0704 | -0.3873 | -0.1939 | -0.1023 | 0.0365 | -0.0025 | -0.0955 | -0.0653 | 0.0620 | 0.0611 | 0.0091 | 0.0416 | 0.0373 | 0.0042 | -0.0248 | -0.1514 | -0.1218 | -0.1260 | -0.0931 | 1.0000 | -0.0373 | -0.0829 | 0.0542 | 0.0184 | -0.0289 | -0.0099 | -0.1286 | -0.1455 | -0.1569 |
| X3SsnPorch | -0.0438 | 0.0204 | 0.0304 | 0.0255 | 0.0314 | 0.0453 | 0.0265 | -0.0300 | 0.0208 | 0.0374 | 0.0561 | -0.0244 | -0.0043 | 0.0206 | -0.0245 | -0.0246 | -0.0067 | 0.0113 | 0.0358 | 0.0351 | -0.0328 | -0.0058 | -0.0373 | 1.0000 | -0.0314 | -0.0080 | 0.0004 | 0.0295 | 0.0186 | 0.0446 | 0.0285 | 0.0307 |
| ScreenPorch | -0.0260 | 0.0432 | 0.0649 | 0.0548 | -0.0504 | -0.0387 | 0.0620 | 0.0889 | -0.0126 | 0.0845 | 0.0888 | 0.0406 | 0.0268 | 0.1015 | 0.0443 | -0.0516 | 0.0594 | 0.1845 | 0.0505 | 0.0514 | -0.0742 | 0.0743 | -0.0829 | -0.0314 | 1.0000 | 0.0513 | 0.0319 | 0.0232 | 0.0107 | 0.1114 | 0.0377 | 0.0512 |
| PoolArea | 0.0083 | 0.0777 | 0.0652 | -0.0020 | 0.0049 | 0.0058 | 0.1405 | 0.0417 | -0.0351 | 0.1261 | 0.1315 | 0.0815 | 0.0622 | 0.1702 | 0.0707 | -0.0145 | 0.0838 | 0.0951 | 0.0209 | 0.0610 | 0.0734 | 0.0608 | 0.0542 | -0.0080 | 0.0513 | 1.0000 | 0.0297 | -0.0337 | -0.0597 | 0.0924 | 0.0897 | 0.0181 |
| MiscVal | -0.0077 | 0.0381 | -0.0314 | 0.0688 | -0.0344 | -0.0103 | 0.0036 | 0.0049 | -0.0238 | -0.0185 | -0.0211 | 0.0162 | -0.0038 | -0.0024 | 0.0078 | 0.0623 | 0.0248 | 0.0014 | -0.0431 | -0.0274 | -0.0096 | -0.0186 | 0.0184 | 0.0004 | 0.0319 | 0.0297 | 1.0000 | -0.0065 | 0.0049 | -0.0212 | -0.0260 | -0.0025 |
| MoSold | -0.0136 | 0.0012 | 0.0708 | -0.0035 | 0.0124 | 0.0215 | -0.0157 | -0.0152 | 0.0349 | 0.0132 | 0.0314 | 0.0352 | -0.0222 | 0.0502 | 0.0465 | 0.0266 | 0.0369 | 0.0464 | 0.0405 | 0.0280 | 0.0210 | 0.0713 | -0.0289 | 0.0295 | 0.0232 | -0.0337 | -0.0065 | 1.0000 | -0.1457 | 0.0464 | 0.0245 | 0.0098 |
| YrSold | -0.0214 | -0.0143 | -0.0273 | 0.0439 | -0.0136 | 0.0357 | 0.0144 | 0.0317 | -0.0413 | -0.0150 | -0.0136 | -0.0287 | -0.0289 | -0.0365 | -0.0360 | 0.0317 | -0.0345 | -0.0241 | -0.0391 | -0.0274 | 0.0223 | -0.0576 | -0.0099 | 0.0186 | 0.0107 | -0.0597 | 0.0049 | -0.1457 | 1.0000 | -0.0289 | 0.0201 | -0.0094 |
| SalePrice | -0.0843 | 0.2638 | 0.7910 | -0.0779 | 0.5229 | 0.5071 | 0.3864 | -0.0114 | 0.2145 | 0.6136 | 0.6059 | 0.3193 | -0.0256 | 0.7086 | 0.1682 | -0.1359 | 0.5337 | 0.4669 | 0.6404 | 0.6234 | 0.3244 | 0.3159 | -0.1286 | 0.0446 | 0.1114 | 0.0924 | -0.0212 | 0.0464 | -0.0289 | 1.0000 | 0.6317 | 0.2513 |
| Baths | 0.1510 | 0.2048 | 0.5411 | -0.1740 | 0.5243 | 0.4437 | 0.4816 | 0.0517 | -0.1045 | 0.4145 | 0.3906 | 0.3752 | -0.0412 | 0.5952 | 0.2349 | 0.0383 | 0.4603 | 0.3317 | 0.4836 | 0.4516 | 0.2882 | 0.2869 | -0.1455 | 0.0285 | 0.0377 | 0.0897 | -0.0260 | 0.0245 | 0.0201 | 0.6317 | 1.0000 | 0.2016 |
| CentralAirScore | -0.1018 | 0.0498 | 0.2720 | 0.1190 | 0.3818 | 0.2989 | 0.1665 | 0.0399 | 0.0201 | 0.2080 | 0.1470 | -0.0118 | -0.0501 | 0.0937 | 0.0079 | -0.2468 | 0.0345 | 0.1863 | 0.2337 | 0.2307 | 0.1460 | 0.0259 | -0.1569 | 0.0307 | 0.0512 | 0.0181 | -0.0025 | 0.0098 | -0.0094 | 0.2513 | 0.2016 | 1.0000 |
corrplot(corrMatrix,method ="color")corrplot(corrMatrix, method = "color", outline = T, addgrid.col = "darkgray", order="hclust", addrect = 4, rect.col = "black", rect.lwd = 5,cl.pos = "b", tl.col = "indianred4", tl.cex = 1.5, cl.cex = 1.5, addCoef.col = "white", number.digits = 2, number.cex = 0.75, col = colorRampPalette(c("darkred","white","midnightblue"))(100))Based on the above Corrleation plot, 3 variables with highest correlation scores are - OverallQual, GrLivArea and GarageCars.
Test the hypotheses that the correlations between each pairwise set of variables is 0 and provide an 80% confidence interval. Discuss the meaning of your analysis.
corr_train_data <- subset(housing_pr_train_num, select=c(OverallQual,GrLivArea,GarageCars,SalePrice))Null Hypothesis \({ H }_{ 0 }\): Correlation between House Sale Price and Overll Quality of houses is zero.
Alt. Hypothesis \({ H }_{ A }\): Correlation between House Sale Price and Overll Quality of houses is not zero.
cor.test(corr_train_data$SalePrice,corr_train_data$OverallQual, conf.level = 0.8)##
## Pearson's product-moment correlation
##
## data: corr_train_data$SalePrice and corr_train_data$OverallQual
## t = 49.364, df = 1458, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 80 percent confidence interval:
## 0.7780752 0.8032204
## sample estimates:
## cor
## 0.7909816
With a low P value, we are confident the correlation between these two variables is not zero, and we are 80% confident it is between 0.778 and 0.803. Hence we accept alternate hypothesis.
Null Hypothesis \({ H }_{ 0 }\): Correlation between House Sale Price and GrLivAreay of houses is zero.
Alt. Hypothesis \({ H }_{ A }\): Correlation between House Sale Price and GrLivArea of houses is not zero.
cor.test(corr_train_data$SalePrice,corr_train_data$GrLivArea, conf.level = 0.8)##
## Pearson's product-moment correlation
##
## data: corr_train_data$SalePrice and corr_train_data$GrLivArea
## t = 38.348, df = 1458, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 80 percent confidence interval:
## 0.6915087 0.7249450
## sample estimates:
## cor
## 0.7086245
With a low P value, we are confident the correlation between these two variables is not zero, and we are 80% confident it is between 0.692 and 0.725. Hence we accept alternate hypothesis.
#### 3. SalePrice Vs. Size of garage in car capacity(GarageCars)q Null Hypothesis \({ H }_{ 0 }\): Correlation between House Sale Price and GarageCars of houses is zero.
Alt. Hypothesis \({ H }_{ A }\): Correlation between House Sale Price and GarageCars of houses is not zero.
cor.test(corr_train_data$SalePrice,corr_train_data$GarageCars, conf.level = 0.8)##
## Pearson's product-moment correlation
##
## data: corr_train_data$SalePrice and corr_train_data$GarageCars
## t = 31.839, df = 1458, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 80 percent confidence interval:
## 0.6201771 0.6597899
## sample estimates:
## cor
## 0.6404092
With a low P value, we are confident the correlation between these two variables is not zero, and we are 80% confident it is between 0.620 and 0.659. Hence we accept alternate hypothesis.
I will not be worried about Family Wise Error in this case, since for all 3 variables I have suffcient statistical evidence to reject the Null Hypothesis.
Invert your correlation matrix from above. (This is known as the precision matrix and contains variance inflation factors on the diagonal.) Multiply the correlation matrix by the precision matrix, and then multiply the precision matrix by the correlation matrix. Conduct LU decomposition on the matrix.
Ans:
Invert the correlation matrix to create the precision matrix:
precMatrix <- solve(corrMatrix)
precMatrix %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MSSubClass | 1.5187929 | 0.0896258 | -0.3728027 | 0.0192462 | -0.1294784 | -0.0281652 | -0.3266891 | -0.0973287 | -0.2304666 | 0.3868408 | 0.8815329 | 0.3119878 | -0.0060351 | -1.1792054 | 0.2878876 | -0.5186781 | 0.2580809 | -0.0355909 | -0.0854236 | 0.2122713 | -0.0452697 | 0.0418729 | 0.0251561 | 0.0322569 | -0.0314368 | -0.0136819 | 0.0349678 | 0.0487569 | 0.0693108 | 0.4541448 | -0.2475740 | 0.0586666 |
| LotArea | 0.0896258 | 1.2286247 | 0.2526113 | 0.0205515 | 0.1772295 | 0.0356887 | 0.3605135 | 0.0630309 | 0.3971923 | -0.4585826 | -0.3882111 | -0.3354522 | -0.0255314 | 0.2992615 | -0.0687503 | 0.0137128 | 0.0919937 | -0.1716822 | -0.0112965 | -0.0478966 | -0.0780148 | 0.0002499 | 0.0489740 | -0.0101098 | 0.0423613 | -0.0119318 | -0.0509599 | 0.0142185 | 0.0165527 | -0.2649300 | -0.1016003 | -0.0020999 |
| OverallQual | -0.3728027 | 0.2526113 | 3.7195170 | -0.2302517 | -0.7600601 | -0.2615928 | 2.6379228 | 0.9683630 | 2.1290467 | -2.8918479 | 0.5926402 | 0.4332855 | 0.0331779 | -1.0559318 | 0.2318922 | 0.3819201 | -0.1609482 | -0.2208109 | -0.3062727 | 0.0254338 | 0.1161789 | -0.0689868 | -0.1975677 | 0.0298428 | 0.0157615 | 0.0154577 | 0.0108863 | -0.1415124 | -0.0370148 | -1.6280933 | 0.0057152 | -0.0013015 |
| OverallCond | 0.0192462 | 0.0205515 | -0.2302517 | 1.6852943 | 1.3850804 | -0.7131503 | -0.0539844 | -0.0460802 | 0.1313585 | 0.1212273 | 0.1207346 | 0.0412350 | 0.1009629 | 0.2312606 | -0.1981359 | 0.0430524 | 0.1235128 | 0.0073703 | 0.1515479 | -0.1011573 | -0.0621166 | -0.0372609 | 0.1728914 | -0.0398407 | -0.0037972 | -0.0160637 | -0.0845752 | 0.0216522 | -0.0251138 | -0.3694899 | 0.1235527 | -0.4029192 |
| YearBuilt | -0.1294784 | 0.1772295 | -0.7600601 | 1.3850804 | 4.1640910 | -1.1376843 | -1.0965069 | -0.3970827 | -1.2223569 | 1.0193900 | -0.1815921 | -0.2136660 | 0.2633852 | 1.3964835 | -0.2620557 | 0.1508261 | 0.3691451 | 0.1294159 | -0.4088882 | -0.1070433 | -0.0455798 | -0.0142679 | 0.7970473 | 0.0085539 | 0.2241807 | -0.0776674 | -0.0933470 | 0.0776147 | 0.0449552 | -0.7129222 | -0.9057226 | -0.7067990 |
| YearRemodAdd | -0.0281652 | 0.0356887 | -0.2615928 | -0.7131503 | -1.1376843 | 2.2162347 | -0.0118517 | 0.0162748 | -0.3516506 | 0.3278749 | 0.5336157 | 0.7533361 | 0.0182839 | -0.9759247 | 0.3499482 | 0.0704274 | -0.1690508 | 0.2457118 | -0.1364954 | 0.1683705 | -0.0311433 | -0.0937114 | -0.0722429 | -0.0103045 | 0.0585208 | 0.0035889 | -0.0039778 | -0.0150763 | -0.0827315 | -0.1958077 | -0.3945433 | -0.0249592 |
| BsmtFinSF1 | -0.3266891 | 0.3605135 | 2.6379228 | -0.0539844 | -1.0965069 | -0.0118517 | -6081.2006422 | -2151.1712098 | -5893.1072242 | 5849.7033555 | -674.0564312 | -762.0888549 | -84.9733601 | 920.5059851 | 0.5334566 | 0.4507445 | -3.0073581 | -0.4749160 | 2.3964999 | -1.9906259 | 0.3296336 | 0.1404175 | -0.0185164 | 0.3488403 | -0.3231962 | -0.5720369 | 0.4849930 | 0.1715235 | 0.1605179 | -2.2513881 | -1.2301068 | 0.2845166 |
| BsmtFinSF2 | -0.0973287 | 0.0630309 | 0.9683630 | -0.0460802 | -0.3970827 | 0.0162748 | -2151.1712098 | -759.8151773 | -2084.2773993 | 2068.9496512 | -237.7561951 | -268.7410383 | -29.9887063 | 324.6211598 | 0.1596079 | 0.2008021 | -1.0975963 | -0.1462996 | 0.7757920 | -0.6017772 | 0.0578102 | 0.0244388 | -0.0693203 | 0.1516215 | -0.2011882 | -0.1927933 | 0.1776360 | 0.0594454 | 0.0306899 | -0.6378003 | -0.3979701 | 0.0752365 |
| BsmtUnfSF | -0.2304666 | 0.3971923 | 2.1290467 | 0.1313585 | -1.2223569 | -0.3516506 | -5893.1072242 | -2084.2773993 | -5708.8051564 | 5667.5405647 | -653.5589414 | -739.2352494 | -82.4358202 | 892.5066898 | 0.2709481 | 0.3142328 | -3.1648903 | -0.3627352 | 1.8969195 | -1.5501798 | 0.3568447 | 0.0561981 | -0.0808533 | 0.3122064 | -0.2990549 | -0.4158191 | 0.5054999 | 0.1559984 | 0.1625537 | -1.7899723 | 0.0170691 | 0.3508237 |
| TotalBsmtSF | 0.3868408 | -0.4585826 | -2.8918479 | 0.1212273 | 1.0193900 | 0.3278749 | 5849.7033555 | 2068.9496512 | 5667.5405647 | -5622.4778577 | 648.5758435 | 736.5698612 | 82.0899364 | -888.9931141 | -0.4772984 | -0.2319624 | 3.3647617 | 0.5702412 | -1.7031882 | 1.4144370 | -0.3510774 | -0.2597476 | 0.0289856 | -0.2782575 | 0.2644169 | 0.3880750 | -0.5281458 | -0.0888259 | -0.1508482 | 1.4617095 | 0.2156941 | -0.4257052 |
| X1stFlrSF | 0.8815329 | -0.3882111 | 0.5926402 | 0.1207346 | -0.1815921 | 0.5336157 | -674.0564312 | -237.7561951 | -653.5589414 | 648.5758435 | 5180.4586671 | 5848.1465220 | 650.8760929 | -7039.7518114 | 0.4650636 | -0.1848814 | 0.3671321 | 0.2777617 | -0.8720624 | 1.1639323 | -0.8370026 | -0.2443897 | -0.3634361 | -0.0011621 | -0.4788594 | -0.1459882 | 0.1647503 | -0.5817615 | 0.0729080 | -1.2012921 | -0.9304826 | -0.0761503 |
| X2ndFlrSF | 0.3119878 | -0.3354522 | 0.4332855 | 0.0412350 | -0.2136660 | 0.7533361 | -762.0888549 | -268.7410383 | -739.2352494 | 736.5698612 | 5848.1465220 | 6607.4187144 | 735.2965696 | -7952.1470869 | 0.1344684 | 0.5408196 | 0.4240139 | 0.7205234 | -0.9922997 | 1.5718057 | -0.8767633 | -0.4402663 | -0.4725391 | 0.1029198 | -0.5514440 | -0.1661124 | 0.0800826 | -0.6282969 | 0.0674675 | -1.2661755 | -1.5808144 | -0.1206293 |
| LowQualFinSF | -0.0060351 | -0.0255314 | 0.0331779 | 0.1009629 | 0.2633852 | 0.0182839 | -84.9733601 | -29.9887063 | -82.4358202 | 82.0899364 | 650.8760929 | 735.2965696 | 82.9336728 | -885.2454652 | 0.0684629 | 0.1488813 | -0.0425811 | 0.1715691 | 0.0098023 | 0.1376780 | -0.0884707 | -0.0425301 | -0.0039633 | 0.0056909 | -0.0704553 | -0.0547437 | 0.0179818 | -0.0424173 | 0.0348689 | -0.0817947 | -0.1244076 | -0.0634499 |
| GrLivArea | -1.1792054 | 0.2992615 | -1.0559318 | 0.2312606 | 1.3964835 | -0.9759247 | 920.5059851 | 324.6211598 | 892.5066898 | -888.9931141 | -7039.7518114 | -7952.1470869 | -885.2454652 | 9577.2989883 | -0.8557446 | -0.2501504 | -3.3203721 | -1.2727456 | 1.5698862 | -2.4966084 | 0.9654451 | 0.1784581 | 0.4436743 | -0.1826584 | 0.6564571 | -0.1658447 | -0.1131617 | 0.7291888 | -0.1116095 | -0.0661081 | 0.8306440 | 0.1477788 |
| BedroomAbvGr | 0.2878876 | -0.0687503 | 0.2318922 | -0.1981359 | -0.2620557 | 0.3499482 | 0.5334566 | 0.1596079 | 0.2709481 | -0.4772984 | 0.4650636 | 0.1344684 | 0.0684629 | -0.8557446 | 2.3328897 | 0.0346439 | -1.5547523 | 0.1886041 | -0.0118737 | 0.1961902 | 0.0199195 | 0.0734214 | -0.0102789 | 0.0285296 | -0.0587883 | -0.0470828 | 0.0521659 | -0.0706347 | 0.0262787 | 0.5526497 | -0.2918891 | -0.1121002 |
| KitchenAbvGr | -0.5186781 | 0.0137128 | 0.3819201 | 0.0430524 | 0.1508261 | 0.0704274 | 0.4507445 | 0.2008021 | 0.3142328 | -0.2319624 | -0.1848814 | 0.5408196 | 0.1488813 | -0.2501504 | 0.0346439 | 1.5978617 | -0.7645964 | 0.2072343 | -0.1087378 | 0.0122804 | 0.0985822 | 0.0786318 | 0.0426879 | 0.0211170 | 0.0438416 | 0.0064231 | -0.0892323 | -0.0774241 | -0.0682586 | 0.2115985 | -0.2625170 | 0.1735325 |
| TotRmsAbvGrd | 0.2580809 | 0.0919937 | -0.1609482 | 0.1235128 | 0.3691451 | -0.1690508 | -3.0073581 | -1.0975963 | -3.1648903 | 3.3647617 | 0.3671321 | 0.4240139 | -0.0425811 | -3.3203721 | -1.5547523 | -0.7645964 | 4.9258676 | -0.0790649 | -0.2613985 | 0.1402299 | 0.0015691 | 0.0178050 | 0.1394060 | 0.0655276 | 0.0925771 | 0.1619020 | -0.1007079 | 0.1137357 | 0.0426725 | -0.5506856 | -0.0605385 | -0.0131231 |
| Fireplaces | -0.0355909 | -0.1716822 | -0.2208109 | 0.0073703 | 0.1294159 | 0.2457118 | -0.4749160 | -0.1462996 | -0.3627352 | 0.5702412 | 0.2777617 | 0.7205234 | 0.1715691 | -1.2727456 | 0.1886041 | 0.2072343 | -0.0790649 | 1.5773935 | -0.2944998 | 0.3579616 | -0.0575346 | -0.0133843 | -0.0026849 | 0.0141650 | -0.1623785 | -0.0077151 | -0.0166039 | -0.0295346 | -0.0027785 | -0.1669234 | -0.0586763 | -0.1745289 |
| GarageCars | -0.0854236 | -0.0112965 | -0.3062727 | 0.1515479 | -0.4088882 | -0.1364954 | 2.3964999 | 0.7757920 | 1.8969195 | -1.7031882 | -0.8720624 | -0.9922997 | 0.0098023 | 1.5698862 | -0.0118737 | -0.1087378 | -0.2613985 | -0.2944998 | 5.5159885 | -4.2608057 | -0.0120595 | 0.1908130 | 0.0320692 | -0.0222845 | -0.0599161 | 0.1226352 | 0.0841633 | -0.0218457 | 0.0871742 | -0.4987449 | -0.2919750 | 0.0299363 |
| GarageArea | 0.2122713 | -0.0478966 | 0.0254338 | -0.1011573 | -0.1070433 | 0.1683705 | -1.9906259 | -0.6017772 | -1.5501798 | 1.4144370 | 1.1639323 | 1.5718057 | 0.1376780 | -2.4966084 | 0.1961902 | 0.0122804 | 0.1402299 | 0.3579616 | -4.2608057 | 5.1586993 | -0.0143448 | -0.2004188 | -0.0748826 | 0.0149721 | 0.0163981 | -0.0758021 | -0.0421272 | 0.0271031 | -0.0447443 | -0.0540746 | 0.2279026 | -0.1016034 |
| WoodDeckSF | -0.0452697 | -0.0780148 | 0.1161789 | -0.0621166 | -0.0455798 | -0.0311433 | 0.3296336 | 0.0578102 | 0.3568447 | -0.3510774 | -0.8370026 | -0.8767633 | -0.0884707 | 0.9654451 | 0.0199195 | 0.0985822 | 0.0015691 | -0.0575346 | -0.0120595 | -0.0143448 | 1.2098882 | 0.0822247 | 0.1070574 | 0.0732364 | 0.1618373 | -0.0436141 | 0.0002592 | -0.0306097 | -0.0371833 | -0.2233329 | -0.1055616 | -0.0251613 |
| OpenPorchSF | 0.0418729 | 0.0002499 | -0.0689868 | -0.0372609 | -0.0142679 | -0.0937114 | 0.1404175 | 0.0244388 | 0.0561981 | -0.2597476 | -0.2443897 | -0.4402663 | -0.0425301 | 0.1784581 | 0.0734214 | 0.0786318 | 0.0178050 | -0.0133843 | 0.1908130 | -0.2004188 | 0.0822247 | 1.2203300 | 0.0921435 | 0.0300788 | -0.0395150 | -0.0105990 | 0.0138818 | -0.0601017 | 0.0567198 | 0.0457699 | -0.1659391 | 0.1189225 |
| EnclosedPorch | 0.0251561 | 0.0489740 | -0.1975677 | 0.1728914 | 0.7970473 | -0.0722429 | -0.0185164 | -0.0693203 | -0.0808533 | 0.0289856 | -0.3634361 | -0.4725391 | -0.0039633 | 0.4436743 | -0.0102789 | 0.0426879 | 0.1394060 | -0.0026849 | 0.0320692 | -0.0748826 | 0.1070574 | 0.0921435 | 1.2791244 | 0.0425749 | 0.1682078 | -0.0648520 | -0.0274937 | 0.0361818 | 0.0161678 | -0.0438255 | -0.1028568 | -0.0204113 |
| X3SsnPorch | 0.0322569 | -0.0101098 | 0.0298428 | -0.0398407 | 0.0085539 | -0.0103045 | 0.3488403 | 0.1516215 | 0.3122064 | -0.2782575 | -0.0011621 | 0.1029198 | 0.0056909 | -0.1826584 | 0.0285296 | 0.0211170 | 0.0655276 | 0.0141650 | -0.0222845 | 0.0149721 | 0.0732364 | 0.0300788 | 0.0425749 | 1.0197154 | 0.0478761 | 0.0045333 | -0.0048382 | -0.0337145 | -0.0222234 | -0.0341076 | -0.0510731 | -0.0113314 |
| ScreenPorch | -0.0314368 | 0.0423613 | 0.0157615 | -0.0037972 | 0.2241807 | 0.0585208 | -0.3231962 | -0.2011882 | -0.2990549 | 0.2644169 | -0.4788594 | -0.5514440 | -0.0704553 | 0.6564571 | -0.0587883 | 0.0438416 | 0.0925771 | -0.1623785 | -0.0599161 | 0.0163981 | 0.1618373 | -0.0395150 | 0.1682078 | 0.0478761 | 1.1142253 | -0.0389950 | -0.0402725 | -0.0181218 | -0.0310499 | -0.2131914 | 0.0088053 | -0.0544112 |
| PoolArea | -0.0136819 | -0.0119318 | 0.0154577 | -0.0160637 | -0.0776674 | 0.0035889 | -0.5720369 | -0.1927933 | -0.4158191 | 0.3880750 | -0.1459882 | -0.1661124 | -0.0547437 | -0.1658447 | -0.0470828 | 0.0064231 | 0.1619020 | -0.0077151 | 0.1226352 | -0.0758021 | -0.0436141 | -0.0105990 | -0.0648520 | 0.0045333 | -0.0389950 | 1.0807211 | -0.0281238 | 0.0476788 | 0.0676284 | 0.1094033 | 0.0793226 | 0.0103748 |
| MiscVal | 0.0349678 | -0.0509599 | 0.0108863 | -0.0845752 | -0.0933470 | -0.0039778 | 0.4849930 | 0.1776360 | 0.5054999 | -0.5281458 | 0.1647503 | 0.0800826 | 0.0179818 | -0.1131617 | 0.0521659 | -0.0892323 | -0.1007079 | -0.0166039 | 0.0841633 | -0.0421272 | 0.0002592 | 0.0138818 | -0.0274937 | -0.0048382 | -0.0402725 | -0.0281238 | 1.0220520 | 0.0028627 | 0.0016487 | 0.0317613 | 0.0608899 | 0.0045922 |
| MoSold | 0.0487569 | 0.0142185 | -0.1415124 | 0.0216522 | 0.0776147 | -0.0150763 | 0.1715235 | 0.0594454 | 0.1559984 | -0.0888259 | -0.5817615 | -0.6282969 | -0.0424173 | 0.7291888 | -0.0706347 | -0.0774241 | 0.1137357 | -0.0295346 | -0.0218457 | 0.0271031 | -0.0306097 | -0.0601017 | 0.0361818 | -0.0337145 | -0.0181218 | 0.0476788 | 0.0028627 | 1.0459557 | 0.1552631 | 0.0158545 | -0.0018102 | -0.0106120 |
| YrSold | 0.0693108 | 0.0165527 | -0.0370148 | -0.0251138 | 0.0449552 | -0.0827315 | 0.1605179 | 0.0306899 | 0.1625537 | -0.1508482 | 0.0729080 | 0.0674675 | 0.0348689 | -0.1116095 | 0.0262787 | -0.0682586 | 0.0426725 | -0.0027785 | 0.0871742 | -0.0447443 | -0.0371833 | 0.0567198 | 0.0161678 | -0.0222234 | -0.0310499 | 0.0676284 | 0.0016487 | 0.1552631 | 1.0486723 | 0.0652605 | -0.0920085 | 0.0192693 |
| SalePrice | 0.4541448 | -0.2649300 | -1.6280933 | -0.3694899 | -0.7129222 | -0.1958077 | -2.2513881 | -0.6378003 | -1.7899723 | 1.4617095 | -1.2012921 | -1.2661755 | -0.0817947 | -0.0661081 | 0.5526497 | 0.2115985 | -0.5506856 | -0.1669234 | -0.4987449 | -0.0540746 | -0.2233329 | 0.0457699 | -0.0438255 | -0.0341076 | -0.2131914 | 0.1094033 | 0.0317613 | 0.0158545 | 0.0652605 | 5.2397928 | -0.2986324 | 0.1784433 |
| Baths | -0.2475740 | -0.1016003 | 0.0057152 | 0.1235527 | -0.9057226 | -0.3945433 | -1.2301068 | -0.3979701 | 0.0170691 | 0.2156941 | -0.9304826 | -1.5808144 | -0.1244076 | 0.8306440 | -0.2918891 | -0.2625170 | -0.0605385 | -0.0586763 | -0.2919750 | 0.2279026 | -0.1055616 | -0.1659391 | -0.1028568 | -0.0510731 | 0.0088053 | 0.0793226 | 0.0608899 | -0.0018102 | -0.0920085 | -0.2986324 | 3.1116038 | 0.0533799 |
| CentralAirScore | 0.0586666 | -0.0020999 | -0.0013015 | -0.4029192 | -0.7067990 | -0.0249592 | 0.2845166 | 0.0752365 | 0.3508237 | -0.4257052 | -0.0761503 | -0.1206293 | -0.0634499 | 0.1477788 | -0.1121002 | 0.1735325 | -0.0131231 | -0.1745289 | 0.0299363 | -0.1016034 | -0.0251613 | 0.1189225 | -0.0204113 | -0.0113314 | -0.0544112 | 0.0103748 | 0.0045922 | -0.0106120 | 0.0192693 | 0.1784433 | 0.0533799 | 1.3937145 |
The correlation matrix is now multiplied by the precision matrix (rounding to 15 digits to remove R’s decimilization at the extremes).
round(corrMatrix %*% precMatrix, 15) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MSSubClass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| LotArea | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OverallQual | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OverallCond | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| YearBuilt | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| YearRemodAdd | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtFinSF1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtFinSF2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtUnfSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| TotalBsmtSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X1stFlrSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X2ndFlrSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| LowQualFinSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GrLivArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BedroomAbvGr | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| KitchenAbvGr | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| TotRmsAbvGrd | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Fireplaces | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GarageCars | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GarageArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| WoodDeckSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OpenPorchSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| EnclosedPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X3SsnPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ScreenPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| PoolArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| MiscVal | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| MoSold | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| YrSold | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| SalePrice | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| Baths | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| CentralAirScore | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
The precision matrix is now multiplied by the correlation matrix (rounding to 15 digits to remove R’s decimilization at the extremes).
round(precMatrix %*% corrMatrix, 15) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MSSubClass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| LotArea | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OverallQual | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OverallCond | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| YearBuilt | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| YearRemodAdd | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtFinSF1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtFinSF2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BsmtUnfSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| TotalBsmtSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X1stFlrSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X2ndFlrSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| LowQualFinSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GrLivArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| BedroomAbvGr | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| KitchenAbvGr | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| TotRmsAbvGrd | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Fireplaces | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GarageCars | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GarageArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| WoodDeckSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| OpenPorchSF | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| EnclosedPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| X3SsnPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ScreenPorch | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| PoolArea | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| MiscVal | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| MoSold | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| YrSold | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| SalePrice | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| Baths | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| CentralAirScore | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
## LU Factorization Function
LUDecomposition<-function(A){
nrows<-nrow(A)
ncols<-ncol(A)
if(nrows!=ncols){
print("Please enter a square matrix for LU decomposition")
return()
}
## Initialize Lower Triangular Matrix
L<- matrix(0, nrow=nrows, ncol=ncols, byrow = T)
## Upper Triangular Matrix initialized to A
U <- A
for(i in 1:nrows){
pivotElement <- U[i,i]
L[i,i] <- 1
if(i!=nrows){
for(j in (i+1):nrows){
if(U[j,i]!=0){
multiplier <- U[j,i]/pivotElement
newRow <- U[j,] - (multiplier*U[i,])
U[j,] <- newRow
L[j,i] <- multiplier
}
}
}
}
result <- list(L,U)
return(result)
}
result <- LUDecomposition(corrMatrix)
L <- result[[1]]
U <- result[[2]]
print("The LU decomposition of the input matrix : ")## [1] "The LU decomposition of the input matrix : "
print("A")## [1] "A"
L%*%U %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1.0000 | -0.1398 | 0.0326 | -0.0593 | 0.0279 | 0.0406 | -0.0698 | -0.0656 | -0.1408 | -0.2385 | -0.2518 | 0.3079 | 0.0465 | 0.0749 | -0.0234 | 0.2817 | 0.0404 | -0.0456 | -0.0401 | -0.0987 | -0.0126 | -0.0061 | -0.0120 | -0.0438 | -0.0260 | 0.0083 | -0.0077 | -0.0136 | -0.0214 | -0.0843 | 0.1510 | -0.1018 |
| -0.1398 | 1.0000 | 0.1058 | -0.0056 | 0.0142 | 0.0138 | 0.2141 | 0.1112 | -0.0026 | 0.2608 | 0.2995 | 0.0510 | 0.0048 | 0.2631 | 0.1197 | -0.0178 | 0.1900 | 0.2714 | 0.1549 | 0.1804 | 0.1717 | 0.0848 | -0.0183 | 0.0204 | 0.0432 | 0.0777 | 0.0381 | 0.0012 | -0.0143 | 0.2638 | 0.2048 | 0.0498 |
| 0.0326 | 0.1058 | 1.0000 | -0.0919 | 0.5723 | 0.5507 | 0.2397 | -0.0591 | 0.3082 | 0.5378 | 0.4762 | 0.2955 | -0.0304 | 0.5930 | 0.1017 | -0.1839 | 0.4275 | 0.3968 | 0.6007 | 0.5620 | 0.2389 | 0.3088 | -0.1139 | 0.0304 | 0.0649 | 0.0652 | -0.0314 | 0.0708 | -0.0273 | 0.7910 | 0.5411 | 0.2720 |
| -0.0593 | -0.0056 | -0.0919 | 1.0000 | -0.3760 | 0.0737 | -0.0462 | 0.0402 | -0.1368 | -0.1711 | -0.1442 | 0.0289 | 0.0255 | -0.0797 | 0.0130 | -0.0870 | -0.0576 | -0.0238 | -0.1858 | -0.1515 | -0.0033 | -0.0326 | 0.0704 | 0.0255 | 0.0548 | -0.0020 | 0.0688 | -0.0035 | 0.0439 | -0.0779 | -0.1740 | 0.1190 |
| 0.0279 | 0.0142 | 0.5723 | -0.3760 | 1.0000 | 0.5929 | 0.2495 | -0.0491 | 0.1490 | 0.3915 | 0.2820 | 0.0103 | -0.1838 | 0.1990 | -0.0707 | -0.1748 | 0.0956 | 0.1477 | 0.5379 | 0.4790 | 0.2249 | 0.1887 | -0.3873 | 0.0314 | -0.0504 | 0.0049 | -0.0344 | 0.0124 | -0.0136 | 0.5229 | 0.5243 | 0.3818 |
| 0.0406 | 0.0138 | 0.5507 | 0.0737 | 0.5929 | 1.0000 | 0.1285 | -0.0678 | 0.1811 | 0.2911 | 0.2404 | 0.1400 | -0.0624 | 0.2874 | -0.0406 | -0.1496 | 0.1917 | 0.1126 | 0.4206 | 0.3716 | 0.2057 | 0.2263 | -0.1939 | 0.0453 | -0.0387 | 0.0058 | -0.0103 | 0.0215 | 0.0357 | 0.5071 | 0.4437 | 0.2989 |
| -0.0698 | 0.2141 | 0.2397 | -0.0462 | 0.2495 | 0.1285 | 1.0000 | -0.0501 | -0.4953 | 0.5224 | 0.4459 | -0.1371 | -0.0645 | 0.2082 | -0.1074 | -0.0810 | 0.0443 | 0.2600 | 0.2241 | 0.2970 | 0.2043 | 0.1118 | -0.1023 | 0.0265 | 0.0620 | 0.1405 | 0.0036 | -0.0157 | 0.0144 | 0.3864 | 0.4816 | 0.1665 |
| -0.0656 | 0.1112 | -0.0591 | 0.0402 | -0.0491 | -0.0678 | -0.0501 | 1.0000 | -0.2093 | 0.1048 | 0.0971 | -0.0993 | 0.0148 | -0.0096 | -0.0157 | -0.0408 | -0.0352 | 0.0469 | -0.0383 | -0.0182 | 0.0679 | 0.0031 | 0.0365 | -0.0300 | 0.0889 | 0.0417 | 0.0049 | -0.0152 | 0.0317 | -0.0114 | 0.0517 | 0.0399 |
| -0.1408 | -0.0026 | 0.3082 | -0.1368 | 0.1490 | 0.1811 | -0.4953 | -0.2093 | 1.0000 | 0.4154 | 0.3180 | 0.0045 | 0.0282 | 0.2403 | 0.1666 | 0.0301 | 0.2506 | 0.0516 | 0.2142 | 0.1833 | -0.0053 | 0.1290 | -0.0025 | 0.0208 | -0.0126 | -0.0351 | -0.0238 | 0.0349 | -0.0413 | 0.2145 | -0.1045 | 0.0201 |
| -0.2385 | 0.2608 | 0.5378 | -0.1711 | 0.3915 | 0.2911 | 0.5224 | 0.1048 | 0.4154 | 1.0000 | 0.8195 | -0.1745 | -0.0332 | 0.4549 | 0.0504 | -0.0689 | 0.2856 | 0.3395 | 0.4346 | 0.4867 | 0.2320 | 0.2473 | -0.0955 | 0.0374 | 0.0845 | 0.1261 | -0.0185 | 0.0132 | -0.0150 | 0.6136 | 0.4145 | 0.2080 |
| -0.2518 | 0.2995 | 0.4762 | -0.1442 | 0.2820 | 0.2404 | 0.4459 | 0.0971 | 0.3180 | 0.8195 | 1.0000 | -0.2026 | -0.0142 | 0.5660 | 0.1274 | 0.0681 | 0.4095 | 0.4105 | 0.4393 | 0.4898 | 0.2355 | 0.2117 | -0.0653 | 0.0561 | 0.0888 | 0.1315 | -0.0211 | 0.0314 | -0.0136 | 0.6059 | 0.3906 | 0.1470 |
| 0.3079 | 0.0510 | 0.2955 | 0.0289 | 0.0103 | 0.1400 | -0.1371 | -0.0993 | 0.0045 | -0.1745 | -0.2026 | 1.0000 | 0.0634 | 0.6875 | 0.5029 | 0.0593 | 0.6164 | 0.1946 | 0.1839 | 0.1383 | 0.0922 | 0.2080 | 0.0620 | -0.0244 | 0.0406 | 0.0815 | 0.0162 | 0.0352 | -0.0287 | 0.3193 | 0.3752 | -0.0118 |
| 0.0465 | 0.0048 | -0.0304 | 0.0255 | -0.1838 | -0.0624 | -0.0645 | 0.0148 | 0.0282 | -0.0332 | -0.0142 | 0.0634 | 1.0000 | 0.1347 | 0.1056 | 0.0075 | 0.1312 | -0.0213 | -0.0945 | -0.0676 | -0.0254 | 0.0183 | 0.0611 | -0.0043 | 0.0268 | 0.0622 | -0.0038 | -0.0222 | -0.0289 | -0.0256 | -0.0412 | -0.0501 |
| 0.0749 | 0.2631 | 0.5930 | -0.0797 | 0.1990 | 0.2874 | 0.2082 | -0.0096 | 0.2403 | 0.4549 | 0.5660 | 0.6875 | 0.1347 | 1.0000 | 0.5213 | 0.1001 | 0.8255 | 0.4617 | 0.4672 | 0.4690 | 0.2474 | 0.3302 | 0.0091 | 0.0206 | 0.1015 | 0.1702 | -0.0024 | 0.0502 | -0.0365 | 0.7086 | 0.5952 | 0.0937 |
| -0.0234 | 0.1197 | 0.1017 | 0.0130 | -0.0707 | -0.0406 | -0.1074 | -0.0157 | 0.1666 | 0.0504 | 0.1274 | 0.5029 | 0.1056 | 0.5213 | 1.0000 | 0.1986 | 0.6766 | 0.1076 | 0.0861 | 0.0653 | 0.0469 | 0.0938 | 0.0416 | -0.0245 | 0.0443 | 0.0707 | 0.0078 | 0.0465 | -0.0360 | 0.1682 | 0.2349 | 0.0079 |
| 0.2817 | -0.0178 | -0.1839 | -0.0870 | -0.1748 | -0.1496 | -0.0810 | -0.0408 | 0.0301 | -0.0689 | 0.0681 | 0.0593 | 0.0075 | 0.1001 | 0.1986 | 1.0000 | 0.2560 | -0.1239 | -0.0506 | -0.0644 | -0.0901 | -0.0701 | 0.0373 | -0.0246 | -0.0516 | -0.0145 | 0.0623 | 0.0266 | 0.0317 | -0.1359 | 0.0383 | -0.2468 |
| 0.0404 | 0.1900 | 0.4275 | -0.0576 | 0.0956 | 0.1917 | 0.0443 | -0.0352 | 0.2506 | 0.2856 | 0.4095 | 0.6164 | 0.1312 | 0.8255 | 0.6766 | 0.2560 | 1.0000 | 0.3261 | 0.3623 | 0.3378 | 0.1660 | 0.2342 | 0.0042 | -0.0067 | 0.0594 | 0.0838 | 0.0248 | 0.0369 | -0.0345 | 0.5337 | 0.4603 | 0.0345 |
| -0.0456 | 0.2714 | 0.3968 | -0.0238 | 0.1477 | 0.1126 | 0.2600 | 0.0469 | 0.0516 | 0.3395 | 0.4105 | 0.1946 | -0.0213 | 0.4617 | 0.1076 | -0.1239 | 0.3261 | 1.0000 | 0.3008 | 0.2691 | 0.2000 | 0.1694 | -0.0248 | 0.0113 | 0.1845 | 0.0951 | 0.0014 | 0.0464 | -0.0241 | 0.4669 | 0.3317 | 0.1863 |
| -0.0401 | 0.1549 | 0.6007 | -0.1858 | 0.5379 | 0.4206 | 0.2241 | -0.0383 | 0.2142 | 0.4346 | 0.4393 | 0.1839 | -0.0945 | 0.4672 | 0.0861 | -0.0506 | 0.3623 | 0.3008 | 1.0000 | 0.8825 | 0.2263 | 0.2136 | -0.1514 | 0.0358 | 0.0505 | 0.0209 | -0.0431 | 0.0405 | -0.0391 | 0.6404 | 0.4836 | 0.2337 |
| -0.0987 | 0.1804 | 0.5620 | -0.1515 | 0.4790 | 0.3716 | 0.2970 | -0.0182 | 0.1833 | 0.4867 | 0.4898 | 0.1383 | -0.0676 | 0.4690 | 0.0653 | -0.0644 | 0.3378 | 0.2691 | 0.8825 | 1.0000 | 0.2247 | 0.2414 | -0.1218 | 0.0351 | 0.0514 | 0.0610 | -0.0274 | 0.0280 | -0.0274 | 0.6234 | 0.4516 | 0.2307 |
| -0.0126 | 0.1717 | 0.2389 | -0.0033 | 0.2249 | 0.2057 | 0.2043 | 0.0679 | -0.0053 | 0.2320 | 0.2355 | 0.0922 | -0.0254 | 0.2474 | 0.0469 | -0.0901 | 0.1660 | 0.2000 | 0.2263 | 0.2247 | 1.0000 | 0.0587 | -0.1260 | -0.0328 | -0.0742 | 0.0734 | -0.0096 | 0.0210 | 0.0223 | 0.3244 | 0.2882 | 0.1460 |
| -0.0061 | 0.0848 | 0.3088 | -0.0326 | 0.1887 | 0.2263 | 0.1118 | 0.0031 | 0.1290 | 0.2473 | 0.2117 | 0.2080 | 0.0183 | 0.3302 | 0.0938 | -0.0701 | 0.2342 | 0.1694 | 0.2136 | 0.2414 | 0.0587 | 1.0000 | -0.0931 | -0.0058 | 0.0743 | 0.0608 | -0.0186 | 0.0713 | -0.0576 | 0.3159 | 0.2869 | 0.0259 |
| -0.0120 | -0.0183 | -0.1139 | 0.0704 | -0.3873 | -0.1939 | -0.1023 | 0.0365 | -0.0025 | -0.0955 | -0.0653 | 0.0620 | 0.0611 | 0.0091 | 0.0416 | 0.0373 | 0.0042 | -0.0248 | -0.1514 | -0.1218 | -0.1260 | -0.0931 | 1.0000 | -0.0373 | -0.0829 | 0.0542 | 0.0184 | -0.0289 | -0.0099 | -0.1286 | -0.1455 | -0.1569 |
| -0.0438 | 0.0204 | 0.0304 | 0.0255 | 0.0314 | 0.0453 | 0.0265 | -0.0300 | 0.0208 | 0.0374 | 0.0561 | -0.0244 | -0.0043 | 0.0206 | -0.0245 | -0.0246 | -0.0067 | 0.0113 | 0.0358 | 0.0351 | -0.0328 | -0.0058 | -0.0373 | 1.0000 | -0.0314 | -0.0080 | 0.0004 | 0.0295 | 0.0186 | 0.0446 | 0.0285 | 0.0307 |
| -0.0260 | 0.0432 | 0.0649 | 0.0548 | -0.0504 | -0.0387 | 0.0620 | 0.0889 | -0.0126 | 0.0845 | 0.0888 | 0.0406 | 0.0268 | 0.1015 | 0.0443 | -0.0516 | 0.0594 | 0.1845 | 0.0505 | 0.0514 | -0.0742 | 0.0743 | -0.0829 | -0.0314 | 1.0000 | 0.0513 | 0.0319 | 0.0232 | 0.0107 | 0.1114 | 0.0377 | 0.0512 |
| 0.0083 | 0.0777 | 0.0652 | -0.0020 | 0.0049 | 0.0058 | 0.1405 | 0.0417 | -0.0351 | 0.1261 | 0.1315 | 0.0815 | 0.0622 | 0.1702 | 0.0707 | -0.0145 | 0.0838 | 0.0951 | 0.0209 | 0.0610 | 0.0734 | 0.0608 | 0.0542 | -0.0080 | 0.0513 | 1.0000 | 0.0297 | -0.0337 | -0.0597 | 0.0924 | 0.0897 | 0.0181 |
| -0.0077 | 0.0381 | -0.0314 | 0.0688 | -0.0344 | -0.0103 | 0.0036 | 0.0049 | -0.0238 | -0.0185 | -0.0211 | 0.0162 | -0.0038 | -0.0024 | 0.0078 | 0.0623 | 0.0248 | 0.0014 | -0.0431 | -0.0274 | -0.0096 | -0.0186 | 0.0184 | 0.0004 | 0.0319 | 0.0297 | 1.0000 | -0.0065 | 0.0049 | -0.0212 | -0.0260 | -0.0025 |
| -0.0136 | 0.0012 | 0.0708 | -0.0035 | 0.0124 | 0.0215 | -0.0157 | -0.0152 | 0.0349 | 0.0132 | 0.0314 | 0.0352 | -0.0222 | 0.0502 | 0.0465 | 0.0266 | 0.0369 | 0.0464 | 0.0405 | 0.0280 | 0.0210 | 0.0713 | -0.0289 | 0.0295 | 0.0232 | -0.0337 | -0.0065 | 1.0000 | -0.1457 | 0.0464 | 0.0245 | 0.0098 |
| -0.0214 | -0.0143 | -0.0273 | 0.0439 | -0.0136 | 0.0357 | 0.0144 | 0.0317 | -0.0413 | -0.0150 | -0.0136 | -0.0287 | -0.0289 | -0.0365 | -0.0360 | 0.0317 | -0.0345 | -0.0241 | -0.0391 | -0.0274 | 0.0223 | -0.0576 | -0.0099 | 0.0186 | 0.0107 | -0.0597 | 0.0049 | -0.1457 | 1.0000 | -0.0289 | 0.0201 | -0.0094 |
| -0.0843 | 0.2638 | 0.7910 | -0.0779 | 0.5229 | 0.5071 | 0.3864 | -0.0114 | 0.2145 | 0.6136 | 0.6059 | 0.3193 | -0.0256 | 0.7086 | 0.1682 | -0.1359 | 0.5337 | 0.4669 | 0.6404 | 0.6234 | 0.3244 | 0.3159 | -0.1286 | 0.0446 | 0.1114 | 0.0924 | -0.0212 | 0.0464 | -0.0289 | 1.0000 | 0.6317 | 0.2513 |
| 0.1510 | 0.2048 | 0.5411 | -0.1740 | 0.5243 | 0.4437 | 0.4816 | 0.0517 | -0.1045 | 0.4145 | 0.3906 | 0.3752 | -0.0412 | 0.5952 | 0.2349 | 0.0383 | 0.4603 | 0.3317 | 0.4836 | 0.4516 | 0.2882 | 0.2869 | -0.1455 | 0.0285 | 0.0377 | 0.0897 | -0.0260 | 0.0245 | 0.0201 | 0.6317 | 1.0000 | 0.2016 |
| -0.1018 | 0.0498 | 0.2720 | 0.1190 | 0.3818 | 0.2989 | 0.1665 | 0.0399 | 0.0201 | 0.2080 | 0.1470 | -0.0118 | -0.0501 | 0.0937 | 0.0079 | -0.2468 | 0.0345 | 0.1863 | 0.2337 | 0.2307 | 0.1460 | 0.0259 | -0.1569 | 0.0307 | 0.0512 | 0.0181 | -0.0025 | 0.0098 | -0.0094 | 0.2513 | 0.2016 | 1.0000 |
print("L")## [1] "L"
L %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| 1.0000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.1398 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0326 | 0.1125573 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0593 | -0.0141670 | -0.0896117 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0279 | 0.0184612 | 0.5771354 | -0.3268716 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0406 | 0.0198641 | 0.5546635 | 0.1268941 | 0.5606666 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0698 | 0.2084152 | 0.2219684 | -0.0281490 | 0.1986970 | -0.1068994 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0656 | 0.1040629 | -0.0693811 | 0.0319941 | 0.0012136 | -0.0670527 | -0.0726611 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.1408 | -0.0227280 | 0.3196080 | -0.1185905 | -0.1185478 | 0.1292930 | -0.6325254 | -0.2328028 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.2385 | 0.2319918 | 0.5270804 | -0.1370192 | 0.0878241 | -0.0055207 | 0.3759066 | 0.1332220 | 1.0075507 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.2518 | 0.2695668 | 0.4608745 | -0.1159942 | -0.0278532 | 0.0330431 | 0.3130825 | 0.1124265 | 0.7275876 | 0.8686173 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.3079 | 0.0959191 | 0.2786343 | 0.0739838 | -0.2386542 | 0.0787302 | -0.1864521 | -0.0835051 | -0.3866344 | -0.8290493 | -0.2866741 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0465 | 0.0115260 | -0.0336415 | 0.0257431 | -0.2795070 | 0.0781579 | -0.0228298 | 0.0153463 | 0.0351940 | -0.2159394 | 0.0004768 | 0.0281176 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0749 | 0.2790243 | 0.5674171 | -0.0214710 | -0.2446245 | 0.0969687 | 0.0733663 | 0.0148611 | 0.2174705 | 0.0226581 | 0.4972974 | 0.8332271 | 0.0924648 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0234 | 0.1187495 | 0.0905793 | 0.0215197 | -0.2068666 | -0.0573420 | -0.1512860 | -0.0362348 | 0.0848586 | -0.3835762 | 0.2176117 | 0.6971707 | 0.0642321 | 0.9695948 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.2817 | 0.0220119 | -0.1981850 | -0.0885398 | -0.1750071 | 0.0269248 | -0.0043681 | -0.0355647 | 0.2207784 | 0.2316000 | 0.4664881 | 0.1267147 | -0.0467390 | 0.6602299 | 0.1797899 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0404 | 0.1995479 | 0.4096857 | -0.0164058 | -0.2615499 | 0.0935361 | -0.0565254 | -0.0253199 | 0.1548705 | -0.7648323 | 0.4585178 | 0.7551912 | 0.0835421 | 1.1195440 | 0.3341932 | 0.1573400 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0456 | 0.2703080 | 0.3734923 | 0.0103894 | -0.1154842 | -0.1195969 | 0.1447066 | 0.0481544 | 0.0575950 | -0.1331134 | 0.3105166 | 0.2058735 | -0.0276459 | 0.4756979 | -0.1168356 | -0.1450543 | 0.0685294 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0401 | 0.1522700 | 0.5932020 | -0.1351948 | 0.2742098 | 0.0495204 | 0.0324674 | -0.0082771 | 0.0904155 | 0.2482207 | 0.2274785 | 0.1600057 | -0.0353759 | 0.2440601 | -0.0578563 | 0.0513344 | 0.1103073 | 0.0179862 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0987 | 0.1699227 | 0.5539348 | -0.1072711 | 0.2278016 | 0.0210049 | 0.1218915 | 0.0078103 | 0.1549637 | 0.0608125 | 0.2425910 | 0.1642979 | -0.0125002 | 0.5837401 | -0.0949269 | 0.0375050 | 0.0553527 | -0.0537540 | 0.8231549 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0126 | 0.1733260 | 0.2231925 | 0.0183043 | 0.1787744 | 0.0435338 | 0.1164523 | 0.0748956 | 0.0428974 | 0.1855104 | 0.1146058 | 0.1262064 | 0.0051600 | -0.7748856 | -0.0345107 | -0.0708464 | 0.0393545 | 0.0415520 | 0.0339049 | -0.0014503 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0061 | 0.0856206 | 0.3036444 | -0.0049873 | 0.0227173 | 0.1041115 | 0.0345963 | 0.0211703 | 0.1176299 | -0.0222716 | -0.0078490 | 0.2225467 | 0.0230129 | -0.2079052 | -0.0650047 | -0.0414202 | -0.0227497 | -0.0045837 | -0.0217443 | 0.1431861 | -0.0642375 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0120 | -0.0203758 | -0.1127809 | 0.0601348 | -0.5364990 | 0.0618948 | -0.0103904 | 0.0308060 | -0.0016539 | -0.0439411 | -0.0462333 | 0.0244997 | -0.0333338 | -0.3090294 | -0.0246065 | -0.0307091 | -0.0997648 | -0.0203619 | 0.0187681 | 0.0512230 | -0.0562766 | -0.0754322 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0438 | 0.0145613 | 0.0306340 | 0.0261169 | 0.0413579 | 0.0272687 | 0.0129190 | -0.0322679 | 0.0206528 | 0.4182648 | 0.0775129 | -0.0127625 | 0.0042299 | 0.1229094 | -0.0418854 | -0.0123838 | -0.0563519 | -0.0170961 | 0.0105355 | -0.0237351 | -0.0574974 | -0.0259124 | -0.0349034 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0260 | 0.0403539 | 0.0621321 | 0.0600096 | -0.1175737 | -0.0852830 | 0.0555661 | 0.0886230 | 0.0461082 | -0.3525445 | 0.0320485 | 0.0583953 | 0.0114847 | -0.4380803 | -0.0076289 | -0.0647420 | -0.0390480 | 0.1591972 | 0.0496885 | -0.0077106 | -0.1274346 | 0.0421792 | -0.1472531 | -0.0411226 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| 0.0083 | 0.0804323 | 0.0568193 | 0.0046870 | -0.0489178 | -0.0245378 | 0.1331303 | 0.0467415 | 0.0742067 | -0.2685199 | 0.0681918 | 0.1448783 | 0.0570868 | 0.0147803 | -0.0122645 | -0.0471540 | -0.1711322 | -0.0003597 | -0.0655983 | 0.0794956 | 0.0227781 | 0.0043248 | 0.0554834 | -0.0099384 | 0.0309801 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0077 | 0.0377616 | -0.0357990 | 0.0664766 | 0.0123786 | -0.0067672 | 0.0037520 | -0.0041211 | -0.0057252 | 0.3977306 | -0.0243030 | 0.0292725 | -0.0051208 | 0.2309681 | -0.0076768 | 0.0897162 | 0.0782207 | 0.0148883 | -0.0536951 | 0.0461768 | -0.0087893 | -0.0166098 | 0.0206487 | 0.0014772 | 0.0388799 | 0.0301908 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0136 | -0.0007153 | 0.0722972 | 0.0020993 | -0.0490392 | -0.0044529 | -0.0308664 | -0.0135904 | -0.0285675 | 0.1240597 | 0.0457341 | 0.0091475 | -0.0284298 | -0.7542500 | 0.0422253 | 0.0397457 | -0.0956270 | 0.0348932 | 0.0082849 | -0.0273712 | 0.0174307 | 0.0674288 | -0.0383953 | 0.0293894 | 0.0121978 | -0.0364601 | -0.0023032 | 1.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0214 | -0.0176364 | -0.0249931 | 0.0406495 | 0.0259942 | 0.0743659 | 0.0276306 | 0.0342817 | -0.0271009 | 0.1812353 | -0.0052850 | -0.0213214 | -0.0290697 | 0.1616161 | -0.0173219 | 0.0617800 | -0.0249049 | -0.0023038 | -0.0445760 | 0.0250868 | 0.0310336 | -0.0563914 | -0.0160351 | 0.0173757 | 0.0226901 | -0.0603520 | -0.0025398 | -0.1484964 | 1.0000000 | 0.0000000 | 0.0000000 | 0 |
| -0.0843 | 0.2570384 | 0.7758438 | -0.0108679 | 0.1334521 | 0.0800311 | 0.1681028 | 0.0242459 | 0.1452334 | -0.3397512 | 0.2199497 | 0.3036154 | 0.0153324 | -0.0146475 | -0.0852354 | -0.0197259 | 0.1231578 | 0.0381507 | 0.1114221 | 0.0008355 | 0.0377498 | -0.0015405 | 0.0027067 | 0.0055633 | 0.0383071 | -0.0218023 | -0.0071260 | -0.0017551 | -0.0103495 | 1.0000000 | 0.0000000 | 0 |
| 0.1510 | 0.2304130 | 0.5177308 | -0.1174425 | 0.3244299 | 0.1233467 | 0.3412330 | 0.1057817 | -0.0640287 | -0.2810171 | 0.1222469 | 0.4250203 | 0.0149850 | -0.1553362 | 0.0995736 | 0.0829466 | 0.0368740 | 0.0254777 | 0.0457997 | -0.0675199 | 0.0320133 | 0.0501948 | 0.0307323 | 0.0177304 | -0.0006020 | -0.0299292 | -0.0203018 | -0.0041501 | 0.0288096 | 0.0982348 | 1.0000000 | 0 |
| -0.1018 | 0.0362774 | 0.2750237 | 0.1394022 | 0.4824480 | -0.0367047 | 0.0451801 | 0.0465278 | 0.0143917 | 0.2320922 | -0.0363669 | 0.0110753 | 0.0392450 | -0.0207290 | 0.0525871 | -0.1415324 | 0.0023231 | 0.1222306 | 0.0286219 | 0.0620933 | 0.0107716 | -0.0854061 | 0.0065374 | 0.0051862 | 0.0335793 | -0.0030489 | -0.0015874 | 0.0100509 | -0.0136042 | -0.1317968 | -0.0383005 | 1 |
print("U")## [1] "U"
U %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")| MSSubClass | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BedroomAbvGr | KitchenAbvGr | TotRmsAbvGrd | Fireplaces | GarageCars | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | SalePrice | Baths | CentralAirScore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MSSubClass | 1 | -0.139800 | 0.0326000 | -0.0593000 | 0.0279000 | 0.0406000 | -0.0698000 | -0.0656000 | -0.1408000 | -0.2385000 | -0.2518000 | 0.3079000 | 0.0465000 | 0.0749000 | -0.0234000 | 0.2817000 | 0.0404000 | -0.0456000 | -0.0401000 | -0.0987000 | -0.0126000 | -0.0061000 | -0.0120000 | -0.0438000 | -0.0260000 | 0.0083000 | -0.0077000 | -0.0136000 | -0.0214000 | -0.0843000 | 0.1510000 | -0.1018000 |
| LotArea | 0 | 0.980456 | 0.1103575 | -0.0138901 | 0.0181004 | 0.0194759 | 0.2043420 | 0.1020291 | -0.0222838 | 0.2274577 | 0.2642984 | 0.0940444 | 0.0113007 | 0.2735710 | 0.1164287 | 0.0215817 | 0.1956479 | 0.2650251 | 0.1492940 | 0.1666017 | 0.1699385 | 0.0839472 | -0.0199776 | 0.0142768 | 0.0395652 | 0.0788603 | 0.0370235 | -0.0007013 | -0.0172917 | 0.2520149 | 0.2259098 | 0.0355684 |
| OverallQual | 0 | 0.000000 | 0.9865157 | -0.0884034 | 0.5693531 | 0.5471843 | 0.2189753 | -0.0684456 | 0.3152983 | 0.5199731 | 0.4546600 | 0.2748771 | -0.0331879 | 0.5597658 | 0.0893579 | -0.1955126 | 0.4041614 | 0.3684560 | 0.5852031 | 0.5464654 | 0.2201829 | 0.2995500 | -0.1112602 | 0.0302209 | 0.0612942 | 0.0560531 | -0.0353162 | 0.0713223 | -0.0246561 | 0.7653821 | 0.5107496 | 0.2713152 |
| OverallCond | 0 | 0.000000 | 0.0000000 | 0.9883647 | -0.3230684 | 0.1254176 | -0.0278215 | 0.0316218 | -0.1172107 | -0.1354250 | -0.1146446 | 0.0731230 | 0.0254435 | -0.0212212 | 0.0212693 | -0.0875097 | -0.0162149 | 0.0102685 | -0.1336218 | -0.1060229 | 0.0180913 | -0.0049293 | 0.0594352 | 0.0258131 | 0.0593114 | 0.0046324 | 0.0657032 | 0.0020749 | 0.0401765 | -0.0107415 | -0.1160761 | 0.1377802 |
| YearBuilt | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.5646917 | 0.3166038 | 0.1122026 | 0.0006853 | -0.0669429 | 0.0495936 | -0.0157285 | -0.1347660 | -0.1578353 | -0.1381374 | -0.1168158 | -0.0988250 | -0.1476951 | -0.0652130 | 0.1548440 | 0.1286377 | 0.1009524 | 0.0128283 | -0.3029565 | 0.0233544 | -0.0663929 | -0.0276235 | 0.0069901 | -0.0276920 | 0.0146787 | 0.0753593 | 0.1832029 | 0.2724344 |
| YearRemodAdd | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.5010377 | -0.0535607 | -0.0335959 | 0.0647807 | -0.0027661 | 0.0165559 | 0.0394468 | 0.0391601 | 0.0485850 | -0.0287305 | 0.0134903 | 0.0468651 | -0.0599225 | 0.0248116 | 0.0105243 | 0.0218121 | 0.0521638 | 0.0310116 | 0.0136627 | -0.0427300 | -0.0122944 | -0.0033906 | -0.0022311 | 0.0372601 | 0.0400986 | 0.0618014 | -0.0183905 |
| BsmtFinSF1 | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.8751313 | -0.0635880 | -0.5535428 | 0.3289676 | 0.2739883 | -0.1631701 | -0.0199791 | 0.0642052 | -0.1323951 | -0.0038226 | -0.0494671 | 0.1266372 | 0.0284133 | 0.1066710 | 0.1019111 | 0.0302763 | -0.0090930 | 0.0113059 | 0.0486276 | 0.1165065 | 0.0032835 | -0.0270122 | 0.0241804 | 0.1471120 | 0.2986237 | 0.0395385 |
| BsmtFinSF2 | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9724447 | -0.2263878 | 0.1295511 | 0.1093285 | -0.0812041 | 0.0149234 | 0.0144516 | -0.0352364 | -0.0345847 | -0.0246222 | 0.0468275 | -0.0080491 | 0.0075951 | 0.0728319 | 0.0205869 | 0.0299572 | -0.0313788 | 0.0861809 | 0.0454535 | -0.0040075 | -0.0132159 | 0.0333371 | 0.0235778 | 0.1028668 | 0.0452457 |
| BsmtUnfSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.4458518 | 0.4492183 | 0.3243962 | -0.1723816 | 0.0156913 | 0.0969596 | 0.0378343 | 0.0984344 | 0.0690493 | 0.0256788 | 0.0403119 | 0.0690909 | 0.0191259 | 0.0524455 | -0.0007374 | 0.0092081 | 0.0205574 | 0.0330852 | -0.0025526 | -0.0127369 | -0.0120830 | 0.0647526 | -0.0285473 | 0.0064166 |
| TotalBsmtSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | -0.0001751 | -0.0001521 | 0.0001451 | 0.0000378 | -0.0000040 | 0.0000672 | -0.0000405 | 0.0001339 | 0.0000233 | -0.0000435 | -0.0000106 | -0.0000325 | 0.0000039 | 0.0000077 | -0.0000732 | 0.0000617 | 0.0000470 | -0.0000696 | -0.0000217 | -0.0000317 | 0.0000595 | 0.0000492 | -0.0000406 |
| X1stFlrSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.3075593 | -0.0881693 | 0.0001466 | 0.1529484 | 0.0669285 | 0.1434728 | 0.1410214 | 0.0955023 | 0.0699631 | 0.0746111 | 0.0352481 | -0.0024140 | -0.0142195 | 0.0238398 | 0.0098568 | 0.0209730 | -0.0074746 | 0.0140659 | -0.0016254 | 0.0676476 | 0.0375982 | -0.0111850 |
| X2ndFlrSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.6499002 | 0.0182736 | 0.5415145 | 0.4530914 | 0.0823519 | 0.4907989 | 0.1337972 | 0.1039877 | 0.1067772 | 0.0820215 | 0.1446331 | 0.0159224 | -0.0082943 | 0.0379511 | 0.0941564 | 0.0190242 | 0.0059449 | -0.0138568 | 0.1973197 | 0.2762207 | 0.0071978 |
| LowQualFinSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9470162 | 0.0875657 | 0.0608288 | -0.0442626 | 0.0791157 | -0.0261811 | -0.0335016 | -0.0118379 | 0.0048866 | 0.0217936 | -0.0315677 | 0.0040058 | 0.0108762 | 0.0540621 | -0.0048495 | -0.0269234 | -0.0275295 | 0.0145200 | 0.0141911 | 0.0371657 |
| GrLivArea | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0001045 | 0.0001013 | 0.0000690 | 0.0001170 | 0.0000497 | 0.0000255 | 0.0000610 | -0.0000810 | -0.0000217 | -0.0000323 | 0.0000128 | -0.0000458 | 0.0000015 | 0.0000241 | -0.0000788 | 0.0000169 | -0.0000015 | -0.0000162 | -0.0000022 |
| BedroomAbvGr | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.5923192 | 0.1064930 | 0.1979490 | -0.0692040 | -0.0342694 | -0.0562270 | -0.0204413 | -0.0385035 | -0.0145749 | -0.0248095 | -0.0045188 | -0.0072645 | -0.0045471 | 0.0250109 | -0.0102601 | -0.0504865 | 0.0589793 | 0.0311484 |
| KitchenAbvGr | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.7344223 | 0.1155540 | -0.1065311 | 0.0377011 | 0.0275445 | -0.0520312 | -0.0304199 | -0.0225534 | -0.0090950 | -0.0475480 | -0.0346309 | 0.0658895 | 0.0291902 | 0.0453726 | -0.0144871 | 0.0609178 | -0.1039446 |
| TotRmsAbvGrd | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.2100747 | 0.0143963 | 0.0231728 | 0.0116282 | 0.0082674 | -0.0047791 | -0.0209581 | -0.0118381 | -0.0082030 | -0.0359505 | 0.0164322 | -0.0200888 | -0.0052319 | 0.0258723 | 0.0077463 | 0.0004880 |
| Fireplaces | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.6693337 | 0.0120388 | -0.0359794 | 0.0278122 | -0.0030680 | -0.0136289 | -0.0114430 | 0.1065560 | -0.0002408 | 0.0099652 | 0.0233552 | -0.0015420 | 0.0255355 | 0.0170531 | 0.0818131 |
| GarageCars | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.5217029 | 0.4294423 | 0.0176883 | -0.0113440 | 0.0097914 | 0.0054964 | 0.0259226 | -0.0342228 | -0.0280129 | 0.0043223 | -0.0232554 | 0.0581292 | 0.0238938 | 0.0149321 |
| GarageArea | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.1963045 | -0.0002847 | 0.0281081 | 0.0100553 | -0.0046593 | -0.0015136 | 0.0156053 | 0.0090647 | -0.0053731 | 0.0049247 | 0.0001640 | -0.0132545 | 0.0121892 |
| WoodDeckSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.8628258 | -0.0554258 | -0.0485569 | -0.0496102 | -0.1099539 | 0.0196535 | -0.0075837 | 0.0150397 | 0.0267766 | 0.0325715 | 0.0276219 | 0.0092940 |
| OpenPorchSF | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.8439892 | -0.0636640 | -0.0218698 | 0.0355988 | 0.0036501 | -0.0140185 | 0.0569092 | -0.0475937 | -0.0013002 | 0.0423639 | -0.0720818 |
| EnclosedPorch | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.8040901 | -0.0280655 | -0.1184048 | 0.0446137 | 0.0166034 | -0.0308733 | -0.0128936 | 0.0021764 | 0.0247116 | 0.0052566 |
| X3SsnPorch | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9850631 | -0.0405084 | -0.0097899 | 0.0014551 | 0.0289504 | 0.0171162 | 0.0054802 | 0.0174656 | 0.0051088 |
| ScreenPorch | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9086558 | 0.0281502 | 0.0353284 | 0.0110836 | 0.0206175 | 0.0348080 | -0.0005470 | 0.0305121 |
| PoolArea | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9352252 | 0.0282352 | -0.0340984 | -0.0564427 | -0.0203900 | -0.0279906 | -0.0028514 |
| MiscVal | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9798433 | -0.0022567 | -0.0024886 | -0.0069823 | -0.0198926 | -0.0015554 |
| MoSold | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9777343 | -0.1451900 | -0.0017160 | -0.0040577 | 0.0098271 |
| YrSold | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.9568609 | -0.0099031 | 0.0275667 | -0.0130173 |
| SalePrice | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.1927920 | 0.0189389 | -0.0254094 |
| Baths | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.3215890 | -0.0123170 |
| CentralAirScore | 0 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.7175071 |
We can confirm the decomposition by comparing to our original Correlation Matrix -
round(L %*% U ,4)== round(corrMatrix,4)## MSSubClass LotArea OverallQual OverallCond YearBuilt YearRemodAdd
## [1,] TRUE TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE TRUE TRUE TRUE
## BsmtFinSF1 BsmtFinSF2 BsmtUnfSF TotalBsmtSF X1stFlrSF X2ndFlrSF
## [1,] TRUE TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE TRUE TRUE TRUE
## LowQualFinSF GrLivArea BedroomAbvGr KitchenAbvGr TotRmsAbvGrd
## [1,] TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE TRUE TRUE
## Fireplaces GarageCars GarageArea WoodDeckSF OpenPorchSF
## [1,] TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE TRUE TRUE
## EnclosedPorch X3SsnPorch ScreenPorch PoolArea MiscVal MoSold YrSold
## [1,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## SalePrice Baths CentralAirScore
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE
## [6,] TRUE TRUE TRUE
## [7,] TRUE TRUE TRUE
## [8,] TRUE TRUE TRUE
## [9,] TRUE TRUE TRUE
## [10,] TRUE TRUE TRUE
## [11,] TRUE TRUE TRUE
## [12,] TRUE TRUE TRUE
## [13,] TRUE TRUE TRUE
## [14,] TRUE TRUE TRUE
## [15,] TRUE TRUE TRUE
## [16,] TRUE TRUE TRUE
## [17,] TRUE TRUE TRUE
## [18,] TRUE TRUE TRUE
## [19,] TRUE TRUE TRUE
## [20,] TRUE TRUE TRUE
## [21,] TRUE TRUE TRUE
## [22,] TRUE TRUE TRUE
## [23,] TRUE TRUE TRUE
## [24,] TRUE TRUE TRUE
## [25,] TRUE TRUE TRUE
## [26,] TRUE TRUE TRUE
## [27,] TRUE TRUE TRUE
## [28,] TRUE TRUE TRUE
## [29,] TRUE TRUE TRUE
## [30,] TRUE TRUE TRUE
## [31,] TRUE TRUE TRUE
## [32,] TRUE TRUE TRUE
Many times, it makes sense to fit a closed form distribution to data. Select a variable in the Kaggle.com training dataset that is skewed to the right, shift it so that the minimum value is absolutely above zero if necessary. Then load the MASS package and run fitdistr to fit an exponential probability density function. (See https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/fitdistr.html ). Find the optimal value of \(\lambda\) for this distribution, and then take 1000 samples from this exponential distribution using this value (e.g., rexp(1000, \(\lambda\))). Plot a histogram and compare it with a histogram of your original variable. Using the exponential pdf, find the 5th and 95th percentiles using the cumulative distribution function (CDF). Also generate a 95% confidence interval from the empirical data, assuming normality. Finally, provide the empirical 5th percentile and 95th percentile of the data. Discuss.
Ans: For this analysis, I have chosen the GarageArea variable in the Kaggle data set.
Dist <- housing_pr_train$GarageArea
min(Dist)## [1] 0
Then run fitdistr to fit an exponential probability density function.
fitDist <- fitdistr(Dist, "exponential")
fitDist## rate
## 2.114254e-03
## (5.533255e-05)
Find the optimal value of \(\lambda\) for this distribution, and then take 1000 samples from this exponential distribution using this value.
lambda <- fitDist$estimate
sim <- rexp(1000,lambda)
hist(sim,breaks = 100, col="blue", main="Histogram of 1000 samples with Simulation", xlab="Exponential of Lot Area (Square Feet)")hist(Dist,breaks=100, col="grey", main="Histogram of Original Data", xlab="Garage Area (Square Feet)")sim.df <- data.frame(length = sim)
Dist.df <- data.frame(length = Dist)
sim.df$from <- 'sim'
Dist.df$from <- 'orig'
both.df <- rbind(sim.df,Dist.df)
ggplotly(ggplot(both.df, aes(length, fill = from)) + geom_density(alpha = 0.2) + scale_fill_brewer(palette="Set1") +
ggtitle("Density plot for Original Vs. Simulated Distributions"))Using the exponential pdf, find the 5th and 95th percentiles using the cumulative distribution function (CDF).
quantile(sim, probs=c(0.05, 0.95))## 5% 95%
## 24.30699 1437.18642
Also generate a 95% confidence interval from the empirical data, assuming normality.
mean(Dist)## [1] 472.9801
normal<-rnorm(length(Dist),mean(Dist),sd(Dist))
hist(normal,breaks = 100, col="orange", main="Histogram of Normalized Distribution", xlab="Garage Area (Square Feet)")quantile(normal, probs=c(0.05, 0.95))## 5% 95%
## 120.6115 811.4731
normal.df <- data.frame(length = normal)
normal.df$from <- 'normal'
all.df <- rbind(both.df,normal.df)
ggplotly(ggplot(all.df, aes(length, fill = from)) + geom_density(alpha = 0.2)+ scale_fill_brewer(palette="Set1") +
ggtitle("Density plot for Original Vs. Simulated Vs. Normal Distributions"))Finally, provide the empirical 5th percentile and 95th percentile of the data. Discuss.
quantile(Dist, probs=c(0.05, 0.95))## 5% 95%
## 0.0 850.1
From this analysis it appears the data select was not very right skew. The exponential simulation does not match our data very well, rather, our selected empirical data matches the normal distribution a lot better. This can be seen in the final density plot, but also on the confidence interval where the limits are much closer than for the exponential approximation.
Build some type of multiple regression model and submit your model to the competition board. Provide your complete model summary and results with analysis. Report your Kaggle.com user name and score.
Ans: Based on the Correlation Scores from the previous section, I have implemented a Linear Regresion model with following predictor variables -
I have used log transformtaion for the Lot Area and SalePrice variables.
housing_pr_train$LogLotArea <- log(housing_pr_train$LotArea)
housing_pr_train$LogSalePrice <- log(housing_pr_train$SalePrice)
model_train_df <- subset(housing_pr_train, select = c(YearBuilt,YearRemodAdd,TotalBsmtSF,OverallQual,OverallCond,GrLivArea,Baths,
GarageCars,GarageArea,BedroomAbvGr,KitchenAbvGr,TotRmsAbvGrd,CentralAirScore,LogLotArea, LogSalePrice))Next, I created a linear model with all 14 variables and then found the optimized model with the final list of predictors using Stepwise regreesion technique.
## Initial Model
lm_full_model <- lm(LogSalePrice ~ YearBuilt + YearRemodAdd + TotalBsmtSF + OverallQual + OverallCond + GrLivArea + Baths + GarageCars +
GarageArea + BedroomAbvGr + KitchenAbvGr + TotRmsAbvGrd + CentralAirScore + LogLotArea, data = model_train_df)
## Model Summary
summary(lm_full_model)##
## Call:
## lm(formula = LogSalePrice ~ YearBuilt + YearRemodAdd + TotalBsmtSF +
## OverallQual + OverallCond + GrLivArea + Baths + GarageCars +
## GarageArea + BedroomAbvGr + KitchenAbvGr + TotRmsAbvGrd +
## CentralAirScore + LogLotArea, data = model_train_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.05965 -0.06474 0.00281 0.07658 0.48775
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.460e+00 5.401e-01 6.407 2.00e-10 ***
## YearBuilt 2.341e-03 2.375e-04 9.859 < 2e-16 ***
## YearRemodAdd 7.635e-04 2.689e-04 2.839 0.00459 **
## TotalBsmtSF 9.510e-05 1.165e-05 8.162 7.11e-16 ***
## OverallQual 8.804e-02 4.826e-03 18.245 < 2e-16 ***
## OverallCond 4.669e-02 4.354e-03 10.724 < 2e-16 ***
## GrLivArea 1.647e-04 1.657e-05 9.941 < 2e-16 ***
## Baths 6.306e-02 7.210e-03 8.747 < 2e-16 ***
## GarageCars 7.733e-02 1.181e-02 6.550 7.98e-11 ***
## GarageArea -2.941e-05 4.020e-05 -0.731 0.46460
## BedroomAbvGr -1.937e-02 6.895e-03 -2.810 0.00503 **
## KitchenAbvGr -9.241e-02 1.989e-02 -4.647 3.67e-06 ***
## TotRmsAbvGrd 1.505e-02 5.149e-03 2.922 0.00353 **
## CentralAirScore 8.754e-02 1.811e-02 4.833 1.49e-06 ***
## LogLotArea 1.093e-01 8.752e-03 12.487 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1472 on 1445 degrees of freedom
## Multiple R-squared: 0.8655, Adjusted R-squared: 0.8642
## F-statistic: 664.4 on 14 and 1445 DF, p-value: < 2.2e-16
I have used the stepAIC() function from MASS package, which choose the best model by AIC. I have used a combined forward and backward elimination process using direcition parameter as ‘both’.
train_model <- stepAIC(lm_full_model, direction = "both",
trace = FALSE)
summary(train_model)##
## Call:
## lm(formula = LogSalePrice ~ YearBuilt + YearRemodAdd + TotalBsmtSF +
## OverallQual + OverallCond + GrLivArea + Baths + GarageCars +
## BedroomAbvGr + KitchenAbvGr + TotRmsAbvGrd + CentralAirScore +
## LogLotArea, data = model_train_df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.07392 -0.06451 0.00265 0.07630 0.48977
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.460e+00 5.400e-01 6.407 2.00e-10 ***
## YearBuilt 2.337e-03 2.374e-04 9.845 < 2e-16 ***
## YearRemodAdd 7.713e-04 2.687e-04 2.871 0.00415 **
## TotalBsmtSF 9.372e-05 1.150e-05 8.152 7.66e-16 ***
## OverallQual 8.815e-02 4.823e-03 18.277 < 2e-16 ***
## OverallCond 4.654e-02 4.348e-03 10.703 < 2e-16 ***
## GrLivArea 1.635e-04 1.648e-05 9.920 < 2e-16 ***
## Baths 6.318e-02 7.207e-03 8.767 < 2e-16 ***
## GarageCars 7.046e-02 7.161e-03 9.839 < 2e-16 ***
## BedroomAbvGr -1.900e-02 6.875e-03 -2.764 0.00579 **
## KitchenAbvGr -9.224e-02 1.988e-02 -4.639 3.81e-06 ***
## TotRmsAbvGrd 1.519e-02 5.145e-03 2.953 0.00320 **
## CentralAirScore 8.721e-02 1.810e-02 4.817 1.61e-06 ***
## LogLotArea 1.086e-01 8.695e-03 12.486 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1472 on 1446 degrees of freedom
## Multiple R-squared: 0.8655, Adjusted R-squared: 0.8643
## F-statistic: 715.7 on 13 and 1446 DF, p-value: < 2.2e-16
Now all predictors have p vlaues less than 0.05.
train_model$coefficients## (Intercept) YearBuilt YearRemodAdd TotalBsmtSF
## 3.459613e+00 2.336921e-03 7.713103e-04 9.372069e-05
## OverallQual OverallCond GrLivArea Baths
## 8.814626e-02 4.654093e-02 1.634841e-04 6.318413e-02
## GarageCars BedroomAbvGr KitchenAbvGr TotRmsAbvGrd
## 7.046074e-02 -1.900090e-02 -9.223818e-02 1.519203e-02
## CentralAirScore LogLotArea
## 8.720929e-02 1.085608e-01
## Build Function for Regression Model
train_model_equation <- function(YearBuilt,YearRemodAdd,TotalBsmtSF,OverallQual,OverallCond,GrLivArea,Baths,
GarageCars,BedroomAbvGr,KitchenAbvGr,TotRmsAbvGrd,CentralAirScore,LogLotArea) {
(3.459613 + (0.002336921 * YearBuilt) + (0.0007713103 * YearRemodAdd) + (0.00009372069 * TotalBsmtSF) + (0.08814626 * OverallQual) + (0.04654093 * OverallCond) + (0.0001634841 * GrLivArea) + (0.06318413 * Baths) + (0.07046074 * GarageCars) + (-0.01900090 * BedroomAbvGr) + (-0.09223818 * KitchenAbvGr) + (0.01519203 * TotRmsAbvGrd) + (0.08720929 * CentralAirScore) + (0.01085608 * LogLotArea))
}The linear regression equation is as follows:
logSalePrice = 3.459613 + (0.002336921 * YearBuilt) + (0.0007713103 * YearRemodAdd) + (0.00009372069 * TotalBsmtSF) + (0.08814626 * OverallQual) + (0.04654093 * OverallCond) + (0.0001634841 * GrLivArea) + (0.06318413 * Baths) + (0.07046074 * GarageCars) + (-0.01900090 * BedroomAbvGr) + (-0.09223818 * KitchenAbvGr) + (0.01519203 * TotRmsAbvGrd) + (0.08720929 * CentralAirScore) + (0.01085608 * LogLotArea)
Having constructed a model where all p-values are below 0.05, I looked the residual plot, Q-Q plot and other relevant plots using ggresidpanel package:
resid_panel(train_model, plots='all', smoother = TRUE)# Residuals plot
resid_interact(train_model, plots='resid', smoother = TRUE)# Q-Q plot
resid_interact(train_model, plots='qq', smoother = TRUE)The residual plot is acceptable with few outliers but he Q-Q plot is heavily tailed. This is not necessarily a surprise because during step wise regression model selection process, as the model was evaluated, the residuals, though fairly centered in terms of mean and quartiles, exhibited skew on the minimum end. We can see that in the residual plot in that there are two huge outliers and there appear to be sligtly more plots below zero than above zero.
Next, I read in the test data and used the linear regression model to predict logSalePrice, which was then tranformed back to SalePrice:
housing_pr_test <- read.csv('https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-605/House%20Price%20Analysis/Data%20Source/house-prices-advanced-regression-techniques/test.csv',sep = ',')# Consolidate no. of baths
housing_pr_test$Baths <- housing_pr_test$BsmtFullBath + 0.5*housing_pr_test$BsmtHalfBath + housing_pr_test$FullBath + 0.5*housing_pr_test$HalfBath
# Derive CentralAirScore as discrete variable
housing_pr_test$CentralAirScore <- ifelse(housing_pr_test$CentralAir == "N", 0, 1)
# Calculate log of LotArea
housing_pr_test$LogLotArea <- log(housing_pr_test$LotArea)# predict logSalePrice using the test data and linear regression model
lm_predicted <- train_model_equation(housing_pr_test$YearBuilt,housing_pr_test$YearRemodAdd,housing_pr_test$TotalBsmtSF,
housing_pr_test$OverallQual,housing_pr_test$OverallCond,housing_pr_test$GrLivArea,
housing_pr_test$Baths,housing_pr_test$GarageCars,housing_pr_test$BedroomAbvGr,
housing_pr_test$KitchenAbvGr,housing_pr_test$TotRmsAbvGrd,housing_pr_test$CentralAirScore,
housing_pr_test$LogLotArea)
# compute mean
lm_predicted_mean <- mean(lm_predicted, na.rm = TRUE)
# replace NA values with mean
lm_predicted <- ifelse(is.na(lm_predicted) == TRUE, lm_predicted_mean, lm_predicted)
# transform logSalePrice prediction to SalePrice
lm_predicted <- (exp(1))^lm_predicted
# put transformed SalePrice into data frame
lm_predicted_df <- data.frame(cbind(seq(from = 1461, to = 2919, by = 1), lm_predicted))
# change column names to Id and SalePrice
colnames(lm_predicted_df) <- c("Id","SalePrice")
# export to .csv for submission
write.csv(lm_predicted_df, file = "C:/CUNY/Semester3 (Fall)/DATA 605/Assignments/Final Project/Output/submission.csv",row.names = FALSE)My Kaggle user name is soumya2g. Below is a screenshot of the submission.
Kaggle Score: 0.90655