Exam # 1: Quantitative Geography Fall 2016

Regina Mendicino

date()
## [1] "Fri Oct 07 11:51:57 2016"

Due Time: 1:45pm Each question is worth 20 points.

1 The average rainfall (in units of inches) over Florida during the month of June for the years 2001-2012 are in order below.

8.6, 10.3, 11.0, 8.2, 11.8 5.7 5.9 6.9 6.1 5.4 4.9 13.1

  1. Create a vector object with the above values as elements.
rainfall = c(8.6, 10.3, 11.0, 8.2, 11.8, 5.7, 5.9, 6.9, 6.1, 5.4, 4.9, 13.1)
rainfall
##  [1]  8.6 10.3 11.0  8.2 11.8  5.7  5.9  6.9  6.1  5.4  4.9 13.1
  1. What is the standard deviation of the June rainfall over these years?
sd(rainfall)
## [1] 2.791695
  1. How many Junes had rainfall exceeding 6 inches?
sum(rainfall > 6)
## [1] 8
  1. Compute the rainfall departure from the 12-year June mean for each June.
rainfall - mean(rainfall)
##  [1]  0.44166667  2.14166667  2.84166667  0.04166667  3.64166667
##  [6] -2.45833333 -2.25833333 -1.25833333 -2.05833333 -2.75833333
## [11] -3.25833333  4.94166667
  1. What is the average June rainfall for years that are above the 12-year June mean?
rfmean = mean(rainfall)
rfmean
## [1] 8.158333
mean(rainfall > rfmean)
## [1] 0.5

2 Create a vector containing 100 random numbers generated from a log normal distribution (rlnorm).

rn = rlnorm(100)
rn
##   [1]  1.9076100  0.8301482  1.7045232  2.6597569  1.8360573  0.9461888
##   [7]  0.2829647  2.2141570  0.3967021  1.1304586  0.6316042  0.3326914
##  [13]  0.5703098  4.6465236  0.7648833  1.3089663  0.3026619  1.1312956
##  [19]  0.9748449  0.2614919  0.7227911  2.4597611  0.8020379  0.3946221
##  [25]  0.8659235  0.7447041  0.2392601  4.0023923  0.2422225  0.1574863
##  [31]  0.6272363  0.7563500  0.8696872  1.1937493  3.4637999  0.1246687
##  [37]  1.0547064  0.7582225  1.3182692  0.9747678  0.3563878  2.8719364
##  [43]  3.2247906  1.5603740  3.7926602  5.0947393  1.3913861  2.6263764
##  [49]  3.8859923  0.5994645  0.7571952  0.3623959  0.4501997  0.9546799
##  [55]  0.5671519  0.8291926  2.3385574  3.5672931  0.4417361  1.2352770
##  [61]  1.2078044  0.5288022  0.7558515  0.3294109  1.5075739  1.4782575
##  [67]  0.1912092  0.1593220  6.5593225  0.6158932  1.3039234  1.4552446
##  [73]  0.4444017  4.1574914  0.8528755  0.7380761  0.6374757  1.3208160
##  [79]  0.5317708  0.4617126  0.3688783  0.9526525  4.6065031  3.1644950
##  [85]  2.1025942  0.6997556  2.5792749  2.7365112 13.0799535  2.4786776
##  [91]  1.2357507  0.6904712  1.5323384  0.9251514  0.8898920  3.2820426
##  [97]  0.4080396  1.0019664  0.2145028  0.1317975
  1. Create a density plot from the set of numbers.
plot(rn)

  1. Compute the mean, median, IQR, 75, 85, and 95th percentile values from the set of numbers.
mean(rn)
## [1] 1.518328
median(rn)
## [1] 0.9356701
IQR(rn)
## [1] 1.295639
quantile(rn, .75)
##      75% 
## 1.853945
quantile(rn, .85)
##      85% 
## 2.756825
quantile(rn, .95)
##      95% 
## 4.179942

3 The data frame carbon (UsingR) contains a list of carbon monoxide levels at three different measuring sites.

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.5
library(datasets)
CO2
##    Plant        Type  Treatment conc uptake
## 1    Qn1      Quebec nonchilled   95   16.0
## 2    Qn1      Quebec nonchilled  175   30.4
## 3    Qn1      Quebec nonchilled  250   34.8
## 4    Qn1      Quebec nonchilled  350   37.2
## 5    Qn1      Quebec nonchilled  500   35.3
## 6    Qn1      Quebec nonchilled  675   39.2
## 7    Qn1      Quebec nonchilled 1000   39.7
## 8    Qn2      Quebec nonchilled   95   13.6
## 9    Qn2      Quebec nonchilled  175   27.3
## 10   Qn2      Quebec nonchilled  250   37.1
## 11   Qn2      Quebec nonchilled  350   41.8
## 12   Qn2      Quebec nonchilled  500   40.6
## 13   Qn2      Quebec nonchilled  675   41.4
## 14   Qn2      Quebec nonchilled 1000   44.3
## 15   Qn3      Quebec nonchilled   95   16.2
## 16   Qn3      Quebec nonchilled  175   32.4
## 17   Qn3      Quebec nonchilled  250   40.3
## 18   Qn3      Quebec nonchilled  350   42.1
## 19   Qn3      Quebec nonchilled  500   42.9
## 20   Qn3      Quebec nonchilled  675   43.9
## 21   Qn3      Quebec nonchilled 1000   45.5
## 22   Qc1      Quebec    chilled   95   14.2
## 23   Qc1      Quebec    chilled  175   24.1
## 24   Qc1      Quebec    chilled  250   30.3
## 25   Qc1      Quebec    chilled  350   34.6
## 26   Qc1      Quebec    chilled  500   32.5
## 27   Qc1      Quebec    chilled  675   35.4
## 28   Qc1      Quebec    chilled 1000   38.7
## 29   Qc2      Quebec    chilled   95    9.3
## 30   Qc2      Quebec    chilled  175   27.3
## 31   Qc2      Quebec    chilled  250   35.0
## 32   Qc2      Quebec    chilled  350   38.8
## 33   Qc2      Quebec    chilled  500   38.6
## 34   Qc2      Quebec    chilled  675   37.5
## 35   Qc2      Quebec    chilled 1000   42.4
## 36   Qc3      Quebec    chilled   95   15.1
## 37   Qc3      Quebec    chilled  175   21.0
## 38   Qc3      Quebec    chilled  250   38.1
## 39   Qc3      Quebec    chilled  350   34.0
## 40   Qc3      Quebec    chilled  500   38.9
## 41   Qc3      Quebec    chilled  675   39.6
## 42   Qc3      Quebec    chilled 1000   41.4
## 43   Mn1 Mississippi nonchilled   95   10.6
## 44   Mn1 Mississippi nonchilled  175   19.2
## 45   Mn1 Mississippi nonchilled  250   26.2
## 46   Mn1 Mississippi nonchilled  350   30.0
## 47   Mn1 Mississippi nonchilled  500   30.9
## 48   Mn1 Mississippi nonchilled  675   32.4
## 49   Mn1 Mississippi nonchilled 1000   35.5
## 50   Mn2 Mississippi nonchilled   95   12.0
## 51   Mn2 Mississippi nonchilled  175   22.0
## 52   Mn2 Mississippi nonchilled  250   30.6
## 53   Mn2 Mississippi nonchilled  350   31.8
## 54   Mn2 Mississippi nonchilled  500   32.4
## 55   Mn2 Mississippi nonchilled  675   31.1
## 56   Mn2 Mississippi nonchilled 1000   31.5
## 57   Mn3 Mississippi nonchilled   95   11.3
## 58   Mn3 Mississippi nonchilled  175   19.4
## 59   Mn3 Mississippi nonchilled  250   25.8
## 60   Mn3 Mississippi nonchilled  350   27.9
## 61   Mn3 Mississippi nonchilled  500   28.5
## 62   Mn3 Mississippi nonchilled  675   28.1
## 63   Mn3 Mississippi nonchilled 1000   27.8
## 64   Mc1 Mississippi    chilled   95   10.5
## 65   Mc1 Mississippi    chilled  175   14.9
## 66   Mc1 Mississippi    chilled  250   18.1
## 67   Mc1 Mississippi    chilled  350   18.9
## 68   Mc1 Mississippi    chilled  500   19.5
## 69   Mc1 Mississippi    chilled  675   22.2
## 70   Mc1 Mississippi    chilled 1000   21.9
## 71   Mc2 Mississippi    chilled   95    7.7
## 72   Mc2 Mississippi    chilled  175   11.4
## 73   Mc2 Mississippi    chilled  250   12.3
## 74   Mc2 Mississippi    chilled  350   13.0
## 75   Mc2 Mississippi    chilled  500   12.5
## 76   Mc2 Mississippi    chilled  675   13.7
## 77   Mc2 Mississippi    chilled 1000   14.4
## 78   Mc3 Mississippi    chilled   95   10.6
## 79   Mc3 Mississippi    chilled  175   18.0
## 80   Mc3 Mississippi    chilled  250   17.9
## 81   Mc3 Mississippi    chilled  350   17.9
## 82   Mc3 Mississippi    chilled  500   17.9
## 83   Mc3 Mississippi    chilled  675   18.9
## 84   Mc3 Mississippi    chilled 1000   19.9
  1. How many rows and columns does the data frame contain?
NROW(CO2)
## [1] 84
NCOL(CO2)
## [1] 5
  1. List the names of the columns.
colnames(CO2)
## [1] "Plant"     "Type"      "Treatment" "conc"      "uptake"
  1. List the first six rows the the data frame.
head(CO2)
##   Plant   Type  Treatment conc uptake
## 1   Qn1 Quebec nonchilled   95   16.0
## 2   Qn1 Quebec nonchilled  175   30.4
## 3   Qn1 Quebec nonchilled  250   34.8
## 4   Qn1 Quebec nonchilled  350   37.2
## 5   Qn1 Quebec nonchilled  500   35.3
## 6   Qn1 Quebec nonchilled  675   39.2
  1. Create side-by-side box plots of the monoxide levels from the three sites. Hint: First make the variable ‘site’ a factor variable.g
ggplot(CO2, aes(x = Type, y = uptake)) +
  geom_boxplot() 

4 The mtcars dataset contains fuel consumption and automobile design and performance values for 32 automobiles from the 1973–74 models.

mtcars
##                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
## Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
## Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
## Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
## Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
## Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
## Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
## Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
## Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
## Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
## Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
## Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
## Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
## Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
## Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
## Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
## Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
## Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
## AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
## Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
## Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
## Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
## Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
## Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
## Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
## Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
## Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
## Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
  1. What is the average gas mileage (mpg) grouped by the number of carborators (carb)?

  2. What is the correlation (Pearson) between mileage (mpg) and car weight (wt)?

cor(mtcars$mpg, mtcars$wt)
## [1] -0.8676594
  1. Create a scatter plot with weight (wt) on the horizontal axis and mileage (mpg) on the vertical axis. Include a best-fit straight line on the plot.
ggplot(mtcars, aes(x = mtcars$wt, y = mtcars$mpg)) + 
  geom_point() 

5 The dataset wellbeing (UsingR) contains information from 22 European countries related to what makes people happy. The dataset is from the New Economics Foundation’s National Accounts of Well-Being Well being is on a scale from 0 (lowest) to 10 (highest). GDP is gross domestic product per person (US$).

library(UsingR)
## Warning: package 'UsingR' was built under R version 3.2.5
## Loading required package: MASS
## Loading required package: HistData
## Warning: package 'HistData' was built under R version 3.2.5
## Loading required package: Hmisc
## Warning: package 'Hmisc' was built under R version 3.2.5
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Warning: package 'Formula' was built under R version 3.2.5
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, round.POSIXt, trunc.POSIXt, units
## 
## Attaching package: 'UsingR'
## The following object is masked from 'package:survival':
## 
##     cancer
wellbeing
##           Country Well.being       GDP Equality Food.consumption
## 1         Austria       5.37 26171.691 70.85000          3760.36
## 2         Belgium       5.04 24512.413 67.03000          3674.95
## 3        Bulgaria       4.59  2332.363 69.41667          2749.46
## 4          Cyprus       5.12 14719.258       NA          3202.02
## 5         Denmark       5.93 32400.061 75.30000          3404.26
## 6         Estonia       4.80  6570.330 63.50200          3127.11
## 7         Finland       5.39 27495.241 73.12000          3217.47
## 8          France       4.88 23133.351 67.26000          3540.73
## 9         Germany       5.01 24463.846 71.69000          3519.28
## 10        Hungary       4.74  5868.302 71.54400          3463.01
## 11        Ireland       5.44 30669.373 65.72000          3552.36
## 12    Netherlands       5.31 26007.679 69.10000          3217.65
## 13         Norway       5.69 41245.809 74.21000          3421.47
## 14         Poland       4.81  5552.501 65.88333          3394.36
## 15       Portugal       4.89 11716.009 61.55000          3574.31
## 16       Slovakia       4.57  7334.110 72.07167          2904.10
## 17       Slovenia       4.91 12588.108 69.62667          3212.38
## 18          Spain       5.34 16074.462 65.34000          3231.84
## 19         Sweden       5.44 32431.940 75.00000          3111.68
## 20    Switzerland       5.66 37877.182 66.32000          3427.98
## 21        Ukraine       4.39  1037.312 71.77375          3251.21
## 22 United Kingdom       4.98 28913.096 64.03000          3437.22
##    Alcohol.consumption Energy.consumption Family Working.hours Work.income
## 1                13.24          2076.2005 1.4054      31.81731       30.46
## 2                10.77          2189.6082 1.7600      30.21154       31.85
## 3                12.44          1260.1506 1.3900            NA          NA
## 4                 9.26          1912.8753 1.5100            NA          NA
## 5                13.37          1940.1139 1.8500      30.26539       35.45
## 6                15.57          1265.0153 1.5580            NA          NA
## 7                12.52          4041.7323 1.8400      32.95192       29.90
## 8                13.66          2416.8827 1.9500      30.15577       24.90
## 9                12.81          1717.0774 1.3500      27.55192       34.21
## 10               16.27          1147.4479 1.3100      38.25385        6.29
## 11               14.41          1990.1495 2.0600      31.53846       25.96
## 12               10.05          1506.0806 1.7200      26.75000       32.34
## 13                7.81          7298.4971 1.8620      27.08077       41.05
## 14               13.25           686.9205 1.2800      38.17308        4.99
## 15               14.55          1264.2445 1.3900      33.80769        7.65
## 16               13.33           841.5971 1.2300      33.63462          NA
## 17               15.19          1519.9117 1.3300            NA          NA
## 18               11.62          1751.2503 1.3700      31.82115       18.83
## 19               10.10          4602.3431 1.8690      30.30365       31.80
## 20               11.06          2353.3150 1.4300      31.87115       30.67
## 21               15.60           592.6461 1.3000            NA          NA
## 22               13.37          1921.6563 1.7700      32.09038       27.10
##    Health.spending Military.spending
## 1        15.741705         0.8126331
## 2        14.569664         1.0770664
## 3        11.422118         2.2613561
## 4         6.256808         2.1059625
## 5        16.282838         1.4202110
## 6        10.936640         1.8744255
## 7        12.684467         1.3760444
## 8        16.489788         2.4168083
## 9        17.923930         1.3122866
## 10       11.306848         1.2530279
## 11       16.759486         0.5322577
## 12       16.145314         1.5077302
## 13       17.903669         1.4738621
## 14        9.881070         1.9377735
## 15       14.950302         2.0154748
## 16       13.745857         1.6326807
## 17       13.414136         1.5622485
## 18       15.517984         1.1674735
## 19       13.771747         1.3975303
## 20       18.996177         0.8508913
## 21        8.695101         2.7716469
## 22       15.588776         2.3514279
  1. What country has the lowest well-being score?

  2. For countries with GDP greater than 10000 and working hours less than 30, what is the average well-being score? How many countries make up this average?