Problem 1: Complete the tables below. Use the relationships between the output tables that we discussed in class. There were 50 observations in the dataset. There are eight missing values in the summary output and four missing values in the anova table.

# Intercept t-value: -17.5791/6.7584 = -2.60107421875
# Speed t-value: 3.9324/0.4155 = 9.46426
# Speed p-value: <2e-16 

# Residual standard error: 15.38 on 49 degrees of freedom

# Multiple R squared: 0.6742

# F-statistic: 49 on 1 and 48DF;
# p-value: <2e-16

#I would like to review this more because a lot of this is still confusing.

Problem 2 (textbook 3.8 ) This question involves the use of simple linear regression on the Auto data set from the textbook website.

2(a) Use the lm() function to perform a simple linear regression with mpg as the response and horsepower as the predictor. Use the summary() function to print the results. Comment on the output. Answer the following:

auto<-read.csv("Auto.csv",
               header=TRUE,
               na.strings = "?")
na.omit(auto)
##      mpg cylinders displacement horsepower weight acceleration year origin
## 1   18.0         8        307.0        130   3504         12.0   70      1
## 2   15.0         8        350.0        165   3693         11.5   70      1
## 3   18.0         8        318.0        150   3436         11.0   70      1
## 4   16.0         8        304.0        150   3433         12.0   70      1
## 5   17.0         8        302.0        140   3449         10.5   70      1
## 6   15.0         8        429.0        198   4341         10.0   70      1
## 7   14.0         8        454.0        220   4354          9.0   70      1
## 8   14.0         8        440.0        215   4312          8.5   70      1
## 9   14.0         8        455.0        225   4425         10.0   70      1
## 10  15.0         8        390.0        190   3850          8.5   70      1
## 11  15.0         8        383.0        170   3563         10.0   70      1
## 12  14.0         8        340.0        160   3609          8.0   70      1
## 13  15.0         8        400.0        150   3761          9.5   70      1
## 14  14.0         8        455.0        225   3086         10.0   70      1
## 15  24.0         4        113.0         95   2372         15.0   70      3
## 16  22.0         6        198.0         95   2833         15.5   70      1
## 17  18.0         6        199.0         97   2774         15.5   70      1
## 18  21.0         6        200.0         85   2587         16.0   70      1
## 19  27.0         4         97.0         88   2130         14.5   70      3
## 20  26.0         4         97.0         46   1835         20.5   70      2
## 21  25.0         4        110.0         87   2672         17.5   70      2
## 22  24.0         4        107.0         90   2430         14.5   70      2
## 23  25.0         4        104.0         95   2375         17.5   70      2
## 24  26.0         4        121.0        113   2234         12.5   70      2
## 25  21.0         6        199.0         90   2648         15.0   70      1
## 26  10.0         8        360.0        215   4615         14.0   70      1
## 27  10.0         8        307.0        200   4376         15.0   70      1
## 28  11.0         8        318.0        210   4382         13.5   70      1
## 29   9.0         8        304.0        193   4732         18.5   70      1
## 30  27.0         4         97.0         88   2130         14.5   71      3
## 31  28.0         4        140.0         90   2264         15.5   71      1
## 32  25.0         4        113.0         95   2228         14.0   71      3
## 34  19.0         6        232.0        100   2634         13.0   71      1
## 35  16.0         6        225.0        105   3439         15.5   71      1
## 36  17.0         6        250.0        100   3329         15.5   71      1
## 37  19.0         6        250.0         88   3302         15.5   71      1
## 38  18.0         6        232.0        100   3288         15.5   71      1
## 39  14.0         8        350.0        165   4209         12.0   71      1
## 40  14.0         8        400.0        175   4464         11.5   71      1
## 41  14.0         8        351.0        153   4154         13.5   71      1
## 42  14.0         8        318.0        150   4096         13.0   71      1
## 43  12.0         8        383.0        180   4955         11.5   71      1
## 44  13.0         8        400.0        170   4746         12.0   71      1
## 45  13.0         8        400.0        175   5140         12.0   71      1
## 46  18.0         6        258.0        110   2962         13.5   71      1
## 47  22.0         4        140.0         72   2408         19.0   71      1
## 48  19.0         6        250.0        100   3282         15.0   71      1
## 49  18.0         6        250.0         88   3139         14.5   71      1
## 50  23.0         4        122.0         86   2220         14.0   71      1
## 51  28.0         4        116.0         90   2123         14.0   71      2
## 52  30.0         4         79.0         70   2074         19.5   71      2
## 53  30.0         4         88.0         76   2065         14.5   71      2
## 54  31.0         4         71.0         65   1773         19.0   71      3
## 55  35.0         4         72.0         69   1613         18.0   71      3
## 56  27.0         4         97.0         60   1834         19.0   71      2
## 57  26.0         4         91.0         70   1955         20.5   71      1
## 58  24.0         4        113.0         95   2278         15.5   72      3
## 59  25.0         4         97.5         80   2126         17.0   72      1
## 60  23.0         4         97.0         54   2254         23.5   72      2
## 61  20.0         4        140.0         90   2408         19.5   72      1
## 62  21.0         4        122.0         86   2226         16.5   72      1
## 63  13.0         8        350.0        165   4274         12.0   72      1
## 64  14.0         8        400.0        175   4385         12.0   72      1
## 65  15.0         8        318.0        150   4135         13.5   72      1
## 66  14.0         8        351.0        153   4129         13.0   72      1
## 67  17.0         8        304.0        150   3672         11.5   72      1
## 68  11.0         8        429.0        208   4633         11.0   72      1
## 69  13.0         8        350.0        155   4502         13.5   72      1
## 70  12.0         8        350.0        160   4456         13.5   72      1
## 71  13.0         8        400.0        190   4422         12.5   72      1
## 72  19.0         3         70.0         97   2330         13.5   72      3
## 73  15.0         8        304.0        150   3892         12.5   72      1
## 74  13.0         8        307.0        130   4098         14.0   72      1
## 75  13.0         8        302.0        140   4294         16.0   72      1
## 76  14.0         8        318.0        150   4077         14.0   72      1
## 77  18.0         4        121.0        112   2933         14.5   72      2
## 78  22.0         4        121.0         76   2511         18.0   72      2
## 79  21.0         4        120.0         87   2979         19.5   72      2
## 80  26.0         4         96.0         69   2189         18.0   72      2
## 81  22.0         4        122.0         86   2395         16.0   72      1
## 82  28.0         4         97.0         92   2288         17.0   72      3
## 83  23.0         4        120.0         97   2506         14.5   72      3
## 84  28.0         4         98.0         80   2164         15.0   72      1
## 85  27.0         4         97.0         88   2100         16.5   72      3
## 86  13.0         8        350.0        175   4100         13.0   73      1
## 87  14.0         8        304.0        150   3672         11.5   73      1
## 88  13.0         8        350.0        145   3988         13.0   73      1
## 89  14.0         8        302.0        137   4042         14.5   73      1
## 90  15.0         8        318.0        150   3777         12.5   73      1
## 91  12.0         8        429.0        198   4952         11.5   73      1
## 92  13.0         8        400.0        150   4464         12.0   73      1
## 93  13.0         8        351.0        158   4363         13.0   73      1
## 94  14.0         8        318.0        150   4237         14.5   73      1
## 95  13.0         8        440.0        215   4735         11.0   73      1
## 96  12.0         8        455.0        225   4951         11.0   73      1
## 97  13.0         8        360.0        175   3821         11.0   73      1
## 98  18.0         6        225.0        105   3121         16.5   73      1
## 99  16.0         6        250.0        100   3278         18.0   73      1
## 100 18.0         6        232.0        100   2945         16.0   73      1
## 101 18.0         6        250.0         88   3021         16.5   73      1
## 102 23.0         6        198.0         95   2904         16.0   73      1
## 103 26.0         4         97.0         46   1950         21.0   73      2
## 104 11.0         8        400.0        150   4997         14.0   73      1
## 105 12.0         8        400.0        167   4906         12.5   73      1
## 106 13.0         8        360.0        170   4654         13.0   73      1
## 107 12.0         8        350.0        180   4499         12.5   73      1
## 108 18.0         6        232.0        100   2789         15.0   73      1
## 109 20.0         4         97.0         88   2279         19.0   73      3
## 110 21.0         4        140.0         72   2401         19.5   73      1
## 111 22.0         4        108.0         94   2379         16.5   73      3
## 112 18.0         3         70.0         90   2124         13.5   73      3
## 113 19.0         4        122.0         85   2310         18.5   73      1
## 114 21.0         6        155.0        107   2472         14.0   73      1
## 115 26.0         4         98.0         90   2265         15.5   73      2
## 116 15.0         8        350.0        145   4082         13.0   73      1
## 117 16.0         8        400.0        230   4278          9.5   73      1
## 118 29.0         4         68.0         49   1867         19.5   73      2
## 119 24.0         4        116.0         75   2158         15.5   73      2
## 120 20.0         4        114.0         91   2582         14.0   73      2
## 121 19.0         4        121.0        112   2868         15.5   73      2
## 122 15.0         8        318.0        150   3399         11.0   73      1
## 123 24.0         4        121.0        110   2660         14.0   73      2
## 124 20.0         6        156.0        122   2807         13.5   73      3
## 125 11.0         8        350.0        180   3664         11.0   73      1
## 126 20.0         6        198.0         95   3102         16.5   74      1
## 128 19.0         6        232.0        100   2901         16.0   74      1
## 129 15.0         6        250.0        100   3336         17.0   74      1
## 130 31.0         4         79.0         67   1950         19.0   74      3
## 131 26.0         4        122.0         80   2451         16.5   74      1
## 132 32.0         4         71.0         65   1836         21.0   74      3
## 133 25.0         4        140.0         75   2542         17.0   74      1
## 134 16.0         6        250.0        100   3781         17.0   74      1
## 135 16.0         6        258.0        110   3632         18.0   74      1
## 136 18.0         6        225.0        105   3613         16.5   74      1
## 137 16.0         8        302.0        140   4141         14.0   74      1
## 138 13.0         8        350.0        150   4699         14.5   74      1
## 139 14.0         8        318.0        150   4457         13.5   74      1
## 140 14.0         8        302.0        140   4638         16.0   74      1
## 141 14.0         8        304.0        150   4257         15.5   74      1
## 142 29.0         4         98.0         83   2219         16.5   74      2
## 143 26.0         4         79.0         67   1963         15.5   74      2
## 144 26.0         4         97.0         78   2300         14.5   74      2
## 145 31.0         4         76.0         52   1649         16.5   74      3
## 146 32.0         4         83.0         61   2003         19.0   74      3
## 147 28.0         4         90.0         75   2125         14.5   74      1
## 148 24.0         4         90.0         75   2108         15.5   74      2
## 149 26.0         4        116.0         75   2246         14.0   74      2
## 150 24.0         4        120.0         97   2489         15.0   74      3
## 151 26.0         4        108.0         93   2391         15.5   74      3
## 152 31.0         4         79.0         67   2000         16.0   74      2
## 153 19.0         6        225.0         95   3264         16.0   75      1
## 154 18.0         6        250.0        105   3459         16.0   75      1
## 155 15.0         6        250.0         72   3432         21.0   75      1
## 156 15.0         6        250.0         72   3158         19.5   75      1
## 157 16.0         8        400.0        170   4668         11.5   75      1
## 158 15.0         8        350.0        145   4440         14.0   75      1
## 159 16.0         8        318.0        150   4498         14.5   75      1
## 160 14.0         8        351.0        148   4657         13.5   75      1
## 161 17.0         6        231.0        110   3907         21.0   75      1
## 162 16.0         6        250.0        105   3897         18.5   75      1
## 163 15.0         6        258.0        110   3730         19.0   75      1
## 164 18.0         6        225.0         95   3785         19.0   75      1
## 165 21.0         6        231.0        110   3039         15.0   75      1
## 166 20.0         8        262.0        110   3221         13.5   75      1
## 167 13.0         8        302.0        129   3169         12.0   75      1
## 168 29.0         4         97.0         75   2171         16.0   75      3
## 169 23.0         4        140.0         83   2639         17.0   75      1
## 170 20.0         6        232.0        100   2914         16.0   75      1
## 171 23.0         4        140.0         78   2592         18.5   75      1
## 172 24.0         4        134.0         96   2702         13.5   75      3
## 173 25.0         4         90.0         71   2223         16.5   75      2
## 174 24.0         4        119.0         97   2545         17.0   75      3
## 175 18.0         6        171.0         97   2984         14.5   75      1
## 176 29.0         4         90.0         70   1937         14.0   75      2
## 177 19.0         6        232.0         90   3211         17.0   75      1
## 178 23.0         4        115.0         95   2694         15.0   75      2
## 179 23.0         4        120.0         88   2957         17.0   75      2
## 180 22.0         4        121.0         98   2945         14.5   75      2
## 181 25.0         4        121.0        115   2671         13.5   75      2
## 182 33.0         4         91.0         53   1795         17.5   75      3
## 183 28.0         4        107.0         86   2464         15.5   76      2
## 184 25.0         4        116.0         81   2220         16.9   76      2
## 185 25.0         4        140.0         92   2572         14.9   76      1
## 186 26.0         4         98.0         79   2255         17.7   76      1
## 187 27.0         4        101.0         83   2202         15.3   76      2
## 188 17.5         8        305.0        140   4215         13.0   76      1
## 189 16.0         8        318.0        150   4190         13.0   76      1
## 190 15.5         8        304.0        120   3962         13.9   76      1
## 191 14.5         8        351.0        152   4215         12.8   76      1
## 192 22.0         6        225.0        100   3233         15.4   76      1
## 193 22.0         6        250.0        105   3353         14.5   76      1
## 194 24.0         6        200.0         81   3012         17.6   76      1
## 195 22.5         6        232.0         90   3085         17.6   76      1
## 196 29.0         4         85.0         52   2035         22.2   76      1
## 197 24.5         4         98.0         60   2164         22.1   76      1
## 198 29.0         4         90.0         70   1937         14.2   76      2
## 199 33.0         4         91.0         53   1795         17.4   76      3
## 200 20.0         6        225.0        100   3651         17.7   76      1
## 201 18.0         6        250.0         78   3574         21.0   76      1
## 202 18.5         6        250.0        110   3645         16.2   76      1
## 203 17.5         6        258.0         95   3193         17.8   76      1
## 204 29.5         4         97.0         71   1825         12.2   76      2
## 205 32.0         4         85.0         70   1990         17.0   76      3
## 206 28.0         4         97.0         75   2155         16.4   76      3
## 207 26.5         4        140.0         72   2565         13.6   76      1
## 208 20.0         4        130.0        102   3150         15.7   76      2
## 209 13.0         8        318.0        150   3940         13.2   76      1
## 210 19.0         4        120.0         88   3270         21.9   76      2
## 211 19.0         6        156.0        108   2930         15.5   76      3
## 212 16.5         6        168.0        120   3820         16.7   76      2
## 213 16.5         8        350.0        180   4380         12.1   76      1
## 214 13.0         8        350.0        145   4055         12.0   76      1
## 215 13.0         8        302.0        130   3870         15.0   76      1
## 216 13.0         8        318.0        150   3755         14.0   76      1
## 217 31.5         4         98.0         68   2045         18.5   77      3
## 218 30.0         4        111.0         80   2155         14.8   77      1
## 219 36.0         4         79.0         58   1825         18.6   77      2
## 220 25.5         4        122.0         96   2300         15.5   77      1
## 221 33.5         4         85.0         70   1945         16.8   77      3
## 222 17.5         8        305.0        145   3880         12.5   77      1
## 223 17.0         8        260.0        110   4060         19.0   77      1
## 224 15.5         8        318.0        145   4140         13.7   77      1
## 225 15.0         8        302.0        130   4295         14.9   77      1
## 226 17.5         6        250.0        110   3520         16.4   77      1
## 227 20.5         6        231.0        105   3425         16.9   77      1
## 228 19.0         6        225.0        100   3630         17.7   77      1
## 229 18.5         6        250.0         98   3525         19.0   77      1
## 230 16.0         8        400.0        180   4220         11.1   77      1
## 231 15.5         8        350.0        170   4165         11.4   77      1
## 232 15.5         8        400.0        190   4325         12.2   77      1
## 233 16.0         8        351.0        149   4335         14.5   77      1
## 234 29.0         4         97.0         78   1940         14.5   77      2
## 235 24.5         4        151.0         88   2740         16.0   77      1
## 236 26.0         4         97.0         75   2265         18.2   77      3
## 237 25.5         4        140.0         89   2755         15.8   77      1
## 238 30.5         4         98.0         63   2051         17.0   77      1
## 239 33.5         4         98.0         83   2075         15.9   77      1
## 240 30.0         4         97.0         67   1985         16.4   77      3
## 241 30.5         4         97.0         78   2190         14.1   77      2
## 242 22.0         6        146.0         97   2815         14.5   77      3
## 243 21.5         4        121.0        110   2600         12.8   77      2
## 244 21.5         3         80.0        110   2720         13.5   77      3
## 245 43.1         4         90.0         48   1985         21.5   78      2
## 246 36.1         4         98.0         66   1800         14.4   78      1
## 247 32.8         4         78.0         52   1985         19.4   78      3
## 248 39.4         4         85.0         70   2070         18.6   78      3
## 249 36.1         4         91.0         60   1800         16.4   78      3
## 250 19.9         8        260.0        110   3365         15.5   78      1
## 251 19.4         8        318.0        140   3735         13.2   78      1
## 252 20.2         8        302.0        139   3570         12.8   78      1
## 253 19.2         6        231.0        105   3535         19.2   78      1
## 254 20.5         6        200.0         95   3155         18.2   78      1
## 255 20.2         6        200.0         85   2965         15.8   78      1
## 256 25.1         4        140.0         88   2720         15.4   78      1
## 257 20.5         6        225.0        100   3430         17.2   78      1
## 258 19.4         6        232.0         90   3210         17.2   78      1
## 259 20.6         6        231.0        105   3380         15.8   78      1
## 260 20.8         6        200.0         85   3070         16.7   78      1
## 261 18.6         6        225.0        110   3620         18.7   78      1
## 262 18.1         6        258.0        120   3410         15.1   78      1
## 263 19.2         8        305.0        145   3425         13.2   78      1
## 264 17.7         6        231.0        165   3445         13.4   78      1
## 265 18.1         8        302.0        139   3205         11.2   78      1
## 266 17.5         8        318.0        140   4080         13.7   78      1
## 267 30.0         4         98.0         68   2155         16.5   78      1
## 268 27.5         4        134.0         95   2560         14.2   78      3
## 269 27.2         4        119.0         97   2300         14.7   78      3
## 270 30.9         4        105.0         75   2230         14.5   78      1
## 271 21.1         4        134.0         95   2515         14.8   78      3
## 272 23.2         4        156.0        105   2745         16.7   78      1
## 273 23.8         4        151.0         85   2855         17.6   78      1
## 274 23.9         4        119.0         97   2405         14.9   78      3
## 275 20.3         5        131.0        103   2830         15.9   78      2
## 276 17.0         6        163.0        125   3140         13.6   78      2
## 277 21.6         4        121.0        115   2795         15.7   78      2
## 278 16.2         6        163.0        133   3410         15.8   78      2
## 279 31.5         4         89.0         71   1990         14.9   78      2
## 280 29.5         4         98.0         68   2135         16.6   78      3
## 281 21.5         6        231.0        115   3245         15.4   79      1
## 282 19.8         6        200.0         85   2990         18.2   79      1
## 283 22.3         4        140.0         88   2890         17.3   79      1
## 284 20.2         6        232.0         90   3265         18.2   79      1
## 285 20.6         6        225.0        110   3360         16.6   79      1
## 286 17.0         8        305.0        130   3840         15.4   79      1
## 287 17.6         8        302.0        129   3725         13.4   79      1
## 288 16.5         8        351.0        138   3955         13.2   79      1
## 289 18.2         8        318.0        135   3830         15.2   79      1
## 290 16.9         8        350.0        155   4360         14.9   79      1
## 291 15.5         8        351.0        142   4054         14.3   79      1
## 292 19.2         8        267.0        125   3605         15.0   79      1
## 293 18.5         8        360.0        150   3940         13.0   79      1
## 294 31.9         4         89.0         71   1925         14.0   79      2
## 295 34.1         4         86.0         65   1975         15.2   79      3
## 296 35.7         4         98.0         80   1915         14.4   79      1
## 297 27.4         4        121.0         80   2670         15.0   79      1
## 298 25.4         5        183.0         77   3530         20.1   79      2
## 299 23.0         8        350.0        125   3900         17.4   79      1
## 300 27.2         4        141.0         71   3190         24.8   79      2
## 301 23.9         8        260.0         90   3420         22.2   79      1
## 302 34.2         4        105.0         70   2200         13.2   79      1
## 303 34.5         4        105.0         70   2150         14.9   79      1
## 304 31.8         4         85.0         65   2020         19.2   79      3
## 305 37.3         4         91.0         69   2130         14.7   79      2
## 306 28.4         4        151.0         90   2670         16.0   79      1
## 307 28.8         6        173.0        115   2595         11.3   79      1
## 308 26.8         6        173.0        115   2700         12.9   79      1
## 309 33.5         4        151.0         90   2556         13.2   79      1
## 310 41.5         4         98.0         76   2144         14.7   80      2
## 311 38.1         4         89.0         60   1968         18.8   80      3
## 312 32.1         4         98.0         70   2120         15.5   80      1
## 313 37.2         4         86.0         65   2019         16.4   80      3
## 314 28.0         4        151.0         90   2678         16.5   80      1
## 315 26.4         4        140.0         88   2870         18.1   80      1
## 316 24.3         4        151.0         90   3003         20.1   80      1
## 317 19.1         6        225.0         90   3381         18.7   80      1
## 318 34.3         4         97.0         78   2188         15.8   80      2
## 319 29.8         4        134.0         90   2711         15.5   80      3
## 320 31.3         4        120.0         75   2542         17.5   80      3
## 321 37.0         4        119.0         92   2434         15.0   80      3
## 322 32.2         4        108.0         75   2265         15.2   80      3
## 323 46.6         4         86.0         65   2110         17.9   80      3
## 324 27.9         4        156.0        105   2800         14.4   80      1
## 325 40.8         4         85.0         65   2110         19.2   80      3
## 326 44.3         4         90.0         48   2085         21.7   80      2
## 327 43.4         4         90.0         48   2335         23.7   80      2
## 328 36.4         5        121.0         67   2950         19.9   80      2
## 329 30.0         4        146.0         67   3250         21.8   80      2
## 330 44.6         4         91.0         67   1850         13.8   80      3
## 332 33.8         4         97.0         67   2145         18.0   80      3
## 333 29.8         4         89.0         62   1845         15.3   80      2
## 334 32.7         6        168.0        132   2910         11.4   80      3
## 335 23.7         3         70.0        100   2420         12.5   80      3
## 336 35.0         4        122.0         88   2500         15.1   80      2
## 338 32.4         4        107.0         72   2290         17.0   80      3
## 339 27.2         4        135.0         84   2490         15.7   81      1
## 340 26.6         4        151.0         84   2635         16.4   81      1
## 341 25.8         4        156.0         92   2620         14.4   81      1
## 342 23.5         6        173.0        110   2725         12.6   81      1
## 343 30.0         4        135.0         84   2385         12.9   81      1
## 344 39.1         4         79.0         58   1755         16.9   81      3
## 345 39.0         4         86.0         64   1875         16.4   81      1
## 346 35.1         4         81.0         60   1760         16.1   81      3
## 347 32.3         4         97.0         67   2065         17.8   81      3
## 348 37.0         4         85.0         65   1975         19.4   81      3
## 349 37.7         4         89.0         62   2050         17.3   81      3
## 350 34.1         4         91.0         68   1985         16.0   81      3
## 351 34.7         4        105.0         63   2215         14.9   81      1
## 352 34.4         4         98.0         65   2045         16.2   81      1
## 353 29.9         4         98.0         65   2380         20.7   81      1
## 354 33.0         4        105.0         74   2190         14.2   81      2
## 356 33.7         4        107.0         75   2210         14.4   81      3
## 357 32.4         4        108.0         75   2350         16.8   81      3
## 358 32.9         4        119.0        100   2615         14.8   81      3
## 359 31.6         4        120.0         74   2635         18.3   81      3
## 360 28.1         4        141.0         80   3230         20.4   81      2
## 361 30.7         6        145.0         76   3160         19.6   81      2
## 362 25.4         6        168.0        116   2900         12.6   81      3
## 363 24.2         6        146.0        120   2930         13.8   81      3
## 364 22.4         6        231.0        110   3415         15.8   81      1
## 365 26.6         8        350.0        105   3725         19.0   81      1
## 366 20.2         6        200.0         88   3060         17.1   81      1
## 367 17.6         6        225.0         85   3465         16.6   81      1
## 368 28.0         4        112.0         88   2605         19.6   82      1
## 369 27.0         4        112.0         88   2640         18.6   82      1
## 370 34.0         4        112.0         88   2395         18.0   82      1
## 371 31.0         4        112.0         85   2575         16.2   82      1
## 372 29.0         4        135.0         84   2525         16.0   82      1
## 373 27.0         4        151.0         90   2735         18.0   82      1
## 374 24.0         4        140.0         92   2865         16.4   82      1
## 375 36.0         4        105.0         74   1980         15.3   82      2
## 376 37.0         4         91.0         68   2025         18.2   82      3
## 377 31.0         4         91.0         68   1970         17.6   82      3
## 378 38.0         4        105.0         63   2125         14.7   82      1
## 379 36.0         4         98.0         70   2125         17.3   82      1
## 380 36.0         4        120.0         88   2160         14.5   82      3
## 381 36.0         4        107.0         75   2205         14.5   82      3
## 382 34.0         4        108.0         70   2245         16.9   82      3
## 383 38.0         4         91.0         67   1965         15.0   82      3
## 384 32.0         4         91.0         67   1965         15.7   82      3
## 385 38.0         4         91.0         67   1995         16.2   82      3
## 386 25.0         6        181.0        110   2945         16.4   82      1
## 387 38.0         6        262.0         85   3015         17.0   82      1
## 388 26.0         4        156.0         92   2585         14.5   82      1
## 389 22.0         6        232.0        112   2835         14.7   82      1
## 390 32.0         4        144.0         96   2665         13.9   82      3
## 391 36.0         4        135.0         84   2370         13.0   82      1
## 392 27.0         4        151.0         90   2950         17.3   82      1
## 393 27.0         4        140.0         86   2790         15.6   82      1
## 394 44.0         4         97.0         52   2130         24.6   82      2
## 395 32.0         4        135.0         84   2295         11.6   82      1
## 396 28.0         4        120.0         79   2625         18.6   82      1
## 397 31.0         4        119.0         82   2720         19.4   82      1
##                                     name
## 1              chevrolet chevelle malibu
## 2                      buick skylark 320
## 3                     plymouth satellite
## 4                          amc rebel sst
## 5                            ford torino
## 6                       ford galaxie 500
## 7                       chevrolet impala
## 8                      plymouth fury iii
## 9                       pontiac catalina
## 10                    amc ambassador dpl
## 11                   dodge challenger se
## 12                    plymouth 'cuda 340
## 13                 chevrolet monte carlo
## 14               buick estate wagon (sw)
## 15                 toyota corona mark ii
## 16                       plymouth duster
## 17                            amc hornet
## 18                         ford maverick
## 19                          datsun pl510
## 20          volkswagen 1131 deluxe sedan
## 21                           peugeot 504
## 22                           audi 100 ls
## 23                              saab 99e
## 24                              bmw 2002
## 25                           amc gremlin
## 26                             ford f250
## 27                             chevy c20
## 28                            dodge d200
## 29                              hi 1200d
## 30                          datsun pl510
## 31                   chevrolet vega 2300
## 32                         toyota corona
## 34                           amc gremlin
## 35             plymouth satellite custom
## 36             chevrolet chevelle malibu
## 37                       ford torino 500
## 38                           amc matador
## 39                      chevrolet impala
## 40             pontiac catalina brougham
## 41                      ford galaxie 500
## 42                     plymouth fury iii
## 43                     dodge monaco (sw)
## 44              ford country squire (sw)
## 45                   pontiac safari (sw)
## 46            amc hornet sportabout (sw)
## 47                   chevrolet vega (sw)
## 48                      pontiac firebird
## 49                          ford mustang
## 50                    mercury capri 2000
## 51                             opel 1900
## 52                           peugeot 304
## 53                             fiat 124b
## 54                   toyota corolla 1200
## 55                           datsun 1200
## 56                  volkswagen model 111
## 57                      plymouth cricket
## 58                 toyota corona hardtop
## 59                    dodge colt hardtop
## 60                     volkswagen type 3
## 61                        chevrolet vega
## 62                   ford pinto runabout
## 63                      chevrolet impala
## 64                      pontiac catalina
## 65                     plymouth fury iii
## 66                      ford galaxie 500
## 67                    amc ambassador sst
## 68                       mercury marquis
## 69                  buick lesabre custom
## 70            oldsmobile delta 88 royale
## 71                chrysler newport royal
## 72                       mazda rx2 coupe
## 73                      amc matador (sw)
## 74      chevrolet chevelle concours (sw)
## 75                 ford gran torino (sw)
## 76        plymouth satellite custom (sw)
## 77                       volvo 145e (sw)
## 78                   volkswagen 411 (sw)
## 79                      peugeot 504 (sw)
## 80                       renault 12 (sw)
## 81                       ford pinto (sw)
## 82                       datsun 510 (sw)
## 83           toyouta corona mark ii (sw)
## 84                       dodge colt (sw)
## 85              toyota corolla 1600 (sw)
## 86                     buick century 350
## 87                           amc matador
## 88                      chevrolet malibu
## 89                      ford gran torino
## 90                  dodge coronet custom
## 91              mercury marquis brougham
## 92             chevrolet caprice classic
## 93                              ford ltd
## 94              plymouth fury gran sedan
## 95          chrysler new yorker brougham
## 96              buick electra 225 custom
## 97               amc ambassador brougham
## 98                      plymouth valiant
## 99                 chevrolet nova custom
## 100                           amc hornet
## 101                        ford maverick
## 102                      plymouth duster
## 103              volkswagen super beetle
## 104                     chevrolet impala
## 105                         ford country
## 106               plymouth custom suburb
## 107             oldsmobile vista cruiser
## 108                          amc gremlin
## 109                        toyota carina
## 110                       chevrolet vega
## 111                           datsun 610
## 112                            maxda rx3
## 113                           ford pinto
## 114                     mercury capri v6
## 115                 fiat 124 sport coupe
## 116              chevrolet monte carlo s
## 117                   pontiac grand prix
## 118                             fiat 128
## 119                           opel manta
## 120                           audi 100ls
## 121                          volvo 144ea
## 122                    dodge dart custom
## 123                            saab 99le
## 124                       toyota mark ii
## 125                     oldsmobile omega
## 126                      plymouth duster
## 128                           amc hornet
## 129                       chevrolet nova
## 130                          datsun b210
## 131                           ford pinto
## 132                  toyota corolla 1200
## 133                       chevrolet vega
## 134    chevrolet chevelle malibu classic
## 135                          amc matador
## 136           plymouth satellite sebring
## 137                     ford gran torino
## 138             buick century luxus (sw)
## 139            dodge coronet custom (sw)
## 140                ford gran torino (sw)
## 141                     amc matador (sw)
## 142                             audi fox
## 143                    volkswagen dasher
## 144                           opel manta
## 145                        toyota corona
## 146                           datsun 710
## 147                           dodge colt
## 148                             fiat 128
## 149                          fiat 124 tc
## 150                          honda civic
## 151                               subaru
## 152                            fiat x1.9
## 153              plymouth valiant custom
## 154                       chevrolet nova
## 155                      mercury monarch
## 156                        ford maverick
## 157                     pontiac catalina
## 158                    chevrolet bel air
## 159                  plymouth grand fury
## 160                             ford ltd
## 161                        buick century
## 162            chevroelt chevelle malibu
## 163                          amc matador
## 164                        plymouth fury
## 165                        buick skyhawk
## 166                  chevrolet monza 2+2
## 167                      ford mustang ii
## 168                       toyota corolla
## 169                           ford pinto
## 170                          amc gremlin
## 171                        pontiac astro
## 172                        toyota corona
## 173                    volkswagen dasher
## 174                           datsun 710
## 175                           ford pinto
## 176                    volkswagen rabbit
## 177                            amc pacer
## 178                           audi 100ls
## 179                          peugeot 504
## 180                          volvo 244dl
## 181                            saab 99le
## 182                     honda civic cvcc
## 183                             fiat 131
## 184                            opel 1900
## 185                             capri ii
## 186                           dodge colt
## 187                         renault 12tl
## 188    chevrolet chevelle malibu classic
## 189               dodge coronet brougham
## 190                          amc matador
## 191                     ford gran torino
## 192                     plymouth valiant
## 193                       chevrolet nova
## 194                        ford maverick
## 195                           amc hornet
## 196                   chevrolet chevette
## 197                      chevrolet woody
## 198                            vw rabbit
## 199                          honda civic
## 200                       dodge aspen se
## 201                    ford granada ghia
## 202                   pontiac ventura sj
## 203                        amc pacer d/l
## 204                    volkswagen rabbit
## 205                         datsun b-210
## 206                       toyota corolla
## 207                           ford pinto
## 208                            volvo 245
## 209           plymouth volare premier v8
## 210                          peugeot 504
## 211                       toyota mark ii
## 212                   mercedes-benz 280s
## 213                     cadillac seville
## 214                            chevy c10
## 215                            ford f108
## 216                           dodge d100
## 217                    honda accord cvcc
## 218              buick opel isuzu deluxe
## 219                        renault 5 gtl
## 220                    plymouth arrow gs
## 221                datsun f-10 hatchback
## 222            chevrolet caprice classic
## 223           oldsmobile cutlass supreme
## 224                dodge monaco brougham
## 225              mercury cougar brougham
## 226                   chevrolet concours
## 227                        buick skylark
## 228               plymouth volare custom
## 229                         ford granada
## 230                pontiac grand prix lj
## 231         chevrolet monte carlo landau
## 232                     chrysler cordoba
## 233                     ford thunderbird
## 234             volkswagen rabbit custom
## 235                pontiac sunbird coupe
## 236              toyota corolla liftback
## 237                  ford mustang ii 2+2
## 238                   chevrolet chevette
## 239                       dodge colt m/m
## 240                            subaru dl
## 241                    volkswagen dasher
## 242                           datsun 810
## 243                             bmw 320i
## 244                           mazda rx-4
## 245      volkswagen rabbit custom diesel
## 246                          ford fiesta
## 247                     mazda glc deluxe
## 248                       datsun b210 gx
## 249                     honda civic cvcc
## 250    oldsmobile cutlass salon brougham
## 251                       dodge diplomat
## 252                 mercury monarch ghia
## 253                   pontiac phoenix lj
## 254                     chevrolet malibu
## 255                 ford fairmont (auto)
## 256                  ford fairmont (man)
## 257                      plymouth volare
## 258                          amc concord
## 259                buick century special
## 260                       mercury zephyr
## 261                          dodge aspen
## 262                      amc concord d/l
## 263         chevrolet monte carlo landau
## 264      buick regal sport coupe (turbo)
## 265                          ford futura
## 266                      dodge magnum xe
## 267                   chevrolet chevette
## 268                        toyota corona
## 269                           datsun 510
## 270                           dodge omni
## 271            toyota celica gt liftback
## 272                     plymouth sapporo
## 273               oldsmobile starfire sx
## 274                        datsun 200-sx
## 275                            audi 5000
## 276                          volvo 264gl
## 277                           saab 99gle
## 278                        peugeot 604sl
## 279                  volkswagen scirocco
## 280                      honda accord lx
## 281                    pontiac lemans v6
## 282                     mercury zephyr 6
## 283                      ford fairmont 4
## 284                     amc concord dl 6
## 285                        dodge aspen 6
## 286            chevrolet caprice classic
## 287                      ford ltd landau
## 288                mercury grand marquis
## 289                      dodge st. regis
## 290              buick estate wagon (sw)
## 291             ford country squire (sw)
## 292        chevrolet malibu classic (sw)
## 293 chrysler lebaron town @ country (sw)
## 294                     vw rabbit custom
## 295                     maxda glc deluxe
## 296          dodge colt hatchback custom
## 297                        amc spirit dl
## 298                   mercedes benz 300d
## 299                    cadillac eldorado
## 300                          peugeot 504
## 301    oldsmobile cutlass salon brougham
## 302                     plymouth horizon
## 303                 plymouth horizon tc3
## 304                           datsun 210
## 305                   fiat strada custom
## 306                buick skylark limited
## 307                   chevrolet citation
## 308            oldsmobile omega brougham
## 309                      pontiac phoenix
## 310                            vw rabbit
## 311                toyota corolla tercel
## 312                   chevrolet chevette
## 313                           datsun 310
## 314                   chevrolet citation
## 315                        ford fairmont
## 316                          amc concord
## 317                          dodge aspen
## 318                            audi 4000
## 319               toyota corona liftback
## 320                            mazda 626
## 321                 datsun 510 hatchback
## 322                       toyota corolla
## 323                            mazda glc
## 324                           dodge colt
## 325                           datsun 210
## 326                 vw rabbit c (diesel)
## 327                   vw dasher (diesel)
## 328                  audi 5000s (diesel)
## 329                   mercedes-benz 240d
## 330                  honda civic 1500 gl
## 332                            subaru dl
## 333                     vokswagen rabbit
## 334                        datsun 280-zx
## 335                        mazda rx-7 gs
## 336                    triumph tr7 coupe
## 338                         honda accord
## 339                     plymouth reliant
## 340                        buick skylark
## 341               dodge aries wagon (sw)
## 342                   chevrolet citation
## 343                     plymouth reliant
## 344                       toyota starlet
## 345                       plymouth champ
## 346                     honda civic 1300
## 347                               subaru
## 348                       datsun 210 mpg
## 349                        toyota tercel
## 350                          mazda glc 4
## 351                   plymouth horizon 4
## 352                       ford escort 4w
## 353                       ford escort 2h
## 354                     volkswagen jetta
## 356                        honda prelude
## 357                       toyota corolla
## 358                         datsun 200sx
## 359                            mazda 626
## 360            peugeot 505s turbo diesel
## 361                         volvo diesel
## 362                      toyota cressida
## 363                    datsun 810 maxima
## 364                        buick century
## 365                oldsmobile cutlass ls
## 366                      ford granada gl
## 367               chrysler lebaron salon
## 368                   chevrolet cavalier
## 369             chevrolet cavalier wagon
## 370            chevrolet cavalier 2-door
## 371           pontiac j2000 se hatchback
## 372                       dodge aries se
## 373                      pontiac phoenix
## 374                 ford fairmont futura
## 375                  volkswagen rabbit l
## 376                   mazda glc custom l
## 377                     mazda glc custom
## 378               plymouth horizon miser
## 379                       mercury lynx l
## 380                     nissan stanza xe
## 381                         honda accord
## 382                       toyota corolla
## 383                          honda civic
## 384                   honda civic (auto)
## 385                        datsun 310 gx
## 386                buick century limited
## 387    oldsmobile cutlass ciera (diesel)
## 388           chrysler lebaron medallion
## 389                       ford granada l
## 390                     toyota celica gt
## 391                    dodge charger 2.2
## 392                     chevrolet camaro
## 393                      ford mustang gl
## 394                            vw pickup
## 395                        dodge rampage
## 396                          ford ranger
## 397                           chevy s-10
mod<-lm(auto$mpg~auto$horsepower)

summary(mod)
## 
## Call:
## lm(formula = auto$mpg ~ auto$horsepower)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13.5710  -3.2592  -0.3435   2.7630  16.9240 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     39.935861   0.717499   55.66   <2e-16 ***
## auto$horsepower -0.157845   0.006446  -24.49   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.906 on 390 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.6059, Adjusted R-squared:  0.6049 
## F-statistic: 599.7 on 1 and 390 DF,  p-value: < 2.2e-16
##  – (i) Is there a relationship between the predictor and the response?
# Yes.

##  – (ii) How strong is the relationship between the predictor and the response?
# Strong

##  – (iii) Is the relationship between the predictor and the response positive or negative?
# negative
##  – (iv) What is the predicted mpg associated with a horsepower of 98? What are the associated 95% confidence and prediction intervals?
attach(auto)
newdata<-data.frame(horsepower=c(98))
predict(mod, newdata,
        interval="predict")
## Warning: 'newdata' had 1 row but variables found have 397 rows
##           fit        lwr      upr
## 1   19.416046  9.7532948 29.07880
## 2   13.891480  4.2037318 23.57923
## 3   16.259151  6.5845976 25.93370
## 4   16.259151  6.5845976 25.93370
## 5   17.837598  8.1697749 27.50542
## 6    8.682604 -1.0471901 18.41240
## 7    5.210020 -4.5576558 14.97770
## 8    5.999243 -3.7591362 15.75762
## 9    4.420796 -5.3565771 14.19817
## 10   9.945362  0.2273963 19.66333
## 11  13.102256  3.4092855 22.79523
## 12  14.680704  4.9977664 24.36364
## 13  16.259151  6.5845976 25.93370
## 14   4.420796 -5.3565771 14.19817
## 15  24.940611 15.2825327 34.59869
## 16  24.940611 15.2825327 34.59869
## 17  24.624922 14.9671249 34.28272
## 18  26.519059 16.8585745 36.17954
## 19  26.045524 16.3859365 35.70511
## 20  32.675003 22.9892883 42.36072
## 21  26.203369 16.5434991 35.86324
## 22  25.729835 16.0707614 35.38891
## 23  24.940611 15.2825327 34.59869
## 24  22.099406 12.4414680 31.75734
## 25  25.729835 16.0707614 35.38891
## 26   5.999243 -3.7591362 15.75762
## 27   8.366914 -1.3659995 18.09983
## 28   6.788467 -2.9610196 16.53795
## 29   9.471827 -0.2504514 19.19411
## 30  26.045524 16.3859365 35.70511
## 31  25.729835 16.0707614 35.38891
## 32  24.940611 15.2825327 34.59869
## 33         NA         NA       NA
## 34  24.151388 14.4938885 33.80889
## 35  23.362164 13.7048286 33.01950
## 36  24.151388 14.4938885 33.80889
## 37  26.045524 16.3859365 35.70511
## 38  24.151388 14.4938885 33.80889
## 39  13.891480  4.2037318 23.57923
## 40  12.313033  2.6144281 22.01164
## 41  15.785617  6.1087217 25.46251
## 42  16.259151  6.5845976 25.93370
## 43  11.523809  1.8191602 21.22846
## 44  13.102256  3.4092855 22.79523
## 45  12.313033  2.6144281 22.01164
## 46  22.572940 12.9153529 32.23053
## 47  28.571040 18.9049457 38.23713
## 48  24.151388 14.4938885 33.80889
## 49  26.045524 16.3859365 35.70511
## 50  26.361214 16.7010451 36.02138
## 51  25.729835 16.0707614 35.38891
## 52  28.886730 19.2195232 38.55394
## 53  27.939661 18.2755918 37.60373
## 54  29.675953 20.0056767 39.34623
## 55  29.044574 19.3767870 38.71236
## 56  30.465177 20.7914163 40.13894
## 57  28.886730 19.2195232 38.55394
## 58  24.940611 15.2825327 34.59869
## 59  27.308282 17.6459724 36.97059
## 60  31.412245 21.7337578 41.09073
## 61  25.729835 16.0707614 35.38891
## 62  26.361214 16.7010451 36.02138
## 63  13.891480  4.2037318 23.57923
## 64  12.313033  2.6144281 22.01164
## 65  16.259151  6.5845976 25.93370
## 66  15.785617  6.1087217 25.46251
## 67  16.259151  6.5845976 25.93370
## 68   7.104156 -2.6418860 16.85020
## 69  15.469927  5.7913884 25.14847
## 70  14.680704  4.9977664 24.36364
## 71   9.945362  0.2273963 19.66333
## 72  24.624922 14.9671249 34.28272
## 73  16.259151  6.5845976 25.93370
## 74  19.416046  9.7532948 29.07880
## 75  17.837598  8.1697749 27.50542
## 76  16.259151  6.5845976 25.93370
## 77  22.257251 12.5994463 31.91506
## 78  27.939661 18.2755918 37.60373
## 79  26.203369 16.5434991 35.86324
## 80  29.044574 19.3767870 38.71236
## 81  26.361214 16.7010451 36.02138
## 82  25.414146 15.7555198 35.07277
## 83  24.624922 14.9671249 34.28272
## 84  27.308282 17.6459724 36.97059
## 85  26.045524 16.3859365 35.70511
## 86  12.313033  2.6144281 22.01164
## 87  16.259151  6.5845976 25.93370
## 88  17.048375  7.3773932 26.71936
## 89  18.311133  8.6450050 27.97726
## 90  16.259151  6.5845976 25.93370
## 91   8.682604 -1.0471901 18.41240
## 92  16.259151  6.5845976 25.93370
## 93  14.996393  5.3152647 24.67752
## 94  16.259151  6.5845976 25.93370
## 95   5.999243 -3.7591362 15.75762
## 96   4.420796 -5.3565771 14.19817
## 97  12.313033  2.6144281 22.01164
## 98  23.362164 13.7048286 33.01950
## 99  24.151388 14.4938885 33.80889
## 100 24.151388 14.4938885 33.80889
## 101 26.045524 16.3859365 35.70511
## 102 24.940611 15.2825327 34.59869
## 103 32.675003 22.9892883 42.36072
## 104 16.259151  6.5845976 25.93370
## 105 13.575791  3.8860027 23.26558
## 106 13.102256  3.4092855 22.79523
## 107 11.523809  1.8191602 21.22846
## 108 24.151388 14.4938885 33.80889
## 109 26.045524 16.3859365 35.70511
## 110 28.571040 18.9049457 38.23713
## 111 25.098456 15.4402117 34.75670
## 112 25.729835 16.0707614 35.38891
## 113 26.519059 16.8585745 36.17954
## 114 23.046475 13.3890882 32.70386
## 115 25.729835 16.0707614 35.38891
## 116 17.048375  7.3773932 26.71936
## 117  3.631572 -6.1558990 13.41904
## 118 32.201469 22.5185881 41.88435
## 119 28.097506 18.4329552 37.76206
## 120 25.571990 15.9131489 35.23083
## 121 22.257251 12.5994463 31.91506
## 122 16.259151  6.5845976 25.93370
## 123 22.572940 12.9153529 32.23053
## 124 20.678804 11.0189156 30.33869
## 125 11.523809  1.8191602 21.22846
## 126 24.940611 15.2825327 34.59869
## 127        NA         NA       NA
## 128 24.151388 14.4938885 33.80889
## 129 24.151388 14.4938885 33.80889
## 130 29.360264 19.6912650 39.02926
## 131 27.308282 17.6459724 36.97059
## 132 29.675953 20.0056767 39.34623
## 133 28.097506 18.4329552 37.76206
## 134 24.151388 14.4938885 33.80889
## 135 22.572940 12.9153529 32.23053
## 136 23.362164 13.7048286 33.01950
## 137 17.837598  8.1697749 27.50542
## 138 16.259151  6.5845976 25.93370
## 139 16.259151  6.5845976 25.93370
## 140 17.837598  8.1697749 27.50542
## 141 16.259151  6.5845976 25.93370
## 142 26.834748 17.1735835 36.49591
## 143 29.360264 19.6912650 39.02926
## 144 27.623972 17.9608153 37.28713
## 145 31.727935 22.0477395 41.40813
## 146 30.307332 20.6343015 39.98036
## 147 28.097506 18.4329552 37.76206
## 148 28.097506 18.4329552 37.76206
## 149 28.097506 18.4329552 37.76206
## 150 24.624922 14.9671249 34.28272
## 151 25.256301 15.5978741 34.91473
## 152 29.360264 19.6912650 39.02926
## 153 24.940611 15.2825327 34.59869
## 154 23.362164 13.7048286 33.01950
## 155 28.571040 18.9049457 38.23713
## 156 28.571040 18.9049457 38.23713
## 157 13.102256  3.4092855 22.79523
## 158 17.048375  7.3773932 26.71936
## 159 16.259151  6.5845976 25.93370
## 160 16.574840  6.9017655 26.24792
## 161 22.572940 12.9153529 32.23053
## 162 23.362164 13.7048286 33.01950
## 163 22.572940 12.9153529 32.23053
## 164 24.940611 15.2825327 34.59869
## 165 22.572940 12.9153529 32.23053
## 166 22.572940 12.9153529 32.23053
## 167 19.573890  9.9115555 29.23623
## 168 28.097506 18.4329552 37.76206
## 169 26.834748 17.1735835 36.49591
## 170 24.151388 14.4938885 33.80889
## 171 27.623972 17.9608153 37.28713
## 172 24.782767 15.1248371 34.44070
## 173 28.728885 19.0622427 38.39553
## 174 24.624922 14.9671249 34.28272
## 175 24.624922 14.9671249 34.28272
## 176 28.886730 19.2195232 38.55394
## 177 25.729835 16.0707614 35.38891
## 178 24.940611 15.2825327 34.59869
## 179 26.045524 16.3859365 35.70511
## 180 24.467077 14.8093961 34.12476
## 181 21.783717 12.1254616 31.44197
## 182 31.570090 21.8907569 41.24942
## 183 26.361214 16.7010451 36.02138
## 184 27.150438 17.4885260 36.81235
## 185 25.414146 15.7555198 35.07277
## 186 27.466127 17.8034021 37.12885
## 187 26.834748 17.1735835 36.49591
## 188 17.837598  8.1697749 27.50542
## 189 16.259151  6.5845976 25.93370
## 190 20.994493 11.3351547 30.65383
## 191 15.943462  6.2673635 25.61956
## 192 24.151388 14.4938885 33.80889
## 193 23.362164 13.7048286 33.01950
## 194 27.150438 17.4885260 36.81235
## 195 25.729835 16.0707614 35.38891
## 196 31.727935 22.0477395 41.40813
## 197 30.465177 20.7914163 40.13894
## 198 28.886730 19.2195232 38.55394
## 199 31.570090 21.8907569 41.24942
## 200 24.151388 14.4938885 33.80889
## 201 27.623972 17.9608153 37.28713
## 202 22.572940 12.9153529 32.23053
## 203 24.940611 15.2825327 34.59869
## 204 28.728885 19.0622427 38.39553
## 205 28.886730 19.2195232 38.55394
## 206 28.097506 18.4329552 37.76206
## 207 28.571040 18.9049457 38.23713
## 208 23.835698 14.1783144 33.49308
## 209 16.259151  6.5845976 25.93370
## 210 26.045524 16.3859365 35.70511
## 211 22.888630 13.2311931 32.54607
## 212 20.994493 11.3351547 30.65383
## 213 11.523809  1.8191602 21.22846
## 214 17.048375  7.3773932 26.71936
## 215 19.416046  9.7532948 29.07880
## 216 16.259151  6.5845976 25.93370
## 217 29.202419 19.5340343 38.87080
## 218 27.308282 17.6459724 36.97059
## 219 30.780866 21.1055963 40.45614
## 220 24.782767 15.1248371 34.44070
## 221 28.886730 19.2195232 38.55394
## 222 17.048375  7.3773932 26.71936
## 223 22.572940 12.9153529 32.23053
## 224 17.048375  7.3773932 26.71936
## 225 19.416046  9.7532948 29.07880
## 226 22.572940 12.9153529 32.23053
## 227 23.362164 13.7048286 33.01950
## 228 24.151388 14.4938885 33.80889
## 229 24.467077 14.8093961 34.12476
## 230 11.523809  1.8191602 21.22846
## 231 13.102256  3.4092855 22.79523
## 232  9.945362  0.2273963 19.66333
## 233 16.416996  6.7431898 26.09080
## 234 27.623972 17.9608153 37.28713
## 235 26.045524 16.3859365 35.70511
## 236 28.097506 18.4329552 37.76206
## 237 25.887680 16.2283572 35.54700
## 238 29.991643 20.3200222 39.66326
## 239 26.834748 17.1735835 36.49591
## 240 29.360264 19.6912650 39.02926
## 241 27.623972 17.9608153 37.28713
## 242 24.624922 14.9671249 34.28272
## 243 22.572940 12.9153529 32.23053
## 244 22.572940 12.9153529 32.23053
## 245 32.359314 22.6755047 42.04312
## 246 29.518109 19.8484792 39.18774
## 247 31.727935 22.0477395 41.40813
## 248 28.886730 19.2195232 38.55394
## 249 30.465177 20.7914163 40.13894
## 250 22.572940 12.9153529 32.23053
## 251 17.837598  8.1697749 27.50542
## 252 17.995443  8.3282015 27.66268
## 253 23.362164 13.7048286 33.01950
## 254 24.940611 15.2825327 34.59869
## 255 26.519059 16.8585745 36.17954
## 256 26.045524 16.3859365 35.70511
## 257 24.151388 14.4938885 33.80889
## 258 25.729835 16.0707614 35.38891
## 259 23.362164 13.7048286 33.01950
## 260 26.519059 16.8585745 36.17954
## 261 22.572940 12.9153529 32.23053
## 262 20.994493 11.3351547 30.65383
## 263 17.048375  7.3773932 26.71936
## 264 13.891480  4.2037318 23.57923
## 265 17.995443  8.3282015 27.66268
## 266 17.837598  8.1697749 27.50542
## 267 29.202419 19.5340343 38.87080
## 268 24.940611 15.2825327 34.59869
## 269 24.624922 14.9671249 34.28272
## 270 28.097506 18.4329552 37.76206
## 271 24.940611 15.2825327 34.59869
## 272 23.362164 13.7048286 33.01950
## 273 26.519059 16.8585745 36.17954
## 274 24.624922 14.9671249 34.28272
## 275 23.677853 14.0205024 33.33520
## 276 20.205269 10.5444324 29.86611
## 277 21.783717 12.1254616 31.44197
## 278 18.942511  9.2784130 28.60661
## 279 28.728885 19.0622427 38.39553
## 280 29.202419 19.5340343 38.87080
## 281 21.783717 12.1254616 31.44197
## 282 26.519059 16.8585745 36.17954
## 283 26.045524 16.3859365 35.70511
## 284 25.729835 16.0707614 35.38891
## 285 22.572940 12.9153529 32.23053
## 286 19.416046  9.7532948 29.07880
## 287 19.573890  9.9115555 29.23623
## 288 18.153288  8.4866115 27.81996
## 289 18.626822  8.9617422 28.29190
## 290 15.469927  5.7913884 25.14847
## 291 17.521909  7.8528719 27.19095
## 292 20.205269 10.5444324 29.86611
## 293 16.259151  6.5845976 25.93370
## 294 28.728885 19.0622427 38.39553
## 295 29.675953 20.0056767 39.34623
## 296 27.308282 17.6459724 36.97059
## 297 27.308282 17.6459724 36.97059
## 298 27.781817 18.1182118 37.44542
## 299 20.205269 10.5444324 29.86611
## 300 28.728885 19.0622427 38.39553
## 301 25.729835 16.0707614 35.38891
## 302 28.886730 19.2195232 38.55394
## 303 28.886730 19.2195232 38.55394
## 304 29.675953 20.0056767 39.34623
## 305 29.044574 19.3767870 38.71236
## 306 25.729835 16.0707614 35.38891
## 307 21.783717 12.1254616 31.44197
## 308 21.783717 12.1254616 31.44197
## 309 25.729835 16.0707614 35.38891
## 310 27.939661 18.2755918 37.60373
## 311 30.465177 20.7914163 40.13894
## 312 28.886730 19.2195232 38.55394
## 313 29.675953 20.0056767 39.34623
## 314 25.729835 16.0707614 35.38891
## 315 26.045524 16.3859365 35.70511
## 316 25.729835 16.0707614 35.38891
## 317 25.729835 16.0707614 35.38891
## 318 27.623972 17.9608153 37.28713
## 319 25.729835 16.0707614 35.38891
## 320 28.097506 18.4329552 37.76206
## 321 25.414146 15.7555198 35.07277
## 322 28.097506 18.4329552 37.76206
## 323 29.675953 20.0056767 39.34623
## 324 23.362164 13.7048286 33.01950
## 325 29.675953 20.0056767 39.34623
## 326 32.359314 22.6755047 42.04312
## 327 32.359314 22.6755047 42.04312
## 328 29.360264 19.6912650 39.02926
## 329 29.360264 19.6912650 39.02926
## 330 29.360264 19.6912650 39.02926
## 331        NA         NA       NA
## 332 29.360264 19.6912650 39.02926
## 333 30.149488 20.4771701 39.82180
## 334 19.100356  9.4367235 28.76399
## 335 24.151388 14.4938885 33.80889
## 336 26.045524 16.3859365 35.70511
## 337        NA         NA       NA
## 338 28.571040 18.9049457 38.23713
## 339 26.676903 17.0160873 36.33772
## 340 26.676903 17.0160873 36.33772
## 341 25.414146 15.7555198 35.07277
## 342 22.572940 12.9153529 32.23053
## 343 26.676903 17.0160873 36.33772
## 344 30.780866 21.1055963 40.45614
## 345 29.833798 20.1628578 39.50474
## 346 30.465177 20.7914163 40.13894
## 347 29.360264 19.6912650 39.02926
## 348 29.675953 20.0056767 39.34623
## 349 30.149488 20.4771701 39.82180
## 350 29.202419 19.5340343 38.87080
## 351 29.991643 20.3200222 39.66326
## 352 29.675953 20.0056767 39.34623
## 353 29.675953 20.0056767 39.34623
## 354 28.255351 18.5903019 37.92040
## 355        NA         NA       NA
## 356 28.097506 18.4329552 37.76206
## 357 28.097506 18.4329552 37.76206
## 358 24.151388 14.4938885 33.80889
## 359 28.255351 18.5903019 37.92040
## 360 27.308282 17.6459724 36.97059
## 361 27.939661 18.2755918 37.60373
## 362 21.625872 11.9674335 31.28431
## 363 20.994493 11.3351547 30.65383
## 364 22.572940 12.9153529 32.23053
## 365 23.362164 13.7048286 33.01950
## 366 26.045524 16.3859365 35.70511
## 367 26.519059 16.8585745 36.17954
## 368 26.045524 16.3859365 35.70511
## 369 26.045524 16.3859365 35.70511
## 370 26.045524 16.3859365 35.70511
## 371 26.519059 16.8585745 36.17954
## 372 26.676903 17.0160873 36.33772
## 373 25.729835 16.0707614 35.38891
## 374 25.414146 15.7555198 35.07277
## 375 28.255351 18.5903019 37.92040
## 376 29.202419 19.5340343 38.87080
## 377 29.202419 19.5340343 38.87080
## 378 29.991643 20.3200222 39.66326
## 379 28.886730 19.2195232 38.55394
## 380 26.045524 16.3859365 35.70511
## 381 28.097506 18.4329552 37.76206
## 382 28.886730 19.2195232 38.55394
## 383 29.360264 19.6912650 39.02926
## 384 29.360264 19.6912650 39.02926
## 385 29.360264 19.6912650 39.02926
## 386 22.572940 12.9153529 32.23053
## 387 26.519059 16.8585745 36.17954
## 388 25.414146 15.7555198 35.07277
## 389 22.257251 12.5994463 31.91506
## 390 24.782767 15.1248371 34.44070
## 391 26.676903 17.0160873 36.33772
## 392 25.729835 16.0707614 35.38891
## 393 26.361214 16.7010451 36.02138
## 394 31.727935 22.0477395 41.40813
## 395 26.676903 17.0160873 36.33772
## 396 27.466127 17.8034021 37.12885
## 397 26.992593 17.3310631 36.65412
# Horsepower of 98 prediction --> fit       lwr       upr
#                               125.37566  77.7200072 173.03131
predict(mod, newdata,
        interval="confidence")
## Warning: 'newdata' had 1 row but variables found have 397 rows
##           fit       lwr       upr
## 1   19.416046 18.831250 20.000841
## 2   13.891480 12.982802 14.800158
## 3   16.259151 15.504025 17.014277
## 4   16.259151 15.504025 17.014277
## 5   17.837598 17.174242 18.500955
## 6    8.682604  7.401151  9.964056
## 7    5.210020  3.667064  6.752976
## 8    5.999243  4.516273  7.482214
## 9    4.420796  2.817595  6.023998
## 10   9.945362  8.757051 11.133672
## 11  13.102256 12.139493 14.065020
## 12  14.680704 13.824838 15.536569
## 13  16.259151 15.504025 17.014277
## 14   4.420796  2.817595  6.023998
## 15  24.940611 24.438901 25.442321
## 16  24.940611 24.438901 25.442321
## 17  24.624922 24.128663 25.121180
## 18  26.519059 25.972996 27.065122
## 19  26.045524 25.515552 26.575497
## 20  32.675003 31.788265 33.561742
## 21  26.203369 25.668280 26.738459
## 22  25.729835 25.209322 26.250348
## 23  24.940611 24.438901 25.442321
## 24  22.099406 21.600408 22.598404
## 25  25.729835 25.209322 26.250348
## 26   5.999243  4.516273  7.482214
## 27   8.366914  7.061985  9.671844
## 28   6.788467  5.365189  8.211745
## 29   9.471827  8.248742 10.694913
## 30  26.045524 25.515552 26.575497
## 31  25.729835 25.209322 26.250348
## 32  24.940611 24.438901 25.442321
## 33         NA        NA        NA
## 34  24.151388 23.660958 24.641817
## 35  23.362164 22.874970 23.849358
## 36  24.151388 23.660958 24.641817
## 37  26.045524 25.515552 26.575497
## 38  24.151388 23.660958 24.641817
## 39  13.891480 12.982802 14.800158
## 40  12.313033 11.295112 13.330953
## 41  15.785617 15.001060 16.570174
## 42  16.259151 15.504025 17.014277
## 43  11.523809 10.449826 12.597792
## 44  13.102256 12.139493 14.065020
## 45  12.313033 11.295112 13.330953
## 46  22.572940 22.080777 23.065104
## 47  28.571040 27.933378 29.208703
## 48  24.151388 23.660958 24.641817
## 49  26.045524 25.515552 26.575497
## 50  26.361214 25.820758 26.901669
## 51  25.729835 25.209322 26.250348
## 52  28.886730 28.232427 29.541033
## 53  27.939661 27.333469 28.545854
## 54  29.675953 28.977756 30.374151
## 55  29.044574 28.381744 29.707404
## 56  30.465177 29.720276 31.210078
## 57  28.886730 28.232427 29.541033
## 58  24.940611 24.438901 25.442321
## 59  27.308282 26.730818 27.885746
## 60  31.412245 30.608285 32.216206
## 61  25.729835 25.209322 26.250348
## 62  26.361214 25.820758 26.901669
## 63  13.891480 12.982802 14.800158
## 64  12.313033 11.295112 13.330953
## 65  16.259151 15.504025 17.014277
## 66  15.785617 15.001060 16.570174
## 67  16.259151 15.504025 17.014277
## 68   7.104156  5.704666  8.503647
## 69  15.469927 14.665349 16.274505
## 70  14.680704 13.824838 15.536569
## 71   9.945362  8.757051 11.133672
## 72  24.624922 24.128663 25.121180
## 73  16.259151 15.504025 17.014277
## 74  19.416046 18.831250 20.000841
## 75  17.837598 17.174242 18.500955
## 76  16.259151 15.504025 17.014277
## 77  22.257251 21.760844 22.753658
## 78  27.939661 27.333469 28.545854
## 79  26.203369 25.668280 26.738459
## 80  29.044574 28.381744 29.707404
## 81  26.361214 25.820758 26.901669
## 82  25.414146 24.902011 25.926280
## 83  24.624922 24.128663 25.121180
## 84  27.308282 26.730818 27.885746
## 85  26.045524 25.515552 26.575497
## 86  12.313033 11.295112 13.330953
## 87  16.259151 15.504025 17.014277
## 88  17.048375 16.340481 17.756268
## 89  18.311133 17.672969 18.949296
## 90  16.259151 15.504025 17.014277
## 91   8.682604  7.401151  9.964056
## 92  16.259151 15.504025 17.014277
## 93  14.996393 14.161242 15.831545
## 94  16.259151 15.504025 17.014277
## 95   5.999243  4.516273  7.482214
## 96   4.420796  2.817595  6.023998
## 97  12.313033 11.295112 13.330953
## 98  23.362164 22.874970 23.849358
## 99  24.151388 23.660958 24.641817
## 100 24.151388 23.660958 24.641817
## 101 26.045524 25.515552 26.575497
## 102 24.940611 24.438901 25.442321
## 103 32.675003 31.788265 33.561742
## 104 16.259151 15.504025 17.014277
## 105 13.575791 12.645619 14.505962
## 106 13.102256 12.139493 14.065020
## 107 11.523809 10.449826 12.597792
## 108 24.151388 23.660958 24.641817
## 109 26.045524 25.515552 26.575497
## 110 28.571040 27.933378 29.208703
## 111 25.098456 24.593565 25.603347
## 112 25.729835 25.209322 26.250348
## 113 26.519059 25.972996 27.065122
## 114 23.046475 22.558272 23.534677
## 115 25.729835 25.209322 26.250348
## 116 17.048375 16.340481 17.756268
## 117  3.631572  1.967894  5.295251
## 118 32.201469 31.346241 33.056697
## 119 28.097506 27.483687 28.711325
## 120 25.571990 25.055805 26.088176
## 121 22.257251 21.760844 22.753658
## 122 16.259151 15.504025 17.014277
## 123 22.572940 22.080777 23.065104
## 124 20.678804 20.143392 21.214215
## 125 11.523809 10.449826 12.597792
## 126 24.940611 24.438901 25.442321
## 127        NA        NA        NA
## 128 24.151388 23.660958 24.641817
## 129 24.151388 23.660958 24.641817
## 130 29.360264 28.679992 30.040536
## 131 27.308282 26.730818 27.885746
## 132 29.675953 28.977756 30.374151
## 133 28.097506 27.483687 28.711325
## 134 24.151388 23.660958 24.641817
## 135 22.572940 22.080777 23.065104
## 136 23.362164 22.874970 23.849358
## 137 17.837598 17.174242 18.500955
## 138 16.259151 15.504025 17.014277
## 139 16.259151 15.504025 17.014277
## 140 17.837598 17.174242 18.500955
## 141 16.259151 15.504025 17.014277
## 142 26.834748 26.276776 27.392720
## 143 29.360264 28.679992 30.040536
## 144 27.623972 27.032512 28.215432
## 145 31.727935 30.903669 32.552201
## 146 30.307332 29.571971 31.042693
## 147 28.097506 27.483687 28.711325
## 148 28.097506 27.483687 28.711325
## 149 28.097506 27.483687 28.711325
## 150 24.624922 24.128663 25.121180
## 151 25.256301 24.747933 25.764669
## 152 29.360264 28.679992 30.040536
## 153 24.940611 24.438901 25.442321
## 154 23.362164 22.874970 23.849358
## 155 28.571040 27.933378 29.208703
## 156 28.571040 27.933378 29.208703
## 157 13.102256 12.139493 14.065020
## 158 17.048375 16.340481 17.756268
## 159 16.259151 15.504025 17.014277
## 160 16.574840 15.838898 17.310783
## 161 22.572940 22.080777 23.065104
## 162 23.362164 22.874970 23.849358
## 163 22.572940 22.080777 23.065104
## 164 24.940611 24.438901 25.442321
## 165 22.572940 22.080777 23.065104
## 166 22.572940 22.080777 23.065104
## 167 19.573890 18.996010 20.151771
## 168 28.097506 27.483687 28.711325
## 169 26.834748 26.276776 27.392720
## 170 24.151388 23.660958 24.641817
## 171 27.623972 27.032512 28.215432
## 172 24.782767 24.283936 25.281597
## 173 28.728885 28.082973 29.374797
## 174 24.624922 24.128663 25.121180
## 175 24.624922 24.128663 25.121180
## 176 28.886730 28.232427 29.541033
## 177 25.729835 25.209322 26.250348
## 178 24.940611 24.438901 25.442321
## 179 26.045524 25.515552 26.575497
## 180 24.467077 23.973079 24.961075
## 181 21.783717 21.278621 22.288812
## 182 31.570090 30.756012 32.384168
## 183 26.361214 25.820758 26.901669
## 184 27.150438 26.579678 27.721197
## 185 25.414146 24.902011 25.926280
## 186 27.466127 26.881761 28.050493
## 187 26.834748 26.276776 27.392720
## 188 17.837598 17.174242 18.500955
## 189 16.259151 15.504025 17.014277
## 190 20.994493 20.469092 21.519894
## 191 15.943462 15.168798 16.718125
## 192 24.151388 23.660958 24.641817
## 193 23.362164 22.874970 23.849358
## 194 27.150438 26.579678 27.721197
## 195 25.729835 25.209322 26.250348
## 196 31.727935 30.903669 32.552201
## 197 30.465177 29.720276 31.210078
## 198 28.886730 28.232427 29.541033
## 199 31.570090 30.756012 32.384168
## 200 24.151388 23.660958 24.641817
## 201 27.623972 27.032512 28.215432
## 202 22.572940 22.080777 23.065104
## 203 24.940611 24.438901 25.442321
## 204 28.728885 28.082973 29.374797
## 205 28.886730 28.232427 29.541033
## 206 28.097506 27.483687 28.711325
## 207 28.571040 27.933378 29.208703
## 208 23.835698 23.347546 24.323850
## 209 16.259151 15.504025 17.014277
## 210 26.045524 25.515552 26.575497
## 211 22.888630 22.399432 23.377828
## 212 20.994493 20.469092 21.519894
## 213 11.523809 10.449826 12.597792
## 214 17.048375 16.340481 17.756268
## 215 19.416046 18.831250 20.000841
## 216 16.259151 15.504025 17.014277
## 217 29.202419 28.530931 29.873907
## 218 27.308282 26.730818 27.885746
## 219 30.780866 30.016612 31.545121
## 220 24.782767 24.283936 25.281597
## 221 28.886730 28.232427 29.541033
## 222 17.048375 16.340481 17.756268
## 223 22.572940 22.080777 23.065104
## 224 17.048375 16.340481 17.756268
## 225 19.416046 18.831250 20.000841
## 226 22.572940 22.080777 23.065104
## 227 23.362164 22.874970 23.849358
## 228 24.151388 23.660958 24.641817
## 229 24.467077 23.973079 24.961075
## 230 11.523809 10.449826 12.597792
## 231 13.102256 12.139493 14.065020
## 232  9.945362  8.757051 11.133672
## 233 16.416996 15.671508 17.162484
## 234 27.623972 27.032512 28.215432
## 235 26.045524 25.515552 26.575497
## 236 28.097506 27.483687 28.711325
## 237 25.887680 25.362568 26.412791
## 238 29.991643 29.275071 30.708215
## 239 26.834748 26.276776 27.392720
## 240 29.360264 28.679992 30.040536
## 241 27.623972 27.032512 28.215432
## 242 24.624922 24.128663 25.121180
## 243 22.572940 22.080777 23.065104
## 244 22.572940 22.080777 23.065104
## 245 32.359314 31.493641 33.224987
## 246 29.518109 28.828932 30.207285
## 247 31.727935 30.903669 32.552201
## 248 28.886730 28.232427 29.541033
## 249 30.465177 29.720276 31.210078
## 250 22.572940 22.080777 23.065104
## 251 17.837598 17.174242 18.500955
## 252 17.995443 17.340622 18.650264
## 253 23.362164 22.874970 23.849358
## 254 24.940611 24.438901 25.442321
## 255 26.519059 25.972996 27.065122
## 256 26.045524 25.515552 26.575497
## 257 24.151388 23.660958 24.641817
## 258 25.729835 25.209322 26.250348
## 259 23.362164 22.874970 23.849358
## 260 26.519059 25.972996 27.065122
## 261 22.572940 22.080777 23.065104
## 262 20.994493 20.469092 21.519894
## 263 17.048375 16.340481 17.756268
## 264 13.891480 12.982802 14.800158
## 265 17.995443 17.340622 18.650264
## 266 17.837598 17.174242 18.500955
## 267 29.202419 28.530931 29.873907
## 268 24.940611 24.438901 25.442321
## 269 24.624922 24.128663 25.121180
## 270 28.097506 27.483687 28.711325
## 271 24.940611 24.438901 25.442321
## 272 23.362164 22.874970 23.849358
## 273 26.519059 25.972996 27.065122
## 274 24.624922 24.128663 25.121180
## 275 23.677853 23.190350 24.165357
## 276 20.205269 19.653000 20.757539
## 277 21.783717 21.278621 22.288812
## 278 18.942511 18.335857 19.549166
## 279 28.728885 28.082973 29.374797
## 280 29.202419 28.530931 29.873907
## 281 21.783717 21.278621 22.288812
## 282 26.519059 25.972996 27.065122
## 283 26.045524 25.515552 26.575497
## 284 25.729835 25.209322 26.250348
## 285 22.572940 22.080777 23.065104
## 286 19.416046 18.831250 20.000841
## 287 19.573890 18.996010 20.151771
## 288 18.153288 17.506866 18.799709
## 289 18.626822 18.004730 19.248914
## 290 15.469927 14.665349 16.274505
## 291 17.521909 16.841095 18.202722
## 292 20.205269 19.653000 20.757539
## 293 16.259151 15.504025 17.014277
## 294 28.728885 28.082973 29.374797
## 295 29.675953 28.977756 30.374151
## 296 27.308282 26.730818 27.885746
## 297 27.308282 26.730818 27.885746
## 298 27.781817 27.183079 28.380554
## 299 20.205269 19.653000 20.757539
## 300 28.728885 28.082973 29.374797
## 301 25.729835 25.209322 26.250348
## 302 28.886730 28.232427 29.541033
## 303 28.886730 28.232427 29.541033
## 304 29.675953 28.977756 30.374151
## 305 29.044574 28.381744 29.707404
## 306 25.729835 25.209322 26.250348
## 307 21.783717 21.278621 22.288812
## 308 21.783717 21.278621 22.288812
## 309 25.729835 25.209322 26.250348
## 310 27.939661 27.333469 28.545854
## 311 30.465177 29.720276 31.210078
## 312 28.886730 28.232427 29.541033
## 313 29.675953 28.977756 30.374151
## 314 25.729835 25.209322 26.250348
## 315 26.045524 25.515552 26.575497
## 316 25.729835 25.209322 26.250348
## 317 25.729835 25.209322 26.250348
## 318 27.623972 27.032512 28.215432
## 319 25.729835 25.209322 26.250348
## 320 28.097506 27.483687 28.711325
## 321 25.414146 24.902011 25.926280
## 322 28.097506 27.483687 28.711325
## 323 29.675953 28.977756 30.374151
## 324 23.362164 22.874970 23.849358
## 325 29.675953 28.977756 30.374151
## 326 32.359314 31.493641 33.224987
## 327 32.359314 31.493641 33.224987
## 328 29.360264 28.679992 30.040536
## 329 29.360264 28.679992 30.040536
## 330 29.360264 28.679992 30.040536
## 331        NA        NA        NA
## 332 29.360264 28.679992 30.040536
## 333 30.149488 29.423571 30.875404
## 334 19.100356 18.501167 19.699545
## 335 24.151388 23.660958 24.641817
## 336 26.045524 25.515552 26.575497
## 337        NA        NA        NA
## 338 28.571040 27.933378 29.208703
## 339 26.676903 26.124999 27.228808
## 340 26.676903 26.124999 27.228808
## 341 25.414146 24.902011 25.926280
## 342 22.572940 22.080777 23.065104
## 343 26.676903 26.124999 27.228808
## 344 30.780866 30.016612 31.545121
## 345 29.833798 29.126467 30.541129
## 346 30.465177 29.720276 31.210078
## 347 29.360264 28.679992 30.040536
## 348 29.675953 28.977756 30.374151
## 349 30.149488 29.423571 30.875404
## 350 29.202419 28.530931 29.873907
## 351 29.991643 29.275071 30.708215
## 352 29.675953 28.977756 30.374151
## 353 29.675953 28.977756 30.374151
## 354 28.255351 27.633741 28.876961
## 355        NA        NA        NA
## 356 28.097506 27.483687 28.711325
## 357 28.097506 27.483687 28.711325
## 358 24.151388 23.660958 24.641817
## 359 28.255351 27.633741 28.876961
## 360 27.308282 26.730818 27.885746
## 361 27.939661 27.333469 28.545854
## 362 21.625872 21.117282 22.134462
## 363 20.994493 20.469092 21.519894
## 364 22.572940 22.080777 23.065104
## 365 23.362164 22.874970 23.849358
## 366 26.045524 25.515552 26.575497
## 367 26.519059 25.972996 27.065122
## 368 26.045524 25.515552 26.575497
## 369 26.045524 25.515552 26.575497
## 370 26.045524 25.515552 26.575497
## 371 26.519059 25.972996 27.065122
## 372 26.676903 26.124999 27.228808
## 373 25.729835 25.209322 26.250348
## 374 25.414146 24.902011 25.926280
## 375 28.255351 27.633741 28.876961
## 376 29.202419 28.530931 29.873907
## 377 29.202419 28.530931 29.873907
## 378 29.991643 29.275071 30.708215
## 379 28.886730 28.232427 29.541033
## 380 26.045524 25.515552 26.575497
## 381 28.097506 27.483687 28.711325
## 382 28.886730 28.232427 29.541033
## 383 29.360264 28.679992 30.040536
## 384 29.360264 28.679992 30.040536
## 385 29.360264 28.679992 30.040536
## 386 22.572940 22.080777 23.065104
## 387 26.519059 25.972996 27.065122
## 388 25.414146 24.902011 25.926280
## 389 22.257251 21.760844 22.753658
## 390 24.782767 24.283936 25.281597
## 391 26.676903 26.124999 27.228808
## 392 25.729835 25.209322 26.250348
## 393 26.361214 25.820758 26.901669
## 394 31.727935 30.903669 32.552201
## 395 26.676903 26.124999 27.228808
## 396 27.466127 26.881761 28.050493
## 397 26.992593 26.428333 27.556853
#Horsepower of 98 confidence -->  fit       lwr       upr
#                               125.37566 122.44501 128.30631

2(b) Plot the response and the predictor. Use the abline() function to display the least squares regression line.

library(tidyverse)
## -- Attaching packages ---------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   1.0.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
ggplot(auto, aes(x=mpg, y=horsepower))+
  geom_point()+
  geom_abline(slope=mod$coefficients[2], intercept=mod$coefficients[1],
              color="blue", lty=2, lwd=1)
## Warning: Removed 5 rows containing missing values (geom_point).

2(c) Use the plot() function to produce diagnostic plots of the least squares regression fit. Comment on any problems you see with the fit.

plot(mod)

#It has a large curve upwards near the end of the depicted data, which would indicate a skew.

Problem 3 (textbook 3.9 ) This question involves the use of multiple linear regression on the Auto dataset from the textbook website. Load in the data and take out the quantitative variables for origin and name:

3(A) Produce a scatter plot matrix which includes all of the variables in the dataset

auto<-auto[,-c(8:9)]
pairs(auto)

3(B) Compute the matrix of correlations between the variables using the function

cor(auto)
##                     mpg  cylinders displacement horsepower     weight
## mpg           1.0000000 -0.7762599   -0.8044430         NA -0.8317389
## cylinders    -0.7762599  1.0000000    0.9509199         NA  0.8970169
## displacement -0.8044430  0.9509199    1.0000000         NA  0.9331044
## horsepower           NA         NA           NA          1         NA
## weight       -0.8317389  0.8970169    0.9331044         NA  1.0000000
## acceleration  0.4222974 -0.5040606   -0.5441618         NA -0.4195023
## year          0.5814695 -0.3467172   -0.3698041         NA -0.3079004
##              acceleration       year
## mpg             0.4222974  0.5814695
## cylinders      -0.5040606 -0.3467172
## displacement   -0.5441618 -0.3698041
## horsepower             NA         NA
## weight         -0.4195023 -0.3079004
## acceleration    1.0000000  0.2829009
## year            0.2829009  1.0000000

3(C) Use the lm() function to perform a multiple linear regression with mpg as the response and all other variables (except origin and name) as predictors. Use the summary() function to print the results. Comment on the output.

names(auto)
## [1] "mpg"          "cylinders"    "displacement" "horsepower"  
## [5] "weight"       "acceleration" "year"
mlr_mod<-lm(mpg ~ cylinders+displacement+horsepower+weight+acceleration+year, data=auto)
summary(mlr_mod)
## 
## Call:
## lm(formula = mpg ~ cylinders + displacement + horsepower + weight + 
##     acceleration + year, data = auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.6927 -2.3864 -0.0801  2.0291 14.3607 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.454e+01  4.764e+00  -3.051  0.00244 ** 
## cylinders    -3.299e-01  3.321e-01  -0.993  0.32122    
## displacement  7.678e-03  7.358e-03   1.044  0.29733    
## horsepower   -3.914e-04  1.384e-02  -0.028  0.97745    
## weight       -6.795e-03  6.700e-04 -10.141  < 2e-16 ***
## acceleration  8.527e-02  1.020e-01   0.836  0.40383    
## year          7.534e-01  5.262e-02  14.318  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.435 on 385 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.8093, Adjusted R-squared:  0.8063 
## F-statistic: 272.2 on 6 and 385 DF,  p-value: < 2.2e-16
#  1. Is there a relationship between the predictors and the response?
# Yes.
#  2. Which predictors appear to have a statistically significant relationship to the response?
# Weight and year.
#  3. What does the coefficient for the year variable suggest?
# I am unsure and would like to review this.

3(D): Write code using matrix algebra to produce the summary output (ie. ˆ vector and SE(ˆ), you’ll need to find the response vector and design matrix to do this).

Y<-as.matrix(mpg)
n<-dim(Y)[1]
X<-matrix(c(rep(1, n),
            cylinders, 
            displacement,
            horsepower,
            weight,
            acceleration,
            year), 
          ncol=6, 
          byrow=FALSE)
dim(X)
## [1] 436   6

3(E) Use the plot function in base R or use ggplot to produce diagnostic plots of linear regression fit. Comment on any problems you see with the fit. Do the residual plots suggest any unusually large outliers (in the y direction)?

plot(mlr_mod)

#It appears to have a skew in the upper right part of the data.

HW #5

Problem 1

1A) Use the * and : symbols to fit linear regression models with interaction effects. Do any interactions appear to be statistically significant? (at the 0.05 level)

names(auto)
## [1] "mpg"          "cylinders"    "displacement" "horsepower"  
## [5] "weight"       "acceleration" "year"
autoMod1<-lm(mpg~cylinders*year, data=auto)
summary(autoMod1)#The interaction between cylinders and year does appear to be statistically significant
## 
## Call:
## lm(formula = mpg ~ cylinders * year, data = auto)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.2564  -2.5806  -0.1016   2.2535  15.2226 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -61.84732   15.06957  -4.104 4.94e-05 ***
## cylinders        5.54877    2.74057   2.025  0.04358 *  
## year             1.34426    0.19865   6.767 4.79e-11 ***
## cylinders:year  -0.11410    0.03652  -3.124  0.00191 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.154 on 393 degrees of freedom
## Multiple R-squared:  0.7204, Adjusted R-squared:  0.7183 
## F-statistic: 337.5 on 3 and 393 DF,  p-value: < 2.2e-16
autoMod2<-lm(mpg~cylinders:displacement, data=auto)
summary(autoMod2)#Cylinders and displacement's relationship does appear to be statistically significant
## 
## Call:
## lm(formula = mpg ~ cylinders:displacement, data = auto)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.7498  -3.4685  -0.4891   2.7089  17.6733 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            31.0397951  0.3891622   79.76   <2e-16 ***
## cylinders:displacement -0.0061427  0.0002467  -24.90   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.888 on 395 degrees of freedom
## Multiple R-squared:  0.6109, Adjusted R-squared:  0.6099 
## F-statistic: 620.2 on 1 and 395 DF,  p-value: < 2.2e-16
autoMod3<-lm(weight~horsepower:displacement, data=auto)
summary(autoMod3) #The interaction between horsepower and displacement appears significant. 
## 
## Call:
## lm(formula = weight ~ horsepower:displacement, data = auto)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2596.78  -264.87   -25.09   270.75  1027.21 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             2.153e+03  3.040e+01   70.82   <2e-16 ***
## horsepower:displacement 3.448e-02  9.423e-04   36.59   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 404 on 390 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.7744, Adjusted R-squared:  0.7738 
## F-statistic:  1339 on 1 and 390 DF,  p-value: < 2.2e-16

(B) Try a few different transformations of the variables, such as log(X), √X, X2. Comment on your findings.

log(weight,10)#Answers appear to be between 3-4, which is approximately 1/1000 of the original responses.
##   [1] 3.544564 3.567379 3.536053 3.535674 3.537693 3.637590 3.638888
##   [8] 3.634679 3.645913 3.585461 3.551816 3.557387 3.575303 3.489396
##  [15] 3.375115 3.452247 3.443106 3.412796 3.328380 3.263636 3.426836
##  [22] 3.385606 3.375664 3.349083 3.422918 3.664172 3.641077 3.641672
##  [29] 3.675045 3.328380 3.354876 3.347915 3.310906 3.420616 3.536432
##  [36] 3.522314 3.518777 3.516932 3.624179 3.649724 3.618466 3.612360
##  [43] 3.695044 3.676328 3.710963 3.471585 3.381656 3.516139 3.496791
##  [50] 3.346353 3.326950 3.316809 3.314920 3.248709 3.207634 3.263399
##  [57] 3.291147 3.357554 3.327563 3.352954 3.381656 3.347525 3.630835
##  [64] 3.641970 3.616476 3.615845 3.564903 3.665862 3.653405 3.648945
##  [71] 3.645619 3.367356 3.590173 3.612572 3.632862 3.610341 3.467312
##  [78] 3.399847 3.474071 3.340246 3.379306 3.359456 3.398981 3.335257
##  [85] 3.322219 3.612784 3.564903 3.600755 3.606596 3.577147 3.694781
##  [92] 3.649724 3.639785 3.627058 3.675320 3.694693 3.582177 3.494294
##  [99] 3.515609 3.469085 3.480151 3.462997 3.290035 3.698709 3.690728
## [106] 3.667826 3.653116 3.445449 3.357744 3.380392 3.376394 3.327155
## [113] 3.363612 3.393048 3.355068 3.610873 3.631241 3.271144 3.334051
## [120] 3.411956 3.457579 3.531351 3.424882 3.448242 3.563955 3.491642
## [127] 3.458638 3.462548 3.523226 3.290035 3.389343 3.263873 3.405176
## [134] 3.577607 3.560146 3.557868 3.617105 3.672005 3.649043 3.666331
## [141] 3.629104 3.346157 3.292920 3.361728 3.217221 3.301681 3.327359
## [148] 3.323871 3.351410 3.396025 3.378580 3.301030 3.513750 3.538951
## [155] 3.535547 3.499412 3.669131 3.647383 3.653019 3.668106 3.591843
## [162] 3.590730 3.571709 3.578066 3.482731 3.507991 3.500922 3.336660
## [169] 3.421439 3.464490 3.413635 3.431685 3.346939 3.405688 3.474799
## [176] 3.287130 3.506640 3.430398 3.470851 3.469085 3.426674 3.254064
## [183] 3.391641 3.346353 3.410271 3.353147 3.342817 3.624798 3.622214
## [190] 3.597914 3.624798 3.509606 3.525434 3.478855 3.489255 3.308564
## [197] 3.335257 3.287130 3.254064 3.562412 3.553155 3.561698 3.504199
## [204] 3.261263 3.298853 3.333447 3.409087 3.498311 3.595496 3.514548
## [211] 3.466868 3.582063 3.641474 3.607991 3.587711 3.574610 3.310693
## [218] 3.333447 3.261263 3.361728 3.288920 3.588832 3.608526 3.617000
## [225] 3.632963 3.546543 3.534661 3.559907 3.547159 3.625312 3.619615
## [232] 3.635986 3.636989 3.287802 3.437751 3.355068 3.440122 3.311966
## [239] 3.317018 3.297761 3.340444 3.449478 3.414973 3.434569 3.297761
## [246] 3.255273 3.297761 3.315970 3.255273 3.526985 3.572291 3.552668
## [253] 3.548389 3.498999 3.472025 3.434569 3.535294 3.506505 3.528917
## [260] 3.487138 3.558709 3.532754 3.534661 3.537189 3.505828 3.610660
## [267] 3.333447 3.408240 3.361728 3.348305 3.400538 3.438542 3.455606
## [274] 3.381115 3.451786 3.496930 3.446382 3.532754 3.298853 3.329398
## [281] 3.511215 3.475671 3.460898 3.513883 3.526339 3.584331 3.571126
## [288] 3.597146 3.583199 3.639486 3.607884 3.556905 3.595496 3.284431
## [295] 3.295567 3.282169 3.426511 3.547775 3.591065 3.503791 3.534026
## [302] 3.342423 3.332438 3.305351 3.328380 3.426511 3.414137 3.431364
## [309] 3.407561 3.331225 3.294025 3.326336 3.305136 3.427811 3.457882
## [316] 3.477555 3.529045 3.340047 3.433130 3.405176 3.386321 3.355068
## [323] 3.324282 3.447158 3.324282 3.319106 3.368287 3.469822 3.511883
## [330] 3.267172 3.263636 3.331427 3.265996 3.463893 3.383815 3.397940
## [337] 3.463146 3.359835 3.396199 3.420781 3.418301 3.435367 3.377488
## [344] 3.244277 3.273001 3.245513 3.314920 3.295567 3.311754 3.297761
## [351] 3.345374 3.310693 3.376577 3.340444 3.365488 3.344392 3.371068
## [358] 3.417472 3.420781 3.509203 3.499687 3.462398 3.466868 3.533391
## [365] 3.571126 3.485721 3.539703 3.415808 3.421604 3.379306 3.410777
## [372] 3.402261 3.436957 3.457125 3.296665 3.306425 3.294466 3.327359
## [379] 3.327359 3.334454 3.343409 3.351216 3.293363 3.293363 3.299943
## [386] 3.469085 3.479287 3.412461 3.452553 3.425697 3.374748 3.469822
## [393] 3.445604 3.328380 3.360783 3.419129 3.434569
weight*2 #Each response has doubled. 
##   [1]  7008  7386  6872  6866  6898  8682  8708  8624  8850  7700  7126
##  [12]  7218  7522  6172  4744  5666  5548  5174  4260  3670  5344  4860
##  [23]  4750  4468  5296  9230  8752  8764  9464  4260  4528  4456  4092
##  [34]  5268  6878  6658  6604  6576  8418  8928  8308  8192  9910  9492
##  [45] 10280  5924  4816  6564  6278  4440  4246  4148  4130  3546  3226
##  [56]  3668  3910  4556  4252  4508  4816  4452  8548  8770  8270  8258
##  [67]  7344  9266  9004  8912  8844  4660  7784  8196  8588  8154  5866
##  [78]  5022  5958  4378  4790  4576  5012  4328  4200  8200  7344  7976
##  [89]  8084  7554  9904  8928  8726  8474  9470  9902  7642  6242  6556
## [100]  5890  6042  5808  3900  9994  9812  9308  8998  5578  4558  4802
## [111]  4758  4248  4620  4944  4530  8164  8556  3734  4316  5164  5736
## [122]  6798  5320  5614  7328  6204  5750  5802  6672  3900  4902  3672
## [133]  5084  7562  7264  7226  8282  9398  8914  9276  8514  4438  3926
## [144]  4600  3298  4006  4250  4216  4492  4978  4782  4000  6528  6918
## [155]  6864  6316  9336  8880  8996  9314  7814  7794  7460  7570  6078
## [166]  6442  6338  4342  5278  5828  5184  5404  4446  5090  5968  3874
## [177]  6422  5388  5914  5890  5342  3590  4928  4440  5144  4510  4404
## [188]  8430  8380  7924  8430  6466  6706  6024  6170  4070  4328  3874
## [199]  3590  7302  7148  7290  6386  3650  3980  4310  5130  6300  7880
## [210]  6540  5860  7640  8760  8110  7740  7510  4090  4310  3650  4600
## [221]  3890  7760  8120  8280  8590  7040  6850  7260  7050  8440  8330
## [232]  8650  8670  3880  5480  4530  5510  4102  4150  3970  4380  5630
## [243]  5200  5440  3970  3600  3970  4140  3600  6730  7470  7140  7070
## [254]  6310  5930  5440  6860  6420  6760  6140  7240  6820  6850  6890
## [265]  6410  8160  4310  5120  4600  4460  5030  5490  5710  4810  5660
## [276]  6280  5590  6820  3980  4270  6490  5980  5780  6530  6720  7680
## [287]  7450  7910  7660  8720  8108  7210  7880  3850  3950  3830  5340
## [298]  7060  7800  6380  6840  4400  4300  4040  4260  5340  5190  5400
## [309]  5112  4288  3936  4240  4038  5356  5740  6006  6762  4376  5422
## [320]  5084  4868  4530  4220  5600  4220  4170  4670  5900  6500  3700
## [331]  3670  4290  3690  5820  4840  5000  5810  4580  4980  5270  5240
## [342]  5450  4770  3510  3750  3520  4130  3950  4100  3970  4430  4090
## [353]  4760  4380  4640  4420  4700  5230  5270  6460  6320  5800  5860
## [364]  6830  7450  6120  6930  5210  5280  4790  5150  5050  5470  5730
## [375]  3960  4050  3940  4250  4250  4320  4410  4490  3930  3930  3990
## [386]  5890  6030  5170  5670  5330  4740  5900  5580  4260  4590  5250
## [397]  5440
log(cylinders,10) #Answers appear to be between 1-3,which is approximately 1/100 of the original responses.
##   [1] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##   [8] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [15] 0.6020600 0.7781513 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600
##  [22] 0.6020600 0.6020600 0.6020600 0.7781513 0.9030900 0.9030900 0.9030900
##  [29] 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
##  [36] 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900
##  [43] 0.9030900 0.9030900 0.9030900 0.7781513 0.6020600 0.7781513 0.7781513
##  [50] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
##  [57] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900
##  [64] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [71] 0.9030900 0.4771213 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
##  [78] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
##  [85] 0.6020600 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [92] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.7781513
##  [99] 0.7781513 0.7781513 0.7781513 0.7781513 0.6020600 0.9030900 0.9030900
## [106] 0.9030900 0.9030900 0.7781513 0.6020600 0.6020600 0.6020600 0.4771213
## [113] 0.6020600 0.7781513 0.6020600 0.9030900 0.9030900 0.6020600 0.6020600
## [120] 0.6020600 0.6020600 0.9030900 0.6020600 0.7781513 0.9030900 0.7781513
## [127] 0.7781513 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600
## [134] 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900
## [141] 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [148] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
## [155] 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900 0.7781513
## [162] 0.7781513 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.6020600
## [169] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513
## [176] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [183] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900
## [190] 0.9030900 0.9030900 0.7781513 0.7781513 0.7781513 0.7781513 0.6020600
## [197] 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513 0.7781513 0.7781513
## [204] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.6020600
## [211] 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
## [218] 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900 0.9030900
## [225] 0.9030900 0.7781513 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900
## [232] 0.9030900 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [239] 0.6020600 0.6020600 0.6020600 0.7781513 0.6020600 0.4771213 0.6020600
## [246] 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900 0.9030900
## [253] 0.7781513 0.7781513 0.7781513 0.6020600 0.7781513 0.7781513 0.7781513
## [260] 0.7781513 0.7781513 0.7781513 0.9030900 0.7781513 0.9030900 0.9030900
## [267] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [274] 0.6020600 0.6989700 0.7781513 0.6020600 0.7781513 0.6020600 0.6020600
## [281] 0.7781513 0.7781513 0.6020600 0.7781513 0.7781513 0.9030900 0.9030900
## [288] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
## [295] 0.6020600 0.6020600 0.6020600 0.6989700 0.9030900 0.6020600 0.9030900
## [302] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
## [309] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [316] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [323] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6989700 0.6020600
## [330] 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.4771213 0.6020600
## [337] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.6020600
## [344] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [351] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [358] 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513 0.7781513 0.7781513
## [365] 0.9030900 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600
## [372] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [379] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [386] 0.7781513 0.7781513 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600
## [393] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
sqrt(cylinders)#Answers appear to be betweeen 2-2.5, with a smaller range than the log responses.
##   [1] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##   [8] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [15] 2.000000 2.449490 2.449490 2.449490 2.000000 2.000000 2.000000
##  [22] 2.000000 2.000000 2.000000 2.449490 2.828427 2.828427 2.828427
##  [29] 2.828427 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
##  [36] 2.449490 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427
##  [43] 2.828427 2.828427 2.828427 2.449490 2.000000 2.449490 2.449490
##  [50] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
##  [57] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427
##  [64] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [71] 2.828427 1.732051 2.828427 2.828427 2.828427 2.828427 2.000000
##  [78] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
##  [85] 2.000000 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [92] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.449490
##  [99] 2.449490 2.449490 2.449490 2.449490 2.000000 2.828427 2.828427
## [106] 2.828427 2.828427 2.449490 2.000000 2.000000 2.000000 1.732051
## [113] 2.000000 2.449490 2.000000 2.828427 2.828427 2.000000 2.000000
## [120] 2.000000 2.000000 2.828427 2.000000 2.449490 2.828427 2.449490
## [127] 2.449490 2.449490 2.449490 2.000000 2.000000 2.000000 2.000000
## [134] 2.449490 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427
## [141] 2.828427 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [148] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
## [155] 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427 2.449490
## [162] 2.449490 2.449490 2.449490 2.449490 2.828427 2.828427 2.000000
## [169] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.449490
## [176] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.000000
## [183] 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427
## [190] 2.828427 2.828427 2.449490 2.449490 2.449490 2.449490 2.000000
## [197] 2.000000 2.000000 2.000000 2.449490 2.449490 2.449490 2.449490
## [204] 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427 2.000000
## [211] 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427 2.000000
## [218] 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427 2.828427
## [225] 2.828427 2.449490 2.449490 2.449490 2.449490 2.828427 2.828427
## [232] 2.828427 2.828427 2.000000 2.000000 2.000000 2.000000 2.000000
## [239] 2.000000 2.000000 2.000000 2.449490 2.000000 1.732051 2.000000
## [246] 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427 2.828427
## [253] 2.449490 2.449490 2.449490 2.000000 2.449490 2.449490 2.449490
## [260] 2.449490 2.449490 2.449490 2.828427 2.449490 2.828427 2.828427
## [267] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [274] 2.000000 2.236068 2.449490 2.000000 2.449490 2.000000 2.000000
## [281] 2.449490 2.449490 2.000000 2.449490 2.449490 2.828427 2.828427
## [288] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.000000
## [295] 2.000000 2.000000 2.000000 2.236068 2.828427 2.000000 2.828427
## [302] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
## [309] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [316] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.000000
## [323] 2.000000 2.000000 2.000000 2.000000 2.000000 2.236068 2.000000
## [330] 2.000000 2.000000 2.000000 2.000000 2.449490 1.732051 2.000000
## [337] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.000000
## [344] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [351] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [358] 2.000000 2.000000 2.000000 2.449490 2.449490 2.449490 2.449490
## [365] 2.828427 2.449490 2.449490 2.000000 2.000000 2.000000 2.000000
## [372] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [379] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [386] 2.449490 2.449490 2.000000 2.449490 2.000000 2.000000 2.000000
## [393] 2.000000 2.000000 2.000000 2.000000 2.000000

2B) Try a few different transformations of the variables, such as log(X), √X, X2. Comment on your findings.

log(weight,10)#Answers appear to be between 3-4, which is approximately 1/1000 of the original responses.
##   [1] 3.544564 3.567379 3.536053 3.535674 3.537693 3.637590 3.638888
##   [8] 3.634679 3.645913 3.585461 3.551816 3.557387 3.575303 3.489396
##  [15] 3.375115 3.452247 3.443106 3.412796 3.328380 3.263636 3.426836
##  [22] 3.385606 3.375664 3.349083 3.422918 3.664172 3.641077 3.641672
##  [29] 3.675045 3.328380 3.354876 3.347915 3.310906 3.420616 3.536432
##  [36] 3.522314 3.518777 3.516932 3.624179 3.649724 3.618466 3.612360
##  [43] 3.695044 3.676328 3.710963 3.471585 3.381656 3.516139 3.496791
##  [50] 3.346353 3.326950 3.316809 3.314920 3.248709 3.207634 3.263399
##  [57] 3.291147 3.357554 3.327563 3.352954 3.381656 3.347525 3.630835
##  [64] 3.641970 3.616476 3.615845 3.564903 3.665862 3.653405 3.648945
##  [71] 3.645619 3.367356 3.590173 3.612572 3.632862 3.610341 3.467312
##  [78] 3.399847 3.474071 3.340246 3.379306 3.359456 3.398981 3.335257
##  [85] 3.322219 3.612784 3.564903 3.600755 3.606596 3.577147 3.694781
##  [92] 3.649724 3.639785 3.627058 3.675320 3.694693 3.582177 3.494294
##  [99] 3.515609 3.469085 3.480151 3.462997 3.290035 3.698709 3.690728
## [106] 3.667826 3.653116 3.445449 3.357744 3.380392 3.376394 3.327155
## [113] 3.363612 3.393048 3.355068 3.610873 3.631241 3.271144 3.334051
## [120] 3.411956 3.457579 3.531351 3.424882 3.448242 3.563955 3.491642
## [127] 3.458638 3.462548 3.523226 3.290035 3.389343 3.263873 3.405176
## [134] 3.577607 3.560146 3.557868 3.617105 3.672005 3.649043 3.666331
## [141] 3.629104 3.346157 3.292920 3.361728 3.217221 3.301681 3.327359
## [148] 3.323871 3.351410 3.396025 3.378580 3.301030 3.513750 3.538951
## [155] 3.535547 3.499412 3.669131 3.647383 3.653019 3.668106 3.591843
## [162] 3.590730 3.571709 3.578066 3.482731 3.507991 3.500922 3.336660
## [169] 3.421439 3.464490 3.413635 3.431685 3.346939 3.405688 3.474799
## [176] 3.287130 3.506640 3.430398 3.470851 3.469085 3.426674 3.254064
## [183] 3.391641 3.346353 3.410271 3.353147 3.342817 3.624798 3.622214
## [190] 3.597914 3.624798 3.509606 3.525434 3.478855 3.489255 3.308564
## [197] 3.335257 3.287130 3.254064 3.562412 3.553155 3.561698 3.504199
## [204] 3.261263 3.298853 3.333447 3.409087 3.498311 3.595496 3.514548
## [211] 3.466868 3.582063 3.641474 3.607991 3.587711 3.574610 3.310693
## [218] 3.333447 3.261263 3.361728 3.288920 3.588832 3.608526 3.617000
## [225] 3.632963 3.546543 3.534661 3.559907 3.547159 3.625312 3.619615
## [232] 3.635986 3.636989 3.287802 3.437751 3.355068 3.440122 3.311966
## [239] 3.317018 3.297761 3.340444 3.449478 3.414973 3.434569 3.297761
## [246] 3.255273 3.297761 3.315970 3.255273 3.526985 3.572291 3.552668
## [253] 3.548389 3.498999 3.472025 3.434569 3.535294 3.506505 3.528917
## [260] 3.487138 3.558709 3.532754 3.534661 3.537189 3.505828 3.610660
## [267] 3.333447 3.408240 3.361728 3.348305 3.400538 3.438542 3.455606
## [274] 3.381115 3.451786 3.496930 3.446382 3.532754 3.298853 3.329398
## [281] 3.511215 3.475671 3.460898 3.513883 3.526339 3.584331 3.571126
## [288] 3.597146 3.583199 3.639486 3.607884 3.556905 3.595496 3.284431
## [295] 3.295567 3.282169 3.426511 3.547775 3.591065 3.503791 3.534026
## [302] 3.342423 3.332438 3.305351 3.328380 3.426511 3.414137 3.431364
## [309] 3.407561 3.331225 3.294025 3.326336 3.305136 3.427811 3.457882
## [316] 3.477555 3.529045 3.340047 3.433130 3.405176 3.386321 3.355068
## [323] 3.324282 3.447158 3.324282 3.319106 3.368287 3.469822 3.511883
## [330] 3.267172 3.263636 3.331427 3.265996 3.463893 3.383815 3.397940
## [337] 3.463146 3.359835 3.396199 3.420781 3.418301 3.435367 3.377488
## [344] 3.244277 3.273001 3.245513 3.314920 3.295567 3.311754 3.297761
## [351] 3.345374 3.310693 3.376577 3.340444 3.365488 3.344392 3.371068
## [358] 3.417472 3.420781 3.509203 3.499687 3.462398 3.466868 3.533391
## [365] 3.571126 3.485721 3.539703 3.415808 3.421604 3.379306 3.410777
## [372] 3.402261 3.436957 3.457125 3.296665 3.306425 3.294466 3.327359
## [379] 3.327359 3.334454 3.343409 3.351216 3.293363 3.293363 3.299943
## [386] 3.469085 3.479287 3.412461 3.452553 3.425697 3.374748 3.469822
## [393] 3.445604 3.328380 3.360783 3.419129 3.434569
weight*2 #Each response has doubled. 
##   [1]  7008  7386  6872  6866  6898  8682  8708  8624  8850  7700  7126
##  [12]  7218  7522  6172  4744  5666  5548  5174  4260  3670  5344  4860
##  [23]  4750  4468  5296  9230  8752  8764  9464  4260  4528  4456  4092
##  [34]  5268  6878  6658  6604  6576  8418  8928  8308  8192  9910  9492
##  [45] 10280  5924  4816  6564  6278  4440  4246  4148  4130  3546  3226
##  [56]  3668  3910  4556  4252  4508  4816  4452  8548  8770  8270  8258
##  [67]  7344  9266  9004  8912  8844  4660  7784  8196  8588  8154  5866
##  [78]  5022  5958  4378  4790  4576  5012  4328  4200  8200  7344  7976
##  [89]  8084  7554  9904  8928  8726  8474  9470  9902  7642  6242  6556
## [100]  5890  6042  5808  3900  9994  9812  9308  8998  5578  4558  4802
## [111]  4758  4248  4620  4944  4530  8164  8556  3734  4316  5164  5736
## [122]  6798  5320  5614  7328  6204  5750  5802  6672  3900  4902  3672
## [133]  5084  7562  7264  7226  8282  9398  8914  9276  8514  4438  3926
## [144]  4600  3298  4006  4250  4216  4492  4978  4782  4000  6528  6918
## [155]  6864  6316  9336  8880  8996  9314  7814  7794  7460  7570  6078
## [166]  6442  6338  4342  5278  5828  5184  5404  4446  5090  5968  3874
## [177]  6422  5388  5914  5890  5342  3590  4928  4440  5144  4510  4404
## [188]  8430  8380  7924  8430  6466  6706  6024  6170  4070  4328  3874
## [199]  3590  7302  7148  7290  6386  3650  3980  4310  5130  6300  7880
## [210]  6540  5860  7640  8760  8110  7740  7510  4090  4310  3650  4600
## [221]  3890  7760  8120  8280  8590  7040  6850  7260  7050  8440  8330
## [232]  8650  8670  3880  5480  4530  5510  4102  4150  3970  4380  5630
## [243]  5200  5440  3970  3600  3970  4140  3600  6730  7470  7140  7070
## [254]  6310  5930  5440  6860  6420  6760  6140  7240  6820  6850  6890
## [265]  6410  8160  4310  5120  4600  4460  5030  5490  5710  4810  5660
## [276]  6280  5590  6820  3980  4270  6490  5980  5780  6530  6720  7680
## [287]  7450  7910  7660  8720  8108  7210  7880  3850  3950  3830  5340
## [298]  7060  7800  6380  6840  4400  4300  4040  4260  5340  5190  5400
## [309]  5112  4288  3936  4240  4038  5356  5740  6006  6762  4376  5422
## [320]  5084  4868  4530  4220  5600  4220  4170  4670  5900  6500  3700
## [331]  3670  4290  3690  5820  4840  5000  5810  4580  4980  5270  5240
## [342]  5450  4770  3510  3750  3520  4130  3950  4100  3970  4430  4090
## [353]  4760  4380  4640  4420  4700  5230  5270  6460  6320  5800  5860
## [364]  6830  7450  6120  6930  5210  5280  4790  5150  5050  5470  5730
## [375]  3960  4050  3940  4250  4250  4320  4410  4490  3930  3930  3990
## [386]  5890  6030  5170  5670  5330  4740  5900  5580  4260  4590  5250
## [397]  5440
log(cylinders,10) #Answers appear to be between 1-3,which is approximately 1/100 of the original responses.
##   [1] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##   [8] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [15] 0.6020600 0.7781513 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600
##  [22] 0.6020600 0.6020600 0.6020600 0.7781513 0.9030900 0.9030900 0.9030900
##  [29] 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
##  [36] 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900
##  [43] 0.9030900 0.9030900 0.9030900 0.7781513 0.6020600 0.7781513 0.7781513
##  [50] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
##  [57] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900
##  [64] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [71] 0.9030900 0.4771213 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
##  [78] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
##  [85] 0.6020600 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900
##  [92] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.7781513
##  [99] 0.7781513 0.7781513 0.7781513 0.7781513 0.6020600 0.9030900 0.9030900
## [106] 0.9030900 0.9030900 0.7781513 0.6020600 0.6020600 0.6020600 0.4771213
## [113] 0.6020600 0.7781513 0.6020600 0.9030900 0.9030900 0.6020600 0.6020600
## [120] 0.6020600 0.6020600 0.9030900 0.6020600 0.7781513 0.9030900 0.7781513
## [127] 0.7781513 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600
## [134] 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900
## [141] 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [148] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
## [155] 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900 0.7781513
## [162] 0.7781513 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900 0.6020600
## [169] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513
## [176] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [183] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900
## [190] 0.9030900 0.9030900 0.7781513 0.7781513 0.7781513 0.7781513 0.6020600
## [197] 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513 0.7781513 0.7781513
## [204] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.6020600
## [211] 0.7781513 0.7781513 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
## [218] 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900 0.9030900
## [225] 0.9030900 0.7781513 0.7781513 0.7781513 0.7781513 0.9030900 0.9030900
## [232] 0.9030900 0.9030900 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [239] 0.6020600 0.6020600 0.6020600 0.7781513 0.6020600 0.4771213 0.6020600
## [246] 0.6020600 0.6020600 0.6020600 0.6020600 0.9030900 0.9030900 0.9030900
## [253] 0.7781513 0.7781513 0.7781513 0.6020600 0.7781513 0.7781513 0.7781513
## [260] 0.7781513 0.7781513 0.7781513 0.9030900 0.7781513 0.9030900 0.9030900
## [267] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [274] 0.6020600 0.6989700 0.7781513 0.6020600 0.7781513 0.6020600 0.6020600
## [281] 0.7781513 0.7781513 0.6020600 0.7781513 0.7781513 0.9030900 0.9030900
## [288] 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.9030900 0.6020600
## [295] 0.6020600 0.6020600 0.6020600 0.6989700 0.9030900 0.6020600 0.9030900
## [302] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513
## [309] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [316] 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [323] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6989700 0.6020600
## [330] 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.4771213 0.6020600
## [337] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.7781513 0.6020600
## [344] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [351] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [358] 0.6020600 0.6020600 0.6020600 0.7781513 0.7781513 0.7781513 0.7781513
## [365] 0.9030900 0.7781513 0.7781513 0.6020600 0.6020600 0.6020600 0.6020600
## [372] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [379] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
## [386] 0.7781513 0.7781513 0.6020600 0.7781513 0.6020600 0.6020600 0.6020600
## [393] 0.6020600 0.6020600 0.6020600 0.6020600 0.6020600
sqrt(cylinders)#Answers appear to be betweeen 2-2.5, with a smaller range than the log responses.
##   [1] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##   [8] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [15] 2.000000 2.449490 2.449490 2.449490 2.000000 2.000000 2.000000
##  [22] 2.000000 2.000000 2.000000 2.449490 2.828427 2.828427 2.828427
##  [29] 2.828427 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
##  [36] 2.449490 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427
##  [43] 2.828427 2.828427 2.828427 2.449490 2.000000 2.449490 2.449490
##  [50] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
##  [57] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427
##  [64] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [71] 2.828427 1.732051 2.828427 2.828427 2.828427 2.828427 2.000000
##  [78] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
##  [85] 2.000000 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427
##  [92] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.449490
##  [99] 2.449490 2.449490 2.449490 2.449490 2.000000 2.828427 2.828427
## [106] 2.828427 2.828427 2.449490 2.000000 2.000000 2.000000 1.732051
## [113] 2.000000 2.449490 2.000000 2.828427 2.828427 2.000000 2.000000
## [120] 2.000000 2.000000 2.828427 2.000000 2.449490 2.828427 2.449490
## [127] 2.449490 2.449490 2.449490 2.000000 2.000000 2.000000 2.000000
## [134] 2.449490 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427
## [141] 2.828427 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [148] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
## [155] 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427 2.449490
## [162] 2.449490 2.449490 2.449490 2.449490 2.828427 2.828427 2.000000
## [169] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.449490
## [176] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.000000
## [183] 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427
## [190] 2.828427 2.828427 2.449490 2.449490 2.449490 2.449490 2.000000
## [197] 2.000000 2.000000 2.000000 2.449490 2.449490 2.449490 2.449490
## [204] 2.000000 2.000000 2.000000 2.000000 2.000000 2.828427 2.000000
## [211] 2.449490 2.449490 2.828427 2.828427 2.828427 2.828427 2.000000
## [218] 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427 2.828427
## [225] 2.828427 2.449490 2.449490 2.449490 2.449490 2.828427 2.828427
## [232] 2.828427 2.828427 2.000000 2.000000 2.000000 2.000000 2.000000
## [239] 2.000000 2.000000 2.000000 2.449490 2.000000 1.732051 2.000000
## [246] 2.000000 2.000000 2.000000 2.000000 2.828427 2.828427 2.828427
## [253] 2.449490 2.449490 2.449490 2.000000 2.449490 2.449490 2.449490
## [260] 2.449490 2.449490 2.449490 2.828427 2.449490 2.828427 2.828427
## [267] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [274] 2.000000 2.236068 2.449490 2.000000 2.449490 2.000000 2.000000
## [281] 2.449490 2.449490 2.000000 2.449490 2.449490 2.828427 2.828427
## [288] 2.828427 2.828427 2.828427 2.828427 2.828427 2.828427 2.000000
## [295] 2.000000 2.000000 2.000000 2.236068 2.828427 2.000000 2.828427
## [302] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.449490
## [309] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [316] 2.000000 2.449490 2.000000 2.000000 2.000000 2.000000 2.000000
## [323] 2.000000 2.000000 2.000000 2.000000 2.000000 2.236068 2.000000
## [330] 2.000000 2.000000 2.000000 2.000000 2.449490 1.732051 2.000000
## [337] 2.000000 2.000000 2.000000 2.000000 2.000000 2.449490 2.000000
## [344] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [351] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [358] 2.000000 2.000000 2.000000 2.449490 2.449490 2.449490 2.449490
## [365] 2.828427 2.449490 2.449490 2.000000 2.000000 2.000000 2.000000
## [372] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [379] 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000 2.000000
## [386] 2.449490 2.449490 2.000000 2.449490 2.000000 2.000000 2.000000
## [393] 2.000000 2.000000 2.000000 2.000000 2.000000

Problem 2 (textbook 3.10). This question involves the use of multiple linear regression with categorical variables on the Carseat dataset from the textbook website.

2A) Fit a multiple regression model to predict Sales using Price, Urban, and US.

library(ISLR)
data(Carseats)

carMod<-lm(Sales~Price+Urban+US, data=Carseats)
summary(carMod)
## 
## Call:
## lm(formula = Sales ~ Price + Urban + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9206 -1.6220 -0.0564  1.5786  7.0581 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.043469   0.651012  20.036  < 2e-16 ***
## Price       -0.054459   0.005242 -10.389  < 2e-16 ***
## UrbanYes    -0.021916   0.271650  -0.081    0.936    
## USYes        1.200573   0.259042   4.635 4.86e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.472 on 396 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2335 
## F-statistic: 41.52 on 3 and 396 DF,  p-value: < 2.2e-16

2B) Provide an interpretation of each coefficient in the model. Be careful - some of the variables in the model are qualitative!

# I believe Urban and US are both qualitative variables. Sales slope coefficient is rather high, while the other 3 variables' slopes are relatively low (although for Urban and US that is likely in part due to them being qualitative). The standard errors are all small, implying each data set is made up of small values. The p-values are extremely small for all but Urban, implying that there is a significant difference or influence between at least two variables.

2C) Write out the model in equation form, being careful to handle the qualitative variables properly. (Hint: You can write seperate equations)

#Sales = Bsales+Bprice1*Xprice1+Bprice2*Xprice2+Bprice3*Xprice3+....+Bpricen*Xpricen
#Sales = Bsales+BurbanY1*XurbanY1+BurbanY2*XurbanY2+BurbanY3*XurbanY3+...+BurbanYn*XurbanYn
#Sales = Bsales+BusY1*XusY1+BusY2*XusY2+BusY3*XusY3+...+BusYn*XusYn
#Sales = Bsales+BurbanN1*XurbanN1+BurbanN2*XurbanN2+BurbanN3*XurbanN3+...+BurbanNn*XurbanNn
#Sales = Bsales+BusN1*XusN1+BusN2*XusN2+BusN3*XusN3+...+BusNn*XusNn

2D) For which of the predictors can you reject the null hypothesis H0 : βj = 0?

#Price, and USYes.

#Price, and USYes.

2E) On the basis of your response to the previous question, fit a smaller model that only uses the predictors for which there is evidence of association with the outcome.

carMod2<-lm(Sales~Price+US, data=Carseats)
summary(carMod2)
## 
## Call:
## lm(formula = Sales ~ Price + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9269 -1.6286 -0.0574  1.5766  7.0515 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.03079    0.63098  20.652  < 2e-16 ***
## Price       -0.05448    0.00523 -10.416  < 2e-16 ***
## USYes        1.19964    0.25846   4.641 4.71e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.469 on 397 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2354 
## F-statistic: 62.43 on 2 and 397 DF,  p-value: < 2.2e-16

2F) How well do the models in (a) and (e) fit the data?

#carMod2 is a better fit than carMod to the data because it only includes predictors that affect the response.

2G) Using the model from (e), obtain the 95% confidence intervals for the coefficient(s).

confint(carMod2)
##                   2.5 %      97.5 %
## (Intercept) 11.79032020 14.27126531
## Price       -0.06475984 -0.04419543
## USYes        0.69151957  1.70776632