data<- read.csv("C:/Users/LENOVO/OneDrive/Documents/cobak/processed_automobile_data.csv", header = TRUE)
data <- data[, !(names(data) %in% c("symboling","make","fuel-type","aspiration","num-of-doors","body-style","drive-wheels","engine-location","engine-type","num-of-cylinders","fuel-system","stroke","price"))]
data_numeric <- data[sapply(data, is.numeric)]
cor(data_numeric)
## normalized.losses wheel.base length width
## normalized.losses 1.00000000 -0.06008568 0.03554071 0.1097262
## wheel.base -0.06008568 1.00000000 0.87153448 0.8149912
## length 0.03554071 0.87153448 1.00000000 0.8383385
## width 0.10972620 0.81499125 0.83833846 1.0000000
## height -0.41370154 0.55576713 0.49925137 0.2927058
## curb.weight 0.12585792 0.81018149 0.87129108 0.8705945
## engine.size 0.20781961 0.64920558 0.72595331 0.7792534
## bore -0.03155814 0.57815853 0.64631755 0.5725542
## compression.ratio -0.12725910 0.29143145 0.18481418 0.2587517
## horsepower 0.29051055 0.51694753 0.67206330 0.6818718
## peak.rpm 0.23769662 -0.28923445 -0.23407384 -0.2322160
## city.mpg -0.23552348 -0.58065720 -0.72454445 -0.6666844
## highway.mpg -0.18856420 -0.61174990 -0.72459867 -0.6933385
## height curb.weight engine.size bore
## normalized.losses -0.41370154 0.1258579 0.2078196 -0.03155814
## wheel.base 0.55576713 0.8101815 0.6492056 0.57815853
## length 0.49925137 0.8712911 0.7259533 0.64631755
## width 0.29270580 0.8705945 0.7792534 0.57255416
## height 1.00000000 0.3670518 0.1110826 0.25483608
## curb.weight 0.36705181 1.0000000 0.8886261 0.64579158
## engine.size 0.11108260 0.8886261 1.0000000 0.59573688
## bore 0.25483608 0.6457916 0.5957369 1.00000000
## compression.ratio 0.23330821 0.2247240 0.1410967 0.01511908
## horsepower 0.03431713 0.7900954 0.8120726 0.56023917
## peak.rpm -0.24586416 -0.2599879 -0.2846858 -0.31226891
## city.mpg -0.19973748 -0.7621552 -0.6991393 -0.59044028
## highway.mpg -0.22613562 -0.7893380 -0.7140951 -0.59085039
## compression.ratio horsepower peak.rpm city.mpg
## normalized.losses -0.12725910 0.29051055 0.23769662 -0.23552348
## wheel.base 0.29143145 0.51694753 -0.28923445 -0.58065720
## length 0.18481418 0.67206330 -0.23407384 -0.72454445
## width 0.25875169 0.68187176 -0.23221605 -0.66668439
## height 0.23330821 0.03431713 -0.24586416 -0.19973748
## curb.weight 0.22472399 0.79009539 -0.25998788 -0.76215523
## engine.size 0.14109671 0.81207263 -0.28468581 -0.69913926
## bore 0.01511908 0.56023917 -0.31226891 -0.59044028
## compression.ratio 1.00000000 -0.16230524 -0.41676855 0.27833158
## horsepower -0.16230524 1.00000000 0.07405682 -0.83721415
## peak.rpm -0.41676855 0.07405682 1.00000000 -0.05292904
## city.mpg 0.27833158 -0.83721415 -0.05292904 1.00000000
## highway.mpg 0.22148258 -0.82794105 -0.03277717 0.97199880
## highway.mpg
## normalized.losses -0.18856420
## wheel.base -0.61174990
## length -0.72459867
## width -0.69333851
## height -0.22613562
## curb.weight -0.78933796
## engine.size -0.71409510
## bore -0.59085039
## compression.ratio 0.22148258
## horsepower -0.82794105
## peak.rpm -0.03277717
## city.mpg 0.97199880
## highway.mpg 1.00000000
cor(data_numeric)
## normalized.losses wheel.base length width
## normalized.losses 1.00000000 -0.06008568 0.03554071 0.1097262
## wheel.base -0.06008568 1.00000000 0.87153448 0.8149912
## length 0.03554071 0.87153448 1.00000000 0.8383385
## width 0.10972620 0.81499125 0.83833846 1.0000000
## height -0.41370154 0.55576713 0.49925137 0.2927058
## curb.weight 0.12585792 0.81018149 0.87129108 0.8705945
## engine.size 0.20781961 0.64920558 0.72595331 0.7792534
## bore -0.03155814 0.57815853 0.64631755 0.5725542
## compression.ratio -0.12725910 0.29143145 0.18481418 0.2587517
## horsepower 0.29051055 0.51694753 0.67206330 0.6818718
## peak.rpm 0.23769662 -0.28923445 -0.23407384 -0.2322160
## city.mpg -0.23552348 -0.58065720 -0.72454445 -0.6666844
## highway.mpg -0.18856420 -0.61174990 -0.72459867 -0.6933385
## height curb.weight engine.size bore
## normalized.losses -0.41370154 0.1258579 0.2078196 -0.03155814
## wheel.base 0.55576713 0.8101815 0.6492056 0.57815853
## length 0.49925137 0.8712911 0.7259533 0.64631755
## width 0.29270580 0.8705945 0.7792534 0.57255416
## height 1.00000000 0.3670518 0.1110826 0.25483608
## curb.weight 0.36705181 1.0000000 0.8886261 0.64579158
## engine.size 0.11108260 0.8886261 1.0000000 0.59573688
## bore 0.25483608 0.6457916 0.5957369 1.00000000
## compression.ratio 0.23330821 0.2247240 0.1410967 0.01511908
## horsepower 0.03431713 0.7900954 0.8120726 0.56023917
## peak.rpm -0.24586416 -0.2599879 -0.2846858 -0.31226891
## city.mpg -0.19973748 -0.7621552 -0.6991393 -0.59044028
## highway.mpg -0.22613562 -0.7893380 -0.7140951 -0.59085039
## compression.ratio horsepower peak.rpm city.mpg
## normalized.losses -0.12725910 0.29051055 0.23769662 -0.23552348
## wheel.base 0.29143145 0.51694753 -0.28923445 -0.58065720
## length 0.18481418 0.67206330 -0.23407384 -0.72454445
## width 0.25875169 0.68187176 -0.23221605 -0.66668439
## height 0.23330821 0.03431713 -0.24586416 -0.19973748
## curb.weight 0.22472399 0.79009539 -0.25998788 -0.76215523
## engine.size 0.14109671 0.81207263 -0.28468581 -0.69913926
## bore 0.01511908 0.56023917 -0.31226891 -0.59044028
## compression.ratio 1.00000000 -0.16230524 -0.41676855 0.27833158
## horsepower -0.16230524 1.00000000 0.07405682 -0.83721415
## peak.rpm -0.41676855 0.07405682 1.00000000 -0.05292904
## city.mpg 0.27833158 -0.83721415 -0.05292904 1.00000000
## highway.mpg 0.22148258 -0.82794105 -0.03277717 0.97199880
## highway.mpg
## normalized.losses -0.18856420
## wheel.base -0.61174990
## length -0.72459867
## width -0.69333851
## height -0.22613562
## curb.weight -0.78933796
## engine.size -0.71409510
## bore -0.59085039
## compression.ratio 0.22148258
## horsepower -0.82794105
## peak.rpm -0.03277717
## city.mpg 0.97199880
## highway.mpg 1.00000000
corrplot::corrplot(cor(data_numeric),tl.col = "black",type= "full",tl.srt=40,tl.cex = 0.5)

#Check MSA
r <- cor(data_numeric)
KMO(data_numeric)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = data_numeric)
## Overall MSA = 0.87
## MSA for each item =
## normalized.losses wheel.base length width
## 0.64 0.92 0.91 0.94
## height curb.weight engine.size bore
## 0.69 0.89 0.88 0.95
## compression.ratio horsepower peak.rpm city.mpg
## 0.70 0.90 0.64 0.82
## highway.mpg
## 0.84
bartlett.test(data_numeric)
##
## Bartlett test of homogeneity of variances
##
## data: data_numeric
## Bartlett's K-squared = 11336, df = 12, p-value < 2.2e-16
data[sapply(data, is.numeric)]
## normalized.losses wheel.base length width height curb.weight engine.size
## 1 164 99.8 176.6 66.2 54.3 2337 109
## 2 164 99.4 176.6 66.4 54.3 2824 136
## 3 158 105.8 192.7 71.4 55.7 2844 136
## 4 158 105.8 192.7 71.4 55.9 3086 131
## 5 192 101.2 176.8 64.8 54.3 2395 108
## 6 192 101.2 176.8 64.8 54.3 2395 108
## 7 188 101.2 176.8 64.8 54.3 2710 164
## 8 188 101.2 176.8 64.8 54.3 2765 164
## 9 121 88.4 141.1 60.3 53.2 1488 61
## 10 98 94.5 155.9 63.6 52.0 1874 90
## 11 81 94.5 158.8 63.6 52.0 1909 90
## 12 118 93.7 157.3 63.8 50.8 1876 90
## 13 118 93.7 157.3 63.8 50.8 1876 90
## 14 118 93.7 157.3 63.8 50.8 2128 98
## 15 148 93.7 157.3 63.8 50.6 1967 90
## 16 148 93.7 157.3 63.8 50.6 1989 90
## 17 148 93.7 157.3 63.8 50.6 1989 90
## 18 110 103.3 174.6 64.6 59.8 2535 122
## 19 145 95.9 173.2 66.3 50.2 2811 156
## 20 137 86.6 144.6 63.9 50.8 1713 92
## 21 137 86.6 144.6 63.9 50.8 1819 92
## 22 101 93.7 150.0 64.0 52.6 1837 79
## 23 101 93.7 150.0 64.0 52.6 1940 92
## 24 101 93.7 150.0 64.0 52.6 1956 92
## 25 110 96.5 163.4 64.0 54.5 2010 92
## 26 78 96.5 157.1 63.9 58.3 2024 92
## 27 106 96.5 167.5 65.2 53.3 2236 110
## 28 106 96.5 167.5 65.2 53.3 2289 110
## 29 85 96.5 175.4 65.2 54.1 2304 110
## 30 85 96.5 175.4 62.5 54.1 2372 110
## 31 85 96.5 175.4 65.2 54.1 2465 110
## 32 107 96.5 169.1 66.0 51.0 2293 110
## 33 145 113.0 199.6 69.6 52.8 4066 258
## 34 104 93.1 159.1 64.2 54.1 1890 91
## 35 104 93.1 159.1 64.2 54.1 1900 91
## 36 104 93.1 159.1 64.2 54.1 1905 91
## 37 113 93.1 166.8 64.2 54.1 1945 91
## 38 113 93.1 166.8 64.2 54.1 1950 91
## 39 129 98.8 177.8 66.5 53.7 2385 122
## 40 115 98.8 177.8 66.5 55.5 2410 122
## 41 129 98.8 177.8 66.5 53.7 2385 122
## 42 115 98.8 177.8 66.5 55.5 2410 122
## 43 115 98.8 177.8 66.5 55.5 2425 122
## 44 118 104.9 175.0 66.1 54.4 2670 140
## 45 93 110.0 190.9 70.3 56.5 3515 183
## 46 93 110.0 190.9 70.3 58.7 3750 183
## 47 93 106.7 187.5 70.3 54.9 3495 183
## 48 93 115.6 202.6 71.7 56.3 3770 183
## 49 142 96.6 180.3 70.5 50.8 3685 234
## 50 161 93.7 157.3 64.4 50.8 1918 92
## 51 161 93.7 157.3 64.4 50.8 1944 92
## 52 161 93.7 157.3 64.4 50.8 2004 92
## 53 161 93.0 157.3 63.8 50.8 2145 98
## 54 153 96.3 173.0 65.4 49.4 2370 110
## 55 153 96.3 173.0 65.4 49.4 2328 122
## 56 125 96.3 172.4 65.4 51.6 2365 122
## 57 125 96.3 172.4 65.4 51.6 2405 122
## 58 125 96.3 172.4 65.4 51.6 2403 110
## 59 137 96.3 172.4 65.4 51.6 2403 110
## 60 128 94.5 165.3 63.8 54.5 1889 97
## 61 128 94.5 165.3 63.8 54.5 2017 103
## 62 128 94.5 165.3 63.8 54.5 1918 97
## 63 122 94.5 165.3 63.8 54.5 1938 97
## 64 103 94.5 170.2 63.8 53.5 2024 97
## 65 128 94.5 165.3 63.8 54.5 1951 97
## 66 128 94.5 165.6 63.8 53.3 2028 97
## 67 122 94.5 165.3 63.8 54.5 1971 97
## 68 103 94.5 170.2 63.8 53.5 2037 97
## 69 168 95.1 162.4 63.8 53.3 2008 97
## 70 106 97.2 173.4 65.2 54.7 2324 120
## 71 106 97.2 173.4 65.2 54.7 2302 120
## 72 128 100.4 181.7 66.5 55.1 3095 181
## 73 108 100.4 184.6 66.5 56.1 3296 181
## 74 108 100.4 184.6 66.5 55.1 3060 181
## 75 194 91.3 170.7 67.9 49.7 3071 181
## 76 194 91.3 170.7 67.9 49.7 3139 181
## 77 231 99.2 178.5 67.9 49.7 3139 181
## 78 161 107.9 186.7 68.4 56.7 3020 120
## 79 161 107.9 186.7 68.4 56.7 3197 152
## 80 161 107.9 186.7 68.4 56.7 3075 120
## 81 161 107.9 186.7 68.4 56.7 3252 152
## 82 161 107.9 186.7 68.4 56.7 3075 120
## 83 161 107.9 186.7 68.4 56.7 3252 152
## 84 161 108.0 186.7 68.3 56.0 3130 134
## 85 119 93.7 157.3 63.8 50.8 1918 90
## 86 119 93.7 157.3 63.8 50.8 2128 98
## 87 154 93.7 157.3 63.8 50.6 1967 90
## 88 154 93.7 167.3 63.8 50.8 1989 90
## 89 154 93.7 167.3 63.8 50.8 2191 98
## 90 74 103.3 174.6 64.6 59.8 2535 122
## 91 186 94.5 168.9 68.3 50.2 2778 151
## 92 150 99.1 186.6 66.5 56.1 2658 121
## 93 104 99.1 186.6 66.5 56.1 2695 121
## 94 150 99.1 186.6 66.5 56.1 2707 121
## 95 104 99.1 186.6 66.5 56.1 2758 121
## 96 150 99.1 186.6 66.5 56.1 2808 121
## 97 104 99.1 186.6 66.5 56.1 2847 121
## 98 83 93.7 156.9 63.4 53.7 2050 97
## 99 83 93.7 157.9 63.6 53.7 2120 108
## 100 83 93.3 157.3 63.8 55.7 2240 108
## 101 102 97.2 172.0 65.4 52.5 2145 108
## 102 102 97.2 172.0 65.4 52.5 2190 108
## 103 102 97.2 172.0 65.4 52.5 2340 108
## 104 102 97.0 172.0 65.4 54.3 2385 108
## 105 102 97.0 172.0 65.4 54.3 2510 108
## 106 89 97.0 173.5 65.4 53.0 2290 108
## 107 89 97.0 173.5 65.4 53.0 2455 108
## 108 85 96.9 173.6 65.4 54.9 2420 108
## 109 85 96.9 173.6 65.4 54.9 2650 108
## 110 87 95.7 158.7 63.6 54.5 1985 92
## 111 87 95.7 158.7 63.6 54.5 2040 92
## 112 74 95.7 158.7 63.6 54.5 2015 92
## 113 77 95.7 169.7 63.6 59.1 2280 92
## 114 81 95.7 169.7 63.6 59.1 2290 92
## 115 91 95.7 169.7 63.6 59.1 3110 92
## 116 91 95.7 166.3 64.4 53.0 2081 98
## 117 91 95.7 166.3 64.4 52.8 2109 98
## 118 91 95.7 166.3 64.4 53.0 2275 110
## 119 91 95.7 166.3 64.4 52.8 2275 110
## 120 91 95.7 166.3 64.4 53.0 2094 98
## 121 91 95.7 166.3 64.4 52.8 2122 98
## 122 91 95.7 166.3 64.4 52.8 2140 98
## 123 168 94.5 168.7 64.0 52.6 2169 98
## 124 168 94.5 168.7 64.0 52.6 2204 98
## 125 168 94.5 168.7 64.0 52.6 2265 98
## 126 168 94.5 168.7 64.0 52.6 2300 98
## 127 134 98.4 176.2 65.6 52.0 2540 146
## 128 134 98.4 176.2 65.6 52.0 2536 146
## 129 134 98.4 176.2 65.6 52.0 2551 146
## 130 134 98.4 176.2 65.6 52.0 2679 146
## 131 134 98.4 176.2 65.6 52.0 2714 146
## 132 134 98.4 176.2 65.6 53.0 2975 146
## 133 65 102.4 175.6 66.5 54.9 2326 122
## 134 65 102.4 175.6 66.5 54.9 2480 110
## 135 65 102.4 175.6 66.5 53.9 2414 122
## 136 65 102.4 175.6 66.5 54.9 2414 122
## 137 65 102.4 175.6 66.5 53.9 2458 122
## 138 197 102.9 183.5 67.7 52.0 2976 171
## 139 197 102.9 183.5 67.7 52.0 3016 171
## 140 90 104.5 187.8 66.5 54.1 3131 171
## 141 122 97.3 171.7 65.5 55.7 2261 97
## 142 122 97.3 171.7 65.5 55.7 2209 109
## 143 94 97.3 171.7 65.5 55.7 2264 97
## 144 94 97.3 171.7 65.5 55.7 2212 109
## 145 94 97.3 171.7 65.5 55.7 2275 109
## 146 94 97.3 171.7 65.5 55.7 2319 97
## 147 94 97.3 171.7 65.5 55.7 2300 109
## 148 256 94.5 165.7 64.0 51.4 2221 109
## 149 103 104.3 188.8 67.2 56.2 2912 141
## 150 74 104.3 188.8 67.2 57.5 3034 141
## 151 103 104.3 188.8 67.2 56.2 2935 141
## 152 74 104.3 188.8 67.2 57.5 3042 141
## 153 103 104.3 188.8 67.2 56.2 3045 130
## 154 74 104.3 188.8 67.2 57.5 3157 130
## 155 95 109.1 188.8 68.9 55.5 2952 141
## 156 95 109.1 188.8 68.8 55.5 3049 141
## 157 95 109.1 188.8 68.9 55.5 3012 173
## 158 95 109.1 188.8 68.9 55.5 3217 145
## 159 95 109.1 188.8 68.9 55.5 3062 141
## bore compression.ratio horsepower peak.rpm city.mpg highway.mpg
## 1 3.19 10.00 102 5500 24 30
## 2 3.19 8.00 115 5500 18 22
## 3 3.19 8.50 110 5500 19 25
## 4 3.13 8.30 140 5500 17 20
## 5 3.50 8.80 101 5800 23 29
## 6 3.50 8.80 101 5800 23 29
## 7 3.31 9.00 121 4250 21 28
## 8 3.31 9.00 121 4250 21 28
## 9 2.91 9.50 48 5100 47 53
## 10 3.03 9.60 70 5400 38 43
## 11 3.03 9.60 70 5400 38 43
## 12 2.97 9.41 68 5500 37 41
## 13 2.97 9.40 68 5500 31 38
## 14 3.03 7.60 102 5500 24 30
## 15 2.97 9.40 68 5500 31 38
## 16 2.97 9.40 68 5500 31 38
## 17 2.97 9.40 68 5500 31 38
## 18 3.34 8.50 88 5000 24 30
## 19 3.60 7.00 145 5000 19 24
## 20 2.91 9.60 58 4800 49 54
## 21 2.91 9.20 76 6000 31 38
## 22 2.91 10.10 60 5500 38 42
## 23 2.91 9.20 76 6000 30 34
## 24 2.91 9.20 76 6000 30 34
## 25 2.91 9.20 76 6000 30 34
## 26 2.92 9.20 76 6000 30 34
## 27 3.15 9.00 86 5800 27 33
## 28 3.15 9.00 86 5800 27 33
## 29 3.15 9.00 86 5800 27 33
## 30 3.15 9.00 86 5800 27 33
## 31 3.15 9.00 101 5800 24 28
## 32 3.15 9.10 100 5500 25 31
## 33 3.63 8.10 176 4750 15 19
## 34 3.03 9.00 68 5000 30 31
## 35 3.03 9.00 68 5000 31 38
## 36 3.03 9.00 68 5000 31 38
## 37 3.03 9.00 68 5000 31 38
## 38 3.08 9.00 68 5000 31 38
## 39 3.39 8.60 84 4800 26 32
## 40 3.39 8.60 84 4800 26 32
## 41 3.39 8.60 84 4800 26 32
## 42 3.39 8.60 84 4800 26 32
## 43 3.39 8.60 84 4800 26 32
## 44 3.76 8.00 120 5000 19 27
## 45 3.58 21.50 123 4350 22 25
## 46 3.58 21.50 123 4350 22 25
## 47 3.58 21.50 123 4350 22 25
## 48 3.58 21.50 123 4350 22 25
## 49 3.46 8.30 155 4750 16 18
## 50 2.97 9.40 68 5500 37 41
## 51 2.97 9.40 68 5500 31 38
## 52 2.97 9.40 68 5500 31 38
## 53 3.03 7.60 102 5500 24 30
## 54 3.17 7.50 116 5500 23 30
## 55 3.35 8.50 88 5000 25 32
## 56 3.35 8.50 88 5000 25 32
## 57 3.35 8.50 88 5000 25 32
## 58 3.17 7.50 116 5500 23 30
## 59 3.17 7.50 116 5500 23 30
## 60 3.15 9.40 69 5200 31 37
## 61 2.99 21.90 55 4800 45 50
## 62 3.15 9.40 69 5200 31 37
## 63 3.15 9.40 69 5200 31 37
## 64 3.15 9.40 69 5200 31 37
## 65 3.15 9.40 69 5200 31 37
## 66 3.15 9.40 69 5200 31 37
## 67 3.15 9.40 69 5200 31 37
## 68 3.15 9.40 69 5200 31 37
## 69 3.15 9.40 69 5200 31 37
## 70 3.33 8.50 97 5200 27 34
## 71 3.33 8.50 97 5200 27 34
## 72 3.43 9.00 152 5200 17 22
## 73 3.43 9.00 152 5200 17 22
## 74 3.43 9.00 152 5200 19 25
## 75 3.43 9.00 160 5200 19 25
## 76 3.43 7.80 200 5200 17 23
## 77 3.43 9.00 160 5200 19 25
## 78 3.46 8.40 97 5000 19 24
## 79 3.70 21.00 95 4150 28 33
## 80 3.46 8.40 95 5000 19 24
## 81 3.70 21.00 95 4150 28 33
## 82 3.46 8.40 97 5000 19 24
## 83 3.70 21.00 95 4150 28 33
## 84 3.61 7.00 142 5600 18 24
## 85 2.97 9.40 68 5500 37 41
## 86 3.03 7.60 102 5500 24 30
## 87 2.97 9.40 68 5500 31 38
## 88 2.97 9.40 68 5500 31 38
## 89 2.97 9.40 68 5500 31 38
## 90 3.35 8.50 88 5000 24 30
## 91 3.94 9.50 143 5500 19 27
## 92 3.54 9.31 110 5250 21 28
## 93 3.54 9.30 110 5250 21 28
## 94 2.54 9.30 110 5250 21 28
## 95 3.54 9.30 110 5250 21 28
## 96 3.54 9.00 160 5500 19 26
## 97 3.54 9.00 160 5500 19 26
## 98 3.62 9.00 69 4900 31 36
## 99 3.62 8.70 73 4400 26 31
## 100 3.62 8.70 73 4400 26 31
## 101 3.62 9.50 82 4800 32 37
## 102 3.62 9.50 82 4400 28 33
## 103 3.62 9.00 94 5200 26 32
## 104 3.62 9.00 82 4800 24 25
## 105 3.62 7.70 111 4800 24 29
## 106 3.62 9.00 82 4800 28 32
## 107 3.62 9.00 94 5200 25 31
## 108 3.62 9.00 82 4800 23 29
## 109 3.62 7.70 111 4800 23 23
## 110 3.05 9.00 62 4800 35 39
## 111 3.05 9.00 62 4800 31 38
## 112 3.05 9.00 62 4800 31 38
## 113 3.05 9.00 62 4800 31 37
## 114 3.05 9.00 62 4800 27 32
## 115 3.05 9.00 62 4800 27 32
## 116 3.19 9.00 70 4800 30 37
## 117 3.19 9.00 70 4800 30 37
## 118 3.27 22.50 56 4500 34 36
## 119 3.27 22.50 56 4500 38 47
## 120 3.19 9.00 70 4800 38 47
## 121 3.19 9.00 70 4800 28 34
## 122 3.19 9.00 70 4800 28 34
## 123 3.19 9.00 70 4800 29 34
## 124 3.19 9.00 70 4800 29 34
## 125 3.24 9.40 112 6600 26 29
## 126 3.24 9.40 112 6600 26 29
## 127 3.62 9.30 116 4800 24 30
## 128 3.62 9.30 116 4800 24 30
## 129 3.62 9.30 116 4800 24 30
## 130 3.62 9.30 116 4800 24 30
## 131 3.62 9.30 116 4800 24 30
## 132 3.62 9.30 116 4800 24 30
## 133 3.31 8.70 92 4200 29 34
## 134 3.27 22.50 73 4500 30 33
## 135 3.31 8.70 92 4200 27 32
## 136 3.31 8.70 92 4200 27 32
## 137 3.31 8.70 92 4200 27 32
## 138 3.27 9.30 161 5200 20 24
## 139 3.27 9.30 161 5200 19 24
## 140 3.27 9.20 156 5200 20 24
## 141 3.01 23.00 52 4800 37 46
## 142 3.19 9.00 85 5250 27 34
## 143 3.01 23.00 52 4800 37 46
## 144 3.19 9.00 85 5250 27 34
## 145 3.19 9.00 85 5250 27 34
## 146 3.01 23.00 68 4500 37 42
## 147 3.19 10.00 100 5500 26 32
## 148 3.19 8.50 90 5500 24 29
## 149 3.78 9.50 114 5400 23 28
## 150 3.78 9.50 114 5400 23 28
## 151 3.78 9.50 114 5400 24 28
## 152 3.78 9.50 114 5400 24 28
## 153 3.62 7.50 162 5100 17 22
## 154 3.62 7.50 162 5100 17 22
## 155 3.78 9.50 114 5400 23 28
## 156 3.78 8.70 160 5300 19 25
## 157 3.58 8.80 134 5500 18 23
## 158 3.01 23.00 106 4800 26 27
## 159 3.78 9.50 114 5400 19 25
data_numeric <- na.omit(data_numeric)
scale_data <- scale(data_numeric)
pc <- prcomp(scale_data, center = TRUE, scale. = TRUE)
summary(pc)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.6438 1.5052 1.08693 0.89435 0.69383 0.62798 0.52403
## Proportion of Variance 0.5377 0.1743 0.09088 0.06153 0.03703 0.03034 0.02112
## Cumulative Proportion 0.5377 0.7119 0.80283 0.86436 0.90139 0.93173 0.95285
## PC8 PC9 PC10 PC11 PC12 PC13
## Standard deviation 0.46059 0.3551 0.34175 0.29453 0.22192 0.14808
## Proportion of Variance 0.01632 0.0097 0.00898 0.00667 0.00379 0.00169
## Cumulative Proportion 0.96917 0.9789 0.98785 0.99452 0.99831 1.00000
L <- as.matrix(pc$rotation[, 1:3])
L
## PC1 PC2 PC3
## normalized.losses -0.04712085 -0.40728655 -0.52377869
## wheel.base -0.31934324 0.21969671 0.05769507
## length -0.34775495 0.10955469 0.06314271
## width -0.33745867 0.07287623 -0.14678535
## height -0.14210671 0.39502019 0.48668747
## curb.weight -0.36306536 0.04719091 -0.10245181
## engine.size -0.33130027 -0.04426188 -0.26057098
## bore -0.27710397 0.05225351 0.07597513
## compression.ratio -0.03767052 0.47377617 -0.48168250
## horsepower -0.31565365 -0.27247665 -0.03889134
## peak.rpm 0.08605377 -0.43815929 0.27174736
## city.mpg 0.32446240 0.25631945 -0.18656302
## highway.mpg 0.32968622 0.22178768 -0.18325048
lambda <- pc$sdev^2
lambda
## [1] 6.98987311 2.26551757 1.18142742 0.79985778 0.48140230 0.39436479
## [7] 0.27460541 0.21214078 0.12608875 0.11679354 0.08675014 0.04924972
## [13] 0.02192869
lambda_k <- lambda[1:ncol(L)]
V <- sweep(L, 2, sqrt(lambda_k[1:3]), "/")
V
## PC1 PC2 PC3
## normalized.losses -0.01782290 -0.27059287 -0.48188599
## wheel.base -0.12078780 0.14596201 0.05308052
## length -0.13153420 0.07278590 0.05809245
## width -0.12763975 0.04841748 -0.13504521
## height -0.05375018 0.26244335 0.44776139
## curb.weight -0.13732518 0.03135268 -0.09425754
## engine.size -0.12531041 -0.02940669 -0.23973008
## bore -0.10481130 0.03471616 0.06989852
## compression.ratio -0.01424843 0.31476721 -0.44315672
## horsepower -0.11939226 -0.18102792 -0.03578075
## peak.rpm 0.03254882 -0.29110409 0.25001255
## city.mpg 0.12272407 0.17029341 -0.17164140
## highway.mpg 0.12469991 0.14735121 -0.16859380
scores <- scale_data %*% V
head(scores)
## PC1 PC2 PC3
## 1 -0.1201427 -0.6156282 -0.08478590
## 2 -0.6921532 -1.2048871 0.17994964
## 3 -1.2933873 -0.4230449 0.17610260
## 4 -1.5756409 -0.7500330 0.36656010
## 5 -0.2215470 -1.1066110 0.07995753
## 6 -0.2215470 -1.1066110 0.07995753
fa <- principal(scale_data, nfactors = 3, rotate = "none")
fa
## Principal Components Analysis
## Call: principal(r = scale_data, nfactors = 3, rotate = "none")
## Standardized loadings (pattern matrix) based upon correlation matrix
## PC1 PC2 PC3 h2 u2 com
## normalized.losses 0.12 -0.61 0.57 0.72 0.285 2.1
## wheel.base 0.84 0.33 -0.06 0.83 0.174 1.3
## length 0.92 0.16 -0.07 0.88 0.123 1.1
## width 0.89 0.11 0.16 0.83 0.167 1.1
## height 0.38 0.59 -0.53 0.77 0.225 2.7
## curb.weight 0.96 0.07 0.11 0.94 0.061 1.0
## engine.size 0.88 -0.07 0.28 0.85 0.148 1.2
## bore 0.73 0.08 -0.08 0.55 0.450 1.0
## compression.ratio 0.10 0.71 0.52 0.79 0.207 1.9
## horsepower 0.83 -0.41 0.04 0.87 0.134 1.5
## peak.rpm -0.23 -0.66 -0.30 0.57 0.426 1.7
## city.mpg -0.86 0.39 0.20 0.93 0.074 1.5
## highway.mpg -0.87 0.33 0.20 0.91 0.089 1.4
##
## PC1 PC2 PC3
## SS loadings 6.99 2.27 1.18
## Proportion Var 0.54 0.17 0.09
## Cumulative Var 0.54 0.71 0.80
## Proportion Explained 0.67 0.22 0.11
## Cumulative Proportion 0.67 0.89 1.00
##
## Mean item complexity = 1.5
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.04
## with the empirical chi square 39.62 with prob < 0.58
##
## Fit based upon off diagonal values = 0.99
fa$loadings
##
## Loadings:
## PC1 PC2 PC3
## normalized.losses 0.125 -0.613 0.569
## wheel.base 0.844 0.331
## length 0.919 0.165
## width 0.892 0.110 0.160
## height 0.376 0.595 -0.529
## curb.weight 0.960 0.111
## engine.size 0.876 0.283
## bore 0.733
## compression.ratio 0.713 0.524
## horsepower 0.835 -0.410
## peak.rpm -0.228 -0.660 -0.295
## city.mpg -0.858 0.386 0.203
## highway.mpg -0.872 0.334 0.199
##
## PC1 PC2 PC3
## SS loadings 6.990 2.266 1.181
## Proportion Var 0.538 0.174 0.091
## Cumulative Var 0.538 0.712 0.803
fa.diagram(fa$loadings)

fa_1 <- principal(scale_data, nfactors = 3, rotate = "varimax")
fa_1
## Principal Components Analysis
## Call: principal(r = scale_data, nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 RC3 h2 u2 com
## normalized.losses 0.20 -0.09 -0.82 0.72 0.285 1.1
## wheel.base 0.79 0.31 0.32 0.83 0.174 1.7
## length 0.89 0.19 0.23 0.88 0.123 1.2
## width 0.87 0.29 0.02 0.83 0.167 1.2
## height 0.30 0.16 0.81 0.77 0.225 1.4
## curb.weight 0.94 0.24 0.03 0.94 0.061 1.1
## engine.size 0.87 0.23 -0.19 0.85 0.148 1.2
## bore 0.72 0.09 0.17 0.55 0.450 1.1
## compression.ratio -0.01 0.89 0.05 0.79 0.207 1.0
## horsepower 0.88 -0.19 -0.23 0.87 0.134 1.2
## peak.rpm -0.13 -0.72 -0.20 0.57 0.426 1.2
## city.mpg -0.91 0.32 0.02 0.93 0.074 1.3
## highway.mpg -0.91 0.28 -0.01 0.91 0.089 1.2
##
## RC1 RC2 RC3
## SS loadings 6.90 1.90 1.64
## Proportion Var 0.53 0.15 0.13
## Cumulative Var 0.53 0.68 0.80
## Proportion Explained 0.66 0.18 0.16
## Cumulative Proportion 0.66 0.84 1.00
##
## Mean item complexity = 1.2
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.04
## with the empirical chi square 39.62 with prob < 0.58
##
## Fit based upon off diagonal values = 0.99
fa_1$communality
## normalized.losses wheel.base length width
## 0.7154471 0.8261096 0.8772115 0.8334822
## height curb.weight engine.size bore
## 0.7745077 0.9388263 0.8518616 0.5497340
## compression.ratio horsepower peak.rpm city.mpg
## 0.7925584 0.8664385 0.5739483 0.9258290
## highway.mpg
## 0.9108638
scores <- scale_data %*% solve(cor(scale_data)) %*% as.matrix(fa$loadings)
scores
## PC1 PC2 PC3
## 1 0.12014267 -0.61562816 0.08478590
## 2 0.69215317 -1.20488712 -0.17994964
## 3 1.29338731 -0.42304489 -0.17610260
## 4 1.57564088 -0.75003296 -0.36656010
## 5 0.22154705 -1.10661104 -0.07995753
## 6 0.22154705 -1.10661104 -0.07995753
## 7 0.71153498 -0.34606926 1.21369217
## 8 0.72720677 -0.34249124 1.22444900
## 9 -2.62561725 0.54019558 0.47974739
## 10 -1.42232529 0.14790846 0.13116938
## 11 -1.38774824 0.29753299 -0.10638837
## 12 -1.41004192 -0.29879505 0.51142775
## 13 -1.23139233 -0.53562250 0.26307748
## 14 -0.68225748 -1.24320764 -0.21171691
## 15 -1.19520323 -0.78053756 0.72584659
## 16 -1.18893451 -0.77910635 0.73014932
## 17 -1.18893451 -0.77910635 0.73014932
## 18 0.32132937 0.77034338 -1.68438822
## 19 0.78679949 -1.49634667 0.73598284
## 20 -2.24842588 0.40192744 1.97456802
## 21 -1.56238920 -1.34738570 0.40220026
## 22 -1.59400602 0.15133269 0.02210541
## 23 -1.17175839 -0.74009098 -0.64176050
## 24 -1.16719932 -0.73905010 -0.63863124
## 25 -0.88389209 -0.42032953 -0.97771922
## 26 -0.88041813 0.22205237 -2.13526672
## 27 -0.42454746 -0.50128118 -0.62365361
## 28 -0.40944555 -0.49783327 -0.61328793
## 29 -0.30654014 -0.19502594 -1.09191818
## 30 -0.46408818 -0.25771467 -1.26580775
## 31 -0.04545137 -0.47080206 -1.25791841
## 32 -0.23699811 -0.72961982 -0.01743231
## 33 2.87370004 -0.63991370 1.23577469
## 34 -0.90710492 0.05699055 -0.54574155
## 35 -1.05952435 0.24525968 -0.33292491
## 36 -1.05809964 0.24558495 -0.33194702
## 37 -0.95430908 0.22851413 -0.24129245
## 38 -0.93328142 0.23533240 -0.25338773
## 39 0.13894289 0.11572303 0.11832605
## 40 0.18171207 0.43182773 -0.42126454
## 41 0.13894289 0.11572303 0.11832605
## 42 0.18171207 0.43182773 -0.42126454
## 43 0.18598620 0.43280355 -0.41833085
## 44 0.89593179 -0.22121120 -0.60547689
## 45 1.94097386 2.06970474 1.27434571
## 46 2.06005628 2.33948191 0.88611605
## 47 1.78142144 1.76863069 1.63724792
## 48 2.36508612 2.33004127 1.34424316
## 49 1.92448531 -1.28991370 1.69952843
## 50 -1.32907019 -0.61025847 1.15705649
## 51 -1.14297549 -0.84458521 0.91493064
## 52 -1.12587899 -0.84068191 0.92666537
## 53 -0.67227920 -1.58824388 0.38001446
## 54 -0.10571305 -1.55461210 0.62466777
## 55 -0.14683274 -0.88562620 1.12205474
## 56 -0.10501547 -0.42000010 0.31965903
## 57 -0.09361780 -0.41739790 0.32748219
## 58 -0.06503555 -1.08924623 -0.17851025
## 59 -0.05903647 -1.18032610 -0.01631043
## 60 -0.88148763 0.06587305 -0.23386407
## 61 -1.39649878 2.07932426 2.23628541
## 62 -0.87322432 0.06775964 -0.22819228
## 63 -0.87052503 0.11460068 -0.30538061
## 64 -0.82327772 0.17967901 -0.37272045
## 65 -0.86382125 0.06990646 -0.22173817
## 66 -0.86688602 -0.06200169 0.02864028
## 67 -0.86112195 0.11674749 -0.29892651
## 68 -0.81957348 0.18052473 -0.37017793
## 69 -0.87509019 -0.37016712 0.57536381
## 70 -0.10734025 0.02968593 -0.58402321
## 71 -0.11360897 0.02825472 -0.58832595
## 72 1.32625002 -0.74834854 -0.21916017
## 73 1.43031904 -0.44947798 -0.66216119
## 74 1.24120767 -0.45620987 -0.37635199
## 75 0.91085674 -2.09007784 2.12390299
## 76 1.16017052 -2.51997733 1.93856409
## 77 1.22242666 -2.09406691 2.51684582
## 78 1.19613446 0.03688263 -0.47856076
## 79 1.21518628 2.06809699 2.12297536
## 80 1.20403296 0.05224687 -0.47013350
## 81 1.23085808 2.07167501 2.13373220
## 82 1.21180625 0.04046065 -0.46780392
## 83 1.23085808 2.07167501 2.13373220
## 84 1.47104933 -0.81206114 -0.71321538
## 85 -1.39761108 -0.30446201 0.53201934
## 86 -0.68175756 -1.25079763 -0.19820026
## 87 -1.19220369 -0.82607749 0.80694650
## 88 -1.06704918 -0.73834611 0.72136378
## 89 -0.97658034 -0.73292817 0.82383167
## 90 0.30725272 1.04488159 -2.17360232
## 91 0.86839630 -1.80766069 1.42260374
## 92 0.69631692 -0.27169852 -0.48816556
## 93 0.68382666 0.07903874 -1.10383449
## 94 0.31818358 -0.39917996 -0.21825804
## 95 0.70177799 0.08313720 -1.09151302
## 96 0.99365173 -0.83942263 -0.67861226
## 97 0.98176799 -0.48774598 -1.29275066
## 98 -0.79478315 0.43311157 -0.66343145
## 99 -0.45850558 0.44927744 -0.58673474
## 100 -0.38002306 0.67832066 -0.93698456
## 101 -0.33625049 0.46670308 0.14199146
## 102 -0.13773873 0.51666608 0.14849847
## 103 -0.04653453 -0.16344220 -0.37699154
## 104 0.16096825 0.14722937 -0.75965646
## 105 0.22731311 -0.02949463 -0.74514324
## 106 -0.10193016 0.37022241 -0.40963352
## 107 0.04346157 -0.04636984 -0.68865626
## 108 0.13548834 0.41854454 -1.03179444
## 109 0.42481024 0.02052482 -1.25775933
## 110 -1.11464046 0.77861705 -0.44960019
## 111 -0.99915034 0.64766227 -0.57754923
## 112 -1.01277288 0.74470576 -0.75815517
## 113 -0.68191494 1.31795786 -1.65518640
## 114 -0.50002424 1.06246507 -1.84227544
## 115 -0.26137282 1.03991025 -1.54673424
## 116 -0.73173280 0.42884505 -0.23659405
## 117 -0.72849272 0.40753120 -0.19164596
## 118 -0.64092307 1.89171283 1.64426087
## 119 -0.93853785 2.23123672 2.08345251
## 120 -1.08211175 0.88125754 0.25217134
## 121 -0.62661477 0.28407890 -0.32370985
## 122 -0.62148582 0.28524989 -0.32018943
## 123 -0.62646028 -0.32117702 0.76638318
## 124 -0.61648732 -0.31890010 0.77322844
## 125 -0.38367623 -1.84645966 -0.31460050
## 126 -0.37370327 -1.84418274 -0.30775524
## 127 0.45345507 -0.37928699 0.63878452
## 128 0.45231530 -0.37954721 0.63800220
## 129 0.45658943 -0.37857138 0.64093589
## 130 0.49306197 -0.37024434 0.66596998
## 131 0.50303493 -0.36796742 0.67281525
## 132 0.60109613 -0.23531114 0.52650193
## 133 0.12063231 1.27923193 -0.52063959
## 134 0.05438522 2.34202822 0.81671483
## 135 0.20088365 1.06779447 -0.41457427
## 136 0.22457507 1.18347140 -0.61193367
## 137 0.21342108 1.07065688 -0.40596880
## 138 1.24422508 -1.43705167 1.49492277
## 139 1.27575088 -1.46237951 1.47459480
## 140 1.27270202 -0.30801732 -0.47402506
## 141 -0.83786585 2.24172067 1.76268070
## 142 -0.25427033 0.08835475 -0.59308061
## 143 -0.85100887 2.45443553 1.38480119
## 144 -0.26741335 0.30106961 -0.97096012
## 145 -0.24946202 0.30516808 -0.95863865
## 146 -0.67496227 2.45997793 1.47082614
## 147 -0.13910670 0.06951653 -1.03689128
## 148 -0.36091977 -2.00364485 1.62385687
## 149 1.08197039 0.25707088 -1.01274066
## 150 1.13303435 0.63549729 -1.63743017
## 151 1.06839592 0.28649718 -0.98009123
## 152 1.11518575 0.66394776 -1.60771441
## 153 1.44868735 -0.30611154 -1.36790875
## 154 1.49690190 0.07166432 -1.99455404
## 155 1.29638081 0.41725889 -0.90634580
## 156 1.63874083 -0.03239827 -1.06910676
## 157 1.63205790 -0.12642913 -0.97187645
## 158 1.10567397 1.90630388 1.28755288
## 159 1.46615436 0.24425685 -1.07574078