auto<-read.csv("Auto.csv", TRUE, na.strings="?")
auto<-na.omit(auto)

#1A :which of the predictorrs are quantitative and which are qualitative?
str(auto)
## 'data.frame':    392 obs. of  9 variables:
##  $ mpg         : num  18 15 18 16 17 15 14 14 14 15 ...
##  $ cylinders   : int  8 8 8 8 8 8 8 8 8 8 ...
##  $ displacement: num  307 350 318 304 302 429 454 440 455 390 ...
##  $ horsepower  : int  130 165 150 150 140 198 220 215 225 190 ...
##  $ weight      : int  3504 3693 3436 3433 3449 4341 4354 4312 4425 3850 ...
##  $ acceleration: num  12 11.5 11 12 10.5 10 9 8.5 10 8.5 ...
##  $ year        : int  70 70 70 70 70 70 70 70 70 70 ...
##  $ origin      : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ name        : Factor w/ 304 levels "amc ambassador brougham",..: 49 36 231 14 161 141 54 223 241 2 ...
##  - attr(*, "na.action")= 'omit' Named int  33 127 331 337 355
##   ..- attr(*, "names")= chr  "33" "127" "331" "337" ...
#1A: Quantitative: mpg, cylinders, displacement, horsepower, weight, acceleration, year, origin, 
#1A: Qualitative: name

#1B: What is the range of each quantitative predictor?

#mpg
range(auto$mpg)
## [1]  9.0 46.6
#cylinders
range(auto$cylinders)
## [1] 3 8
#dispalcement
range(auto$displacement) 
## [1]  68 455
#horsepower     
range(auto$horsepower)
## [1]  46 230
#weight
range(auto$weight)
## [1] 1613 5140
#acceleration
range(auto$acceleration)
## [1]  8.0 24.8
#year
range(auto$year)
## [1] 70 82
#origin
range(auto$origin)
## [1] 1 3
#1C: What is the mean and standard deviation of each quantitative predictor?

#mpg
mean(auto$mpg)
## [1] 23.44592
sd(auto$mpg)
## [1] 7.805007
#cylinders
mean(auto$cylinders)
## [1] 5.471939
sd(auto$cylinders)
## [1] 1.705783
#horsepower
mean(auto$horsepower)
## [1] 104.4694
sd(auto$horsepower)
## [1] 38.49116
#displacement
mean(auto$displacement)
## [1] 194.412
sd(auto$displacement)
## [1] 104.644
#weight
mean(auto$weight)
## [1] 2977.584
sd(auto$weight)
## [1] 849.4026
#acceleration
mean(auto$acceleration)
## [1] 15.54133
sd(auto$acceleration)
## [1] 2.758864
#year
mean(auto$year)
## [1] 75.97959
sd(auto$year)
## [1] 3.683737
#origin
mean(auto$origin)
## [1] 1.576531
sd(auto$origin)
## [1] 0.8055182
#1D: now remove the 10th through 85th observation. What is the range, mean and standard deviation of each predictorin the subset of the data that remains?

auto_matrix<- auto[-c(10:84),-9]
auto_matrix
##      mpg cylinders displacement horsepower weight acceleration year origin
## 1   18.0         8          307        130   3504         12.0   70      1
## 2   15.0         8          350        165   3693         11.5   70      1
## 3   18.0         8          318        150   3436         11.0   70      1
## 4   16.0         8          304        150   3433         12.0   70      1
## 5   17.0         8          302        140   3449         10.5   70      1
## 6   15.0         8          429        198   4341         10.0   70      1
## 7   14.0         8          454        220   4354          9.0   70      1
## 8   14.0         8          440        215   4312          8.5   70      1
## 9   14.0         8          455        225   4425         10.0   70      1
## 86  13.0         8          350        175   4100         13.0   73      1
## 87  14.0         8          304        150   3672         11.5   73      1
## 88  13.0         8          350        145   3988         13.0   73      1
## 89  14.0         8          302        137   4042         14.5   73      1
## 90  15.0         8          318        150   3777         12.5   73      1
## 91  12.0         8          429        198   4952         11.5   73      1
## 92  13.0         8          400        150   4464         12.0   73      1
## 93  13.0         8          351        158   4363         13.0   73      1
## 94  14.0         8          318        150   4237         14.5   73      1
## 95  13.0         8          440        215   4735         11.0   73      1
## 96  12.0         8          455        225   4951         11.0   73      1
## 97  13.0         8          360        175   3821         11.0   73      1
## 98  18.0         6          225        105   3121         16.5   73      1
## 99  16.0         6          250        100   3278         18.0   73      1
## 100 18.0         6          232        100   2945         16.0   73      1
## 101 18.0         6          250         88   3021         16.5   73      1
## 102 23.0         6          198         95   2904         16.0   73      1
## 103 26.0         4           97         46   1950         21.0   73      2
## 104 11.0         8          400        150   4997         14.0   73      1
## 105 12.0         8          400        167   4906         12.5   73      1
## 106 13.0         8          360        170   4654         13.0   73      1
## 107 12.0         8          350        180   4499         12.5   73      1
## 108 18.0         6          232        100   2789         15.0   73      1
## 109 20.0         4           97         88   2279         19.0   73      3
## 110 21.0         4          140         72   2401         19.5   73      1
## 111 22.0         4          108         94   2379         16.5   73      3
## 112 18.0         3           70         90   2124         13.5   73      3
## 113 19.0         4          122         85   2310         18.5   73      1
## 114 21.0         6          155        107   2472         14.0   73      1
## 115 26.0         4           98         90   2265         15.5   73      2
## 116 15.0         8          350        145   4082         13.0   73      1
## 117 16.0         8          400        230   4278          9.5   73      1
## 118 29.0         4           68         49   1867         19.5   73      2
## 119 24.0         4          116         75   2158         15.5   73      2
## 120 20.0         4          114         91   2582         14.0   73      2
## 121 19.0         4          121        112   2868         15.5   73      2
## 122 15.0         8          318        150   3399         11.0   73      1
## 123 24.0         4          121        110   2660         14.0   73      2
## 124 20.0         6          156        122   2807         13.5   73      3
## 125 11.0         8          350        180   3664         11.0   73      1
## 126 20.0         6          198         95   3102         16.5   74      1
## 128 19.0         6          232        100   2901         16.0   74      1
## 129 15.0         6          250        100   3336         17.0   74      1
## 130 31.0         4           79         67   1950         19.0   74      3
## 131 26.0         4          122         80   2451         16.5   74      1
## 132 32.0         4           71         65   1836         21.0   74      3
## 133 25.0         4          140         75   2542         17.0   74      1
## 134 16.0         6          250        100   3781         17.0   74      1
## 135 16.0         6          258        110   3632         18.0   74      1
## 136 18.0         6          225        105   3613         16.5   74      1
## 137 16.0         8          302        140   4141         14.0   74      1
## 138 13.0         8          350        150   4699         14.5   74      1
## 139 14.0         8          318        150   4457         13.5   74      1
## 140 14.0         8          302        140   4638         16.0   74      1
## 141 14.0         8          304        150   4257         15.5   74      1
## 142 29.0         4           98         83   2219         16.5   74      2
## 143 26.0         4           79         67   1963         15.5   74      2
## 144 26.0         4           97         78   2300         14.5   74      2
## 145 31.0         4           76         52   1649         16.5   74      3
## 146 32.0         4           83         61   2003         19.0   74      3
## 147 28.0         4           90         75   2125         14.5   74      1
## 148 24.0         4           90         75   2108         15.5   74      2
## 149 26.0         4          116         75   2246         14.0   74      2
## 150 24.0         4          120         97   2489         15.0   74      3
## 151 26.0         4          108         93   2391         15.5   74      3
## 152 31.0         4           79         67   2000         16.0   74      2
## 153 19.0         6          225         95   3264         16.0   75      1
## 154 18.0         6          250        105   3459         16.0   75      1
## 155 15.0         6          250         72   3432         21.0   75      1
## 156 15.0         6          250         72   3158         19.5   75      1
## 157 16.0         8          400        170   4668         11.5   75      1
## 158 15.0         8          350        145   4440         14.0   75      1
## 159 16.0         8          318        150   4498         14.5   75      1
## 160 14.0         8          351        148   4657         13.5   75      1
## 161 17.0         6          231        110   3907         21.0   75      1
## 162 16.0         6          250        105   3897         18.5   75      1
## 163 15.0         6          258        110   3730         19.0   75      1
## 164 18.0         6          225         95   3785         19.0   75      1
## 165 21.0         6          231        110   3039         15.0   75      1
## 166 20.0         8          262        110   3221         13.5   75      1
## 167 13.0         8          302        129   3169         12.0   75      1
## 168 29.0         4           97         75   2171         16.0   75      3
## 169 23.0         4          140         83   2639         17.0   75      1
## 170 20.0         6          232        100   2914         16.0   75      1
## 171 23.0         4          140         78   2592         18.5   75      1
## 172 24.0         4          134         96   2702         13.5   75      3
## 173 25.0         4           90         71   2223         16.5   75      2
## 174 24.0         4          119         97   2545         17.0   75      3
## 175 18.0         6          171         97   2984         14.5   75      1
## 176 29.0         4           90         70   1937         14.0   75      2
## 177 19.0         6          232         90   3211         17.0   75      1
## 178 23.0         4          115         95   2694         15.0   75      2
## 179 23.0         4          120         88   2957         17.0   75      2
## 180 22.0         4          121         98   2945         14.5   75      2
## 181 25.0         4          121        115   2671         13.5   75      2
## 182 33.0         4           91         53   1795         17.5   75      3
## 183 28.0         4          107         86   2464         15.5   76      2
## 184 25.0         4          116         81   2220         16.9   76      2
## 185 25.0         4          140         92   2572         14.9   76      1
## 186 26.0         4           98         79   2255         17.7   76      1
## 187 27.0         4          101         83   2202         15.3   76      2
## 188 17.5         8          305        140   4215         13.0   76      1
## 189 16.0         8          318        150   4190         13.0   76      1
## 190 15.5         8          304        120   3962         13.9   76      1
## 191 14.5         8          351        152   4215         12.8   76      1
## 192 22.0         6          225        100   3233         15.4   76      1
## 193 22.0         6          250        105   3353         14.5   76      1
## 194 24.0         6          200         81   3012         17.6   76      1
## 195 22.5         6          232         90   3085         17.6   76      1
## 196 29.0         4           85         52   2035         22.2   76      1
## 197 24.5         4           98         60   2164         22.1   76      1
## 198 29.0         4           90         70   1937         14.2   76      2
## 199 33.0         4           91         53   1795         17.4   76      3
## 200 20.0         6          225        100   3651         17.7   76      1
## 201 18.0         6          250         78   3574         21.0   76      1
## 202 18.5         6          250        110   3645         16.2   76      1
## 203 17.5         6          258         95   3193         17.8   76      1
## 204 29.5         4           97         71   1825         12.2   76      2
## 205 32.0         4           85         70   1990         17.0   76      3
## 206 28.0         4           97         75   2155         16.4   76      3
## 207 26.5         4          140         72   2565         13.6   76      1
## 208 20.0         4          130        102   3150         15.7   76      2
## 209 13.0         8          318        150   3940         13.2   76      1
## 210 19.0         4          120         88   3270         21.9   76      2
## 211 19.0         6          156        108   2930         15.5   76      3
## 212 16.5         6          168        120   3820         16.7   76      2
## 213 16.5         8          350        180   4380         12.1   76      1
## 214 13.0         8          350        145   4055         12.0   76      1
## 215 13.0         8          302        130   3870         15.0   76      1
## 216 13.0         8          318        150   3755         14.0   76      1
## 217 31.5         4           98         68   2045         18.5   77      3
## 218 30.0         4          111         80   2155         14.8   77      1
## 219 36.0         4           79         58   1825         18.6   77      2
## 220 25.5         4          122         96   2300         15.5   77      1
## 221 33.5         4           85         70   1945         16.8   77      3
## 222 17.5         8          305        145   3880         12.5   77      1
## 223 17.0         8          260        110   4060         19.0   77      1
## 224 15.5         8          318        145   4140         13.7   77      1
## 225 15.0         8          302        130   4295         14.9   77      1
## 226 17.5         6          250        110   3520         16.4   77      1
## 227 20.5         6          231        105   3425         16.9   77      1
## 228 19.0         6          225        100   3630         17.7   77      1
## 229 18.5         6          250         98   3525         19.0   77      1
## 230 16.0         8          400        180   4220         11.1   77      1
## 231 15.5         8          350        170   4165         11.4   77      1
## 232 15.5         8          400        190   4325         12.2   77      1
## 233 16.0         8          351        149   4335         14.5   77      1
## 234 29.0         4           97         78   1940         14.5   77      2
## 235 24.5         4          151         88   2740         16.0   77      1
## 236 26.0         4           97         75   2265         18.2   77      3
## 237 25.5         4          140         89   2755         15.8   77      1
## 238 30.5         4           98         63   2051         17.0   77      1
## 239 33.5         4           98         83   2075         15.9   77      1
## 240 30.0         4           97         67   1985         16.4   77      3
## 241 30.5         4           97         78   2190         14.1   77      2
## 242 22.0         6          146         97   2815         14.5   77      3
## 243 21.5         4          121        110   2600         12.8   77      2
## 244 21.5         3           80        110   2720         13.5   77      3
## 245 43.1         4           90         48   1985         21.5   78      2
## 246 36.1         4           98         66   1800         14.4   78      1
## 247 32.8         4           78         52   1985         19.4   78      3
## 248 39.4         4           85         70   2070         18.6   78      3
## 249 36.1         4           91         60   1800         16.4   78      3
## 250 19.9         8          260        110   3365         15.5   78      1
## 251 19.4         8          318        140   3735         13.2   78      1
## 252 20.2         8          302        139   3570         12.8   78      1
## 253 19.2         6          231        105   3535         19.2   78      1
## 254 20.5         6          200         95   3155         18.2   78      1
## 255 20.2         6          200         85   2965         15.8   78      1
## 256 25.1         4          140         88   2720         15.4   78      1
## 257 20.5         6          225        100   3430         17.2   78      1
## 258 19.4         6          232         90   3210         17.2   78      1
## 259 20.6         6          231        105   3380         15.8   78      1
## 260 20.8         6          200         85   3070         16.7   78      1
## 261 18.6         6          225        110   3620         18.7   78      1
## 262 18.1         6          258        120   3410         15.1   78      1
## 263 19.2         8          305        145   3425         13.2   78      1
## 264 17.7         6          231        165   3445         13.4   78      1
## 265 18.1         8          302        139   3205         11.2   78      1
## 266 17.5         8          318        140   4080         13.7   78      1
## 267 30.0         4           98         68   2155         16.5   78      1
## 268 27.5         4          134         95   2560         14.2   78      3
## 269 27.2         4          119         97   2300         14.7   78      3
## 270 30.9         4          105         75   2230         14.5   78      1
## 271 21.1         4          134         95   2515         14.8   78      3
## 272 23.2         4          156        105   2745         16.7   78      1
## 273 23.8         4          151         85   2855         17.6   78      1
## 274 23.9         4          119         97   2405         14.9   78      3
## 275 20.3         5          131        103   2830         15.9   78      2
## 276 17.0         6          163        125   3140         13.6   78      2
## 277 21.6         4          121        115   2795         15.7   78      2
## 278 16.2         6          163        133   3410         15.8   78      2
## 279 31.5         4           89         71   1990         14.9   78      2
## 280 29.5         4           98         68   2135         16.6   78      3
## 281 21.5         6          231        115   3245         15.4   79      1
## 282 19.8         6          200         85   2990         18.2   79      1
## 283 22.3         4          140         88   2890         17.3   79      1
## 284 20.2         6          232         90   3265         18.2   79      1
## 285 20.6         6          225        110   3360         16.6   79      1
## 286 17.0         8          305        130   3840         15.4   79      1
## 287 17.6         8          302        129   3725         13.4   79      1
## 288 16.5         8          351        138   3955         13.2   79      1
## 289 18.2         8          318        135   3830         15.2   79      1
## 290 16.9         8          350        155   4360         14.9   79      1
## 291 15.5         8          351        142   4054         14.3   79      1
## 292 19.2         8          267        125   3605         15.0   79      1
## 293 18.5         8          360        150   3940         13.0   79      1
## 294 31.9         4           89         71   1925         14.0   79      2
## 295 34.1         4           86         65   1975         15.2   79      3
## 296 35.7         4           98         80   1915         14.4   79      1
## 297 27.4         4          121         80   2670         15.0   79      1
## 298 25.4         5          183         77   3530         20.1   79      2
## 299 23.0         8          350        125   3900         17.4   79      1
## 300 27.2         4          141         71   3190         24.8   79      2
## 301 23.9         8          260         90   3420         22.2   79      1
## 302 34.2         4          105         70   2200         13.2   79      1
## 303 34.5         4          105         70   2150         14.9   79      1
## 304 31.8         4           85         65   2020         19.2   79      3
## 305 37.3         4           91         69   2130         14.7   79      2
## 306 28.4         4          151         90   2670         16.0   79      1
## 307 28.8         6          173        115   2595         11.3   79      1
## 308 26.8         6          173        115   2700         12.9   79      1
## 309 33.5         4          151         90   2556         13.2   79      1
## 310 41.5         4           98         76   2144         14.7   80      2
## 311 38.1         4           89         60   1968         18.8   80      3
## 312 32.1         4           98         70   2120         15.5   80      1
## 313 37.2         4           86         65   2019         16.4   80      3
## 314 28.0         4          151         90   2678         16.5   80      1
## 315 26.4         4          140         88   2870         18.1   80      1
## 316 24.3         4          151         90   3003         20.1   80      1
## 317 19.1         6          225         90   3381         18.7   80      1
## 318 34.3         4           97         78   2188         15.8   80      2
## 319 29.8         4          134         90   2711         15.5   80      3
## 320 31.3         4          120         75   2542         17.5   80      3
## 321 37.0         4          119         92   2434         15.0   80      3
## 322 32.2         4          108         75   2265         15.2   80      3
## 323 46.6         4           86         65   2110         17.9   80      3
## 324 27.9         4          156        105   2800         14.4   80      1
## 325 40.8         4           85         65   2110         19.2   80      3
## 326 44.3         4           90         48   2085         21.7   80      2
## 327 43.4         4           90         48   2335         23.7   80      2
## 328 36.4         5          121         67   2950         19.9   80      2
## 329 30.0         4          146         67   3250         21.8   80      2
## 330 44.6         4           91         67   1850         13.8   80      3
## 332 33.8         4           97         67   2145         18.0   80      3
## 333 29.8         4           89         62   1845         15.3   80      2
## 334 32.7         6          168        132   2910         11.4   80      3
## 335 23.7         3           70        100   2420         12.5   80      3
## 336 35.0         4          122         88   2500         15.1   80      2
## 338 32.4         4          107         72   2290         17.0   80      3
## 339 27.2         4          135         84   2490         15.7   81      1
## 340 26.6         4          151         84   2635         16.4   81      1
## 341 25.8         4          156         92   2620         14.4   81      1
## 342 23.5         6          173        110   2725         12.6   81      1
## 343 30.0         4          135         84   2385         12.9   81      1
## 344 39.1         4           79         58   1755         16.9   81      3
## 345 39.0         4           86         64   1875         16.4   81      1
## 346 35.1         4           81         60   1760         16.1   81      3
## 347 32.3         4           97         67   2065         17.8   81      3
## 348 37.0         4           85         65   1975         19.4   81      3
## 349 37.7         4           89         62   2050         17.3   81      3
## 350 34.1         4           91         68   1985         16.0   81      3
## 351 34.7         4          105         63   2215         14.9   81      1
## 352 34.4         4           98         65   2045         16.2   81      1
## 353 29.9         4           98         65   2380         20.7   81      1
## 354 33.0         4          105         74   2190         14.2   81      2
## 356 33.7         4          107         75   2210         14.4   81      3
## 357 32.4         4          108         75   2350         16.8   81      3
## 358 32.9         4          119        100   2615         14.8   81      3
## 359 31.6         4          120         74   2635         18.3   81      3
## 360 28.1         4          141         80   3230         20.4   81      2
## 361 30.7         6          145         76   3160         19.6   81      2
## 362 25.4         6          168        116   2900         12.6   81      3
## 363 24.2         6          146        120   2930         13.8   81      3
## 364 22.4         6          231        110   3415         15.8   81      1
## 365 26.6         8          350        105   3725         19.0   81      1
## 366 20.2         6          200         88   3060         17.1   81      1
## 367 17.6         6          225         85   3465         16.6   81      1
## 368 28.0         4          112         88   2605         19.6   82      1
## 369 27.0         4          112         88   2640         18.6   82      1
## 370 34.0         4          112         88   2395         18.0   82      1
## 371 31.0         4          112         85   2575         16.2   82      1
## 372 29.0         4          135         84   2525         16.0   82      1
## 373 27.0         4          151         90   2735         18.0   82      1
## 374 24.0         4          140         92   2865         16.4   82      1
## 375 36.0         4          105         74   1980         15.3   82      2
## 376 37.0         4           91         68   2025         18.2   82      3
## 377 31.0         4           91         68   1970         17.6   82      3
## 378 38.0         4          105         63   2125         14.7   82      1
## 379 36.0         4           98         70   2125         17.3   82      1
## 380 36.0         4          120         88   2160         14.5   82      3
## 381 36.0         4          107         75   2205         14.5   82      3
## 382 34.0         4          108         70   2245         16.9   82      3
## 383 38.0         4           91         67   1965         15.0   82      3
## 384 32.0         4           91         67   1965         15.7   82      3
## 385 38.0         4           91         67   1995         16.2   82      3
## 386 25.0         6          181        110   2945         16.4   82      1
## 387 38.0         6          262         85   3015         17.0   82      1
## 388 26.0         4          156         92   2585         14.5   82      1
## 389 22.0         6          232        112   2835         14.7   82      1
## 390 32.0         4          144         96   2665         13.9   82      3
## 391 36.0         4          135         84   2370         13.0   82      1
## 392 27.0         4          151         90   2950         17.3   82      1
## 393 27.0         4          140         86   2790         15.6   82      1
## 394 44.0         4           97         52   2130         24.6   82      2
## 395 32.0         4          135         84   2295         11.6   82      1
## 396 28.0         4          120         79   2625         18.6   82      1
## 397 31.0         4          119         82   2720         19.4   82      1
range(auto_matrix$mpg)
## [1] 11.0 46.6
range(auto_matrix$cylinders)
## [1] 3 8
range(auto_matrix$displacement)
## [1]  68 455
range(auto_matrix$horsepower)
## [1]  46 230
range(auto_matrix$weight)
## [1] 1649 4997
range(auto_matrix$acceleration)
## [1]  8.5 24.8
range(auto_matrix$year)
## [1] 70 82
range(auto_matrix$origin)
## [1] 1 3
mean(auto_matrix$mpg)
## [1] 24.36845
mean(auto_matrix$cylinders)
## [1] 5.381703
mean(auto_matrix$displacement)
## [1] 187.7539
mean(auto_matrix$horsepower)
## [1] 100.9558
mean(auto_matrix$weight)
## [1] 2939.644
mean(auto_matrix$acceleration)
## [1] 15.7183
mean(auto_matrix$year)
## [1] 77.13249
mean(auto_matrix$origin)
## [1] 1.599369
sd(auto_matrix$mpg)
## [1] 7.880898
sd(auto_matrix$cylinders)
## [1] 1.658135
sd(auto_matrix$displacement)
## [1] 99.93949
sd(auto_matrix$horsepower)
## [1] 35.89557
sd(auto_matrix$weight)
## [1] 812.6496
sd(auto_matrix$acceleration)
## [1] 2.693813
sd(auto_matrix$year)
## [1] 3.110026
sd(auto_matrix$origin)
## [1] 0.8193079
#1E create at least 3 plots, highlighting relationships among predictors. Comment on your findings.
#using pairs() allows you to see all plots for the data 
pairs(auto_matrix)

#as.factor turns into a categorical variable 
auto$cylinders<-as.factor(auto$cylinders)

#if you want to clean up the labels you can use xlab= and ylab= with quotations. 
#add main title using the function main=""
#create a regression line (line of best fit) using the function lm(dependent~independent)

plot(auto$cylinders, auto$mpg, xlab = "Cylinders", ylab= "MPG", main = "MPG by Cylinders")

#initially we see an uptick in miles per gallon between the three cylinder cars and the four cylinder ones, showing a higher mean mpg and a higher upper bound on the four cylinder models. This may be becasue four cylinder models ae extremely popular and there are a variety of them, all varying in mpg efficiency. However, as is clear, the six and eight cylinder models have a pretty severe drop off in miles per gallon, as the engines are more powerful, yet are lacking the efficiency in their gas mileage. This is seen through the lower mean mpg as well as much smaler range in mpg as the four cylinder ones (which show a higher variannce in mpg, especially between the central point and the upper bound - showing a higher liklihood that four cylinder cars will have average to well-above-average gas mileage). 

plot(auto$year, auto$mpg, xlab= "Year", ylab= "MPG", main = "MPG by Year")
abline(lm(auto$mpg~auto$year))

#The graphic shows that there is a trend of car models becoming mroe efficeint with regards to gas mileage as they are newer. This is seen through the general trend upward of the data, as well as the higher upward bound in MPG. This makes rational sense as well becasue newer cars tend to have better gas mileage because they lack the damage and wear and tear which lead to a drop in eficiency, and also account for the technologlical advancements made to cars in newer models.

plot(auto$weight, auto$acceleration, xlab= "Weight", ylab="Acceleration", main = "Acceleration by Weight")
abline(lm(auto$acceleration~auto$weight))

#As is clear through the general upward trend in the data, as cars get heavier, acceleration decreases. This seems to fit intuition regarding the relationship between weight and acceleration as a car which is heavier would require more fuel and more power to move it the same distance as one which is lighter.Interestingly, a multi-variable analysis may show that those cars which are heavier may well have lower mpg, and might require more cylinders to accomodate for the loss in acceleration. 

#1F: Suppose we wanted to predict mpg on the basis of any of the other variables. Which variables might be useful in doing so?

#According to my plots I argue that all three of them should be accurate predictors of a cars mpg. my reasonign for this is as follows. As I stated with regards to the relationship between mpg and year, it is evident that as cars get older they become less fuel efficient. The general upward trend throughout the twelve year period seems to be a good enough indicator that, on average (mean or median), a car that comes out in 1983 should be more efficient than one from '75, or even one from '82. Additionally, I argue that the cylinder variable is a good predictor of miles per gallon, considering the mean gas mileage is drstically different between cars with 4 cylinders and all the rest. If one were to predict whether a 4 clinder car from 1983 and a 3 cylinder from the same year would have better gas mileage, it is most likely that the 4 cylinder one would have the best gas mileage. Although the graphic for accelration by weight does not necessarily cover the mpg for these cars, I beleive it implies a trend in mpg as well. As weight increases the power needed to move that heavier object must increase, and beacause more power is needed, it is likely this car would need more cylinder to produce this power, meaning that the cars whcih are heavier and have more cylinders are likely to have lower mpg than the lighter 4 cylinder models. 
#2A/B:

new_hope<-c(460.998, 314.4)
empire_strikes <- c(290.475, 247.900)
return_jedi<-c(309.306, 165.8)

region<-c("US", "non-US")
titles<-c("A New Hope", "The Empire Strikes Back", "Return of the Jedi")
starWars<-rbind(new_hope, empire_strikes, return_jedi)
starWars
##                   [,1]  [,2]
## new_hope       460.998 314.4
## empire_strikes 290.475 247.9
## return_jedi    309.306 165.8
rownames(starWars)<- c("A New Hope", "The Empire Strikes Back", "Return of the Jedi")
colnames(starWars)<-c("US", "non-US")
starWars
##                              US non-US
## A New Hope              460.998  314.4
## The Empire Strikes Back 290.475  247.9
## Return of the Jedi      309.306  165.8
#2c: calculate the worldwide box office for each of these movies using the rowSums function. Name and output this vector.
ww_box<- rowSums (starWars)
ww_box
##              A New Hope The Empire Strikes Back      Return of the Jedi 
##                 775.398                 538.375                 475.106
#2D: now we want to add a column to our matrix for worldwide sales. You can do this by using the cbind() function.

ww_matrix<- cbind(starWars,ww_box)
ww_matrix
##                              US non-US  ww_box
## A New Hope              460.998  314.4 775.398
## The Empire Strikes Back 290.475  247.9 538.375
## Return of the Jedi      309.306  165.8 475.106
colnames(ww_matrix)<- c("US", "non-US", "WW Box-office")

#2E: make another matrix for the prequels calles "starWars2"

phantom_menace <- c(474.5, 552.5)
attack_clones <- c(310.7, 338.7)
revenge_sith <- c(380.3, 468.5)
prequels<-rbind(phantom_menace, attack_clones, revenge_sith)
prequels
##                 [,1]  [,2]
## phantom_menace 474.5 552.5
## attack_clones  310.7 338.7
## revenge_sith   380.3 468.5
ww_box2<- rowSums(prequels)
starWars2<- cbind(prequels, ww_box2)

rownames(starWars2)<- c("The Phantom Menace", "Attack of the Clones", "Revenge of the Sith")
colnames(starWars2)<- c("US", "non-US", "WW Box-office")
starWars2
##                         US non-US WW Box-office
## The Phantom Menace   474.5  552.5        1027.0
## Attack of the Clones 310.7  338.7         649.4
## Revenge of the Sith  380.3  468.5         848.8
#2F: create one big matrix that combines all the movies names allstarwars
allstarwars<-rbind(ww_matrix, starWars2)
allstarwars
##                              US non-US WW Box-office
## A New Hope              460.998  314.4       775.398
## The Empire Strikes Back 290.475  247.9       538.375
## Return of the Jedi      309.306  165.8       475.106
## The Phantom Menace      474.500  552.5      1027.000
## Attack of the Clones    310.700  338.7       649.400
## Revenge of the Sith     380.300  468.5       848.800
#2F: usig the colsums() function, find the total non-us revenue for all of the movies.
colSums(allstarwars)
##            US        non-US WW Box-office 
##      2226.279      2087.800      4314.079
#3a: Use the read.csv function to read the data into R.

college<-read.csv("http://faculty.marshall.usc.edu/gareth-james/ISL/
College.csv",header=TRUE)

#3b: use the View() function to view the data. Note that the first column is just the University names.
View(college)
college<- college[,-1]
View(college)

#3c

#A:
summary(college)
##  Private        Apps           Accept          Enroll       Top10perc    
##  No :212   Min.   :   81   Min.   :   72   Min.   :  35   Min.   : 1.00  
##  Yes:565   1st Qu.:  776   1st Qu.:  604   1st Qu.: 242   1st Qu.:15.00  
##            Median : 1558   Median : 1110   Median : 434   Median :23.00  
##            Mean   : 3002   Mean   : 2019   Mean   : 780   Mean   :27.56  
##            3rd Qu.: 3624   3rd Qu.: 2424   3rd Qu.: 902   3rd Qu.:35.00  
##            Max.   :48094   Max.   :26330   Max.   :6392   Max.   :96.00  
##    Top25perc      F.Undergrad     P.Undergrad         Outstate    
##  Min.   :  9.0   Min.   :  139   Min.   :    1.0   Min.   : 2340  
##  1st Qu.: 41.0   1st Qu.:  992   1st Qu.:   95.0   1st Qu.: 7320  
##  Median : 54.0   Median : 1707   Median :  353.0   Median : 9990  
##  Mean   : 55.8   Mean   : 3700   Mean   :  855.3   Mean   :10441  
##  3rd Qu.: 69.0   3rd Qu.: 4005   3rd Qu.:  967.0   3rd Qu.:12925  
##  Max.   :100.0   Max.   :31643   Max.   :21836.0   Max.   :21700  
##    Room.Board       Books           Personal         PhD        
##  Min.   :1780   Min.   :  96.0   Min.   : 250   Min.   :  8.00  
##  1st Qu.:3597   1st Qu.: 470.0   1st Qu.: 850   1st Qu.: 62.00  
##  Median :4200   Median : 500.0   Median :1200   Median : 75.00  
##  Mean   :4358   Mean   : 549.4   Mean   :1341   Mean   : 72.66  
##  3rd Qu.:5050   3rd Qu.: 600.0   3rd Qu.:1700   3rd Qu.: 85.00  
##  Max.   :8124   Max.   :2340.0   Max.   :6800   Max.   :103.00  
##     Terminal       S.F.Ratio      perc.alumni        Expend     
##  Min.   : 24.0   Min.   : 2.50   Min.   : 0.00   Min.   : 3186  
##  1st Qu.: 71.0   1st Qu.:11.50   1st Qu.:13.00   1st Qu.: 6751  
##  Median : 82.0   Median :13.60   Median :21.00   Median : 8377  
##  Mean   : 79.7   Mean   :14.09   Mean   :22.74   Mean   : 9660  
##  3rd Qu.: 92.0   3rd Qu.:16.50   3rd Qu.:31.00   3rd Qu.:10830  
##  Max.   :100.0   Max.   :39.80   Max.   :64.00   Max.   :56233  
##    Grad.Rate     
##  Min.   : 10.00  
##  1st Qu.: 53.00  
##  Median : 65.00  
##  Mean   : 65.46  
##  3rd Qu.: 78.00  
##  Max.   :118.00
#B:
pairs(college[,1:10])

#C:
#plot the private:
plot(college[,1], main="Private")

#plot Out of State
boxplot(college[,9], main= "Out of State")

#D:
Elite <- rep("No", nrow(college))
Elite[college$Top10perc > 50] = "Yes"
Elite <- as.factor(Elite)
college <- data.frame(college, Elite)
summary(college)
##  Private        Apps           Accept          Enroll       Top10perc    
##  No :212   Min.   :   81   Min.   :   72   Min.   :  35   Min.   : 1.00  
##  Yes:565   1st Qu.:  776   1st Qu.:  604   1st Qu.: 242   1st Qu.:15.00  
##            Median : 1558   Median : 1110   Median : 434   Median :23.00  
##            Mean   : 3002   Mean   : 2019   Mean   : 780   Mean   :27.56  
##            3rd Qu.: 3624   3rd Qu.: 2424   3rd Qu.: 902   3rd Qu.:35.00  
##            Max.   :48094   Max.   :26330   Max.   :6392   Max.   :96.00  
##    Top25perc      F.Undergrad     P.Undergrad         Outstate    
##  Min.   :  9.0   Min.   :  139   Min.   :    1.0   Min.   : 2340  
##  1st Qu.: 41.0   1st Qu.:  992   1st Qu.:   95.0   1st Qu.: 7320  
##  Median : 54.0   Median : 1707   Median :  353.0   Median : 9990  
##  Mean   : 55.8   Mean   : 3700   Mean   :  855.3   Mean   :10441  
##  3rd Qu.: 69.0   3rd Qu.: 4005   3rd Qu.:  967.0   3rd Qu.:12925  
##  Max.   :100.0   Max.   :31643   Max.   :21836.0   Max.   :21700  
##    Room.Board       Books           Personal         PhD        
##  Min.   :1780   Min.   :  96.0   Min.   : 250   Min.   :  8.00  
##  1st Qu.:3597   1st Qu.: 470.0   1st Qu.: 850   1st Qu.: 62.00  
##  Median :4200   Median : 500.0   Median :1200   Median : 75.00  
##  Mean   :4358   Mean   : 549.4   Mean   :1341   Mean   : 72.66  
##  3rd Qu.:5050   3rd Qu.: 600.0   3rd Qu.:1700   3rd Qu.: 85.00  
##  Max.   :8124   Max.   :2340.0   Max.   :6800   Max.   :103.00  
##     Terminal       S.F.Ratio      perc.alumni        Expend     
##  Min.   : 24.0   Min.   : 2.50   Min.   : 0.00   Min.   : 3186  
##  1st Qu.: 71.0   1st Qu.:11.50   1st Qu.:13.00   1st Qu.: 6751  
##  Median : 82.0   Median :13.60   Median :21.00   Median : 8377  
##  Mean   : 79.7   Mean   :14.09   Mean   :22.74   Mean   : 9660  
##  3rd Qu.: 92.0   3rd Qu.:16.50   3rd Qu.:31.00   3rd Qu.:10830  
##  Max.   :100.0   Max.   :39.80   Max.   :64.00   Max.   :56233  
##    Grad.Rate      Elite    
##  Min.   : 10.00   No :699  
##  1st Qu.: 53.00   Yes: 78  
##  Median : 65.00            
##  Mean   : 65.46            
##  3rd Qu.: 78.00            
##  Max.   :118.00
#you can see that there are 78 Elite universities


#plot Out of State
boxplot(college[,9], main="Out of State")

#plot Elite schools
plot(college[,19], main = "Elite")