knitr::opts_chunk$set(echo = TRUE,
                      fig.width=8, 
                      fig.height=5,
                      echo = F,
                      warning = F,
                      message = F)


# Load packages
pacman::p_load(dplyr, ggplot2, tidyverse, ggthemes, maps, ggrepel, rpart, rpart.plot, caret, FNN, skimr, broom, GGally)

# Set default theme
theme_set(theme_bw())

# Read in files
parks <- read.csv('parks.csv') |>
  janitor::clean_names()

species <- read.csv('species.csv') |>
  janitor::clean_names() 

tibble(species)
## # A tibble: 119,248 × 14
##    species_id park_name       category order family scientific_name common_names
##    <chr>      <chr>           <chr>    <chr> <chr>  <chr>           <chr>       
##  1 ACAD-1000  Acadia Nationa… Mammal   Arti… Cervi… Alces alces     Moose       
##  2 ACAD-1001  Acadia Nationa… Mammal   Arti… Cervi… Odocoileus vir… Northern Wh…
##  3 ACAD-1002  Acadia Nationa… Mammal   Carn… Canid… Canis latrans   Coyote, Eas…
##  4 ACAD-1003  Acadia Nationa… Mammal   Carn… Canid… Canis lupus     Eastern Tim…
##  5 ACAD-1004  Acadia Nationa… Mammal   Carn… Canid… Vulpes vulpes   Black Fox, …
##  6 ACAD-1005  Acadia Nationa… Mammal   Carn… Felid… Lynx canadensis Canada Lynx 
##  7 ACAD-1006  Acadia Nationa… Mammal   Carn… Felid… Lynx rufus      Bay Lynx, B…
##  8 ACAD-1007  Acadia Nationa… Mammal   Carn… Mephi… Mephitis mephi… Eastern Sku…
##  9 ACAD-1008  Acadia Nationa… Mammal   Carn… Muste… Lutra canadens… Otter, Rive…
## 10 ACAD-1009  Acadia Nationa… Mammal   Carn… Muste… Martes pennanti Blackcat, F…
## # ℹ 119,238 more rows
## # ℹ 7 more variables: record_status <chr>, occurrence <chr>, nativeness <chr>,
## #   abundance <chr>, seasonality <chr>, conservation_status <chr>, x <chr>
tibble(parks)
## # A tibble: 56 × 6
##    park_code park_name                           state  acres latitude longitude
##    <chr>     <chr>                               <chr>  <int>    <dbl>     <dbl>
##  1 ACAD      Acadia National Park                ME     47390     44.4     -68.2
##  2 ARCH      Arches National Park                UT     76519     38.7    -110. 
##  3 BADL      Badlands National Park              SD    242756     43.8    -102. 
##  4 BIBE      Big Bend National Park              TX    801163     29.2    -103. 
##  5 BISC      Biscayne National Park              FL    172924     25.6     -80.1
##  6 BLCA      Black Canyon of the Gunnison Natio… CO     32950     38.6    -108. 
##  7 BRCA      Bryce Canyon National Park          UT     35835     37.6    -112. 
##  8 CANY      Canyonlands National Park           UT    337598     38.2    -110. 
##  9 CARE      Capitol Reef National Park          UT    241904     38.2    -111. 
## 10 CAVE      Carlsbad Caverns National Park      NM     46766     32.2    -104. 
## # ℹ 46 more rows

Data Cleaning

Our data comes from two data sets:

  1. parks: contains general information (size, latitude, longitude, etc.) about each National Park in the United States. This will be largely supplemental, but provides important contextual information we will use later

  2. species: contains a record of each species recorded in a certain National Park. This will be our main data set.

Along with the true taxonomic groupings of order and family, the data also includes a ‘category’ variable, which is not equivalent to any true taxonomic grouping, but instead consists of informal groupings which are recognizable to the layperson. Let’s take a look at them now, since we’ll be using these groups for much of our analysis.

## # A tibble: 14 × 1
##    category           
##    <chr>              
##  1 Algae              
##  2 Amphibian          
##  3 Bird               
##  4 Crab/Lobster/Shrimp
##  5 Fish               
##  6 Fungi              
##  7 Insect             
##  8 Invertebrate       
##  9 Mammal             
## 10 Nonvascular Plant  
## 11 Reptile            
## 12 Slug/Snail         
## 13 Spider/Scorpion    
## 14 Vascular Plant

14 categories, but for our purposes, we only care about the animal diversity of these parks. As such, we will go ahead and remove algae, fungi, Nonvascular plants, and Vascular plants.

As we began analyzing our data, we realized that reporting of insects was inconsistent, and skewed our data heavily in the wrong direction. As such, we decided to limit our scope to vertebrate biodiversity rather than animal diversity. To accomplish this, we removed the insect group which was causing problems, as well as all other invertebrate categories Invertebrate, Crab/Lobster/Shrimp, Slug/Snail and Spider/Scorpion

We’ll also implement a handful of other changes to our data: removing record status and seasonality, which are not useful for our driving question, adding a genus category, which is taken from the scientific name, and shortening the names of parks to remove the suffix for clarity.

## # A tibble: 24,510 × 12
##    species_id park_name category order family genus scientific_name common_names
##    <chr>      <chr>     <chr>    <chr> <chr>  <chr> <chr>           <chr>       
##  1 ACAD-1000  "Acadia " Mammal   Arti… Cervi… Alces Alces alces     Moose       
##  2 ACAD-1001  "Acadia " Mammal   Arti… Cervi… Odoc… Odocoileus vir… Northern Wh…
##  3 ACAD-1002  "Acadia " Mammal   Carn… Canid… Canis Canis latrans   Coyote, Eas…
##  4 ACAD-1003  "Acadia " Mammal   Carn… Canid… Canis Canis lupus     Eastern Tim…
##  5 ACAD-1004  "Acadia " Mammal   Carn… Canid… Vulp… Vulpes vulpes   Black Fox, …
##  6 ACAD-1005  "Acadia " Mammal   Carn… Felid… Lynx  Lynx canadensis Canada Lynx 
##  7 ACAD-1006  "Acadia " Mammal   Carn… Felid… Lynx  Lynx rufus      Bay Lynx, B…
##  8 ACAD-1007  "Acadia " Mammal   Carn… Mephi… Meph… Mephitis mephi… Eastern Sku…
##  9 ACAD-1008  "Acadia " Mammal   Carn… Muste… Lutra Lutra canadens… Otter, Rive…
## 10 ACAD-1009  "Acadia " Mammal   Carn… Muste… Mart… Martes pennanti Blackcat, F…
## # ℹ 24,500 more rows
## # ℹ 4 more variables: occurrence <chr>, nativeness <chr>, abundance <chr>,
## #   conservation_status <chr>
## # A tibble: 56 × 6
##    park_code park_name                       state  acres latitude longitude
##    <chr>     <chr>                           <chr>  <int>    <dbl>     <dbl>
##  1 ACAD      "Acadia "                       ME     47390     44.4     -68.2
##  2 ARCH      "Arches "                       UT     76519     38.7    -110. 
##  3 BADL      "Badlands "                     SD    242756     43.8    -102. 
##  4 BIBE      "Big Bend "                     TX    801163     29.2    -103. 
##  5 BISC      "Biscayne "                     FL    172924     25.6     -80.1
##  6 BLCA      "Black Canyon of the Gunnison " CO     32950     38.6    -108. 
##  7 BRCA      "Bryce Canyon "                 UT     35835     37.6    -112. 
##  8 CANY      "Canyonlands "                  UT    337598     38.2    -110. 
##  9 CARE      "Capitol Reef "                 UT    241904     38.2    -111. 
## 10 CAVE      "Carlsbad Caverns "             NM     46766     32.2    -104. 
## # ℹ 46 more rows

Lastly, we’ll combine the two data sets and remove the park code.

We have decided to restrict our data to the contiguous United States, for a number of reasons. Alaska and Hawaii have populations that are so different from the rest of the country that they are hardly comparable. Removing them makes our data far less complex, as it removes species that are found nowhere else in the country. It also serves the secondary purpose of making the data mapping easier.

## # A tibble: 21,695 × 16
##    species_id park_name category order family genus scientific_name common_names
##    <chr>      <chr>     <chr>    <chr> <chr>  <chr> <chr>           <chr>       
##  1 ACAD-1000  "Acadia " Mammal   Arti… Cervi… Alces Alces alces     Moose       
##  2 ACAD-1001  "Acadia " Mammal   Arti… Cervi… Odoc… Odocoileus vir… Northern Wh…
##  3 ACAD-1002  "Acadia " Mammal   Carn… Canid… Canis Canis latrans   Coyote, Eas…
##  4 ACAD-1003  "Acadia " Mammal   Carn… Canid… Canis Canis lupus     Eastern Tim…
##  5 ACAD-1004  "Acadia " Mammal   Carn… Canid… Vulp… Vulpes vulpes   Black Fox, …
##  6 ACAD-1005  "Acadia " Mammal   Carn… Felid… Lynx  Lynx canadensis Canada Lynx 
##  7 ACAD-1006  "Acadia " Mammal   Carn… Felid… Lynx  Lynx rufus      Bay Lynx, B…
##  8 ACAD-1007  "Acadia " Mammal   Carn… Mephi… Meph… Mephitis mephi… Eastern Sku…
##  9 ACAD-1008  "Acadia " Mammal   Carn… Muste… Lutra Lutra canadens… Otter, Rive…
## 10 ACAD-1009  "Acadia " Mammal   Carn… Muste… Mart… Martes pennanti Blackcat, F…
## # ℹ 21,685 more rows
## # ℹ 8 more variables: occurrence <chr>, nativeness <chr>, abundance <chr>,
## #   conservation_status <chr>, state <chr>, acres <int>, latitude <dbl>,
## #   longitude <dbl>

Here are our updated species, categories, which will be used throughout the rest of the analysis.

## # A tibble: 5 × 1
##   category 
##   <chr>    
## 1 Amphibian
## 2 Bird     
## 3 Fish     
## 4 Mammal   
## 5 Reptile

Data Analysis

Because our categories are not true taxonomic groupings, we need some context to the diversity within each. Lets examine orders first.

As seen above, the vast majority of species observed fall into the bird categories. This can be explained by a few different hypotheses:

  1. Because we removed seasonality, we are looking at species spotted in the park at any time of year, including species that are strictly migratory. Due to their migratory nature, the average bird species is often has a wider range of observation than that of an equivalent reptile, amphibian or mammal.

  2. Additionally, due to a variety of factors, birds are often have more comprehensive records than any other group. The MAPS program, created by the Institute for Bird Populations has gone a long way to creating distribution patterns across the United States, and the role of citizen science, on programs like eBird or iNaturalist create lists of observed species without the need for a monitoring program run by the park.

  3. Birds naturally have a high diversity, and occur across ecosystems. As such, every park is likely to have birds present, while fish, amphibians, reptiles, and mammals are far more restricted to certain habitats.

Deciding on conservation priorities requires the consideration of many different factors. For our purposes, we would argue that the biodiversity of a region is the most important factor. What method should be used to calculate this amorphous idea of ‘biodiversity’ is a topic of some debate. For our purposes, we have chosen a raw species richness.

As can be seen in the graph above and table below, the parks with the greatest raw species richness are Biscayne, Redwoods, & Everglades. The parks with the lowest are Mt. Rainier, Pinnacles and Black Canyon of the Gunnison

## # A tibble: 46 × 6
##    park_name                latitude longitude state    acres num_species
##    <chr>                       <dbl>     <dbl> <chr>    <int>       <int>
##  1 "Biscayne "                  25.6     -80.1 FL      172924        1127
##  2 "Redwood "                   41.3    -124   CA      112512         974
##  3 "Everglades "                25.3     -80.9 FL     1508538         916
##  4 "Death Valley "              36.2    -117.  CA, NV 4740912         913
##  5 "Channel Islands "           34.0    -119.  CA      249561         689
##  6 "Grand Canyon "              36.1    -112.  AZ     1217403         682
##  7 "Big Bend "                  29.2    -103.  TX      801163         632
##  8 "Hot Springs "               34.5     -93.0 AR        5550         608
##  9 "Great Smoky Mountains "     35.7     -83.5 TN, NC  521490         585
## 10 "Dry Tortugas "              24.6     -82.9 FL       64701         575
## # ℹ 36 more rows

However, raw number of species does not tell a manager the whole picture. Certain species require more help than others. If the national parks service was concerned with protection endangered species, certain parks may be more worth investing in than others.

Here we can see that the parks with the highest number of species listed as a ‘species of concern’ or worse by the National Parks are Death Valley, Redwoods, and the Grand Canyon.

In contrast, Congaree has the lowest number of endangered species.

## # A tibble: 46 × 6
##    park_name           latitude longitude state    acres num_species
##    <chr>                  <dbl>     <dbl> <chr>    <int>       <int>
##  1 "Death Valley "         36.2    -117.  CA, NV 4740912         129
##  2 "Redwood "              41.3    -124   CA      112512         127
##  3 "Grand Canyon "         36.1    -112.  AZ     1217403         116
##  4 "Big Bend "             29.2    -103.  TX      801163         108
##  5 "Carlsbad Caverns "     32.2    -104.  NM       46766          94
##  6 "Channel Islands "      34.0    -119.  CA      249561          92
##  7 "Saguaro "              32.2    -110.  AZ       91440          87
##  8 "Zion "                 37.3    -113.  UT      146598          85
##  9 "Joshua Tree "          33.8    -116.  CA      789745          84
## 10 "Everglades "           25.3     -80.9 FL     1508538          83
## # ℹ 36 more rows

The total number of endangered species is important for management consideration, but these ecosystems may just have a large gross number of species. However, it may be worth focusing on ecosystems with a large proportion of endangered species.

There are two theories behind why an ecosystem has many endangered species: 1) Some quality of the environment attracts species with specific habitat requirements, which are more likely to become endangered.

  1. The national park is the last remnant of an ecosystem that used to be far more prevalent, and the species within became endangered as the ecosystem did.

Either way, an organization considered with preserving biodiversity would get more ‘bang for their buck’ if they put their attention on these ecosystems.

Under these criteria, the parks that should be focused on are Pinnacles, The Petrified Forest, and Sequoia. Biscayne, The Everglades, and The Dry Tortugas, on the other hand, consist of ecosystems primarily composed of non-threatened species.

## # A tibble: 46 × 12
##    park_name     latitude.x longitude.x state.x acres.x num_species.x latitude.y
##    <chr>              <dbl>       <dbl> <chr>     <int>         <int>      <dbl>
##  1 "Pinnacles "        36.5       -121. CA        26606           275       36.5
##  2 "Petrified F…       35.1       -110. AZ        93533           335       35.1
##  3 "Sequoia and…       36.4       -119. CA       865952           365       36.4
##  4 "Mesa Verde "       37.2       -108. CO        52122           352       37.2
##  5 "Arches "           38.7       -110. UT        76519           303       38.7
##  6 "Black Canyo…       38.6       -108. CO        32950           271       38.6
##  7 "Capitol Ree…       38.2       -111. UT       241904           363       38.2
##  8 "Great Sand …       37.7       -106. CO        42984           328       37.7
##  9 "Saguaro "          32.2       -110. AZ        91440           420       32.2
## 10 "Yosemite "         37.8       -120. CA       761266           405       37.8
## # ℹ 36 more rows
## # ℹ 5 more variables: longitude.y <dbl>, state.y <chr>, acres.y <int>,
## #   num_species.y <int>, proportion_endangered <dbl>

Lastly, to provide some context to the previous data points, the following graph shows the taxonomic categories present in each park.

The most important insight to be gleaned from this data is the ‘Biscayne Question’. This park has simultaneously the highest number of species and the lowest proportion of endangered species (the same paradox is true of Everglades park, to a lesser extent).

However, the answer becomes present here. According to the IUCN, bony fishes are the invertebrate group with the lowest proportion of endangered species. The parks in our data set that have a large number of fish (Biscayne, Everglades, Dry Tortugas, etc.) are likely to have a low proportion of endangered species.

As such, if the National Park Service is concerned with managing for raw biodiversity, we would advocate for an increased focus on largely aquatic parks. If they are more concerned with protecting endangered species we could recommend an approach that disregards largely aquatic parks in favor of others.

Of course, the reality is not black and white, and this study ignores other factors that could potentially swing the recommendation in a different direction. No management plan is complete when only one facet of the problem is included. This is simply our recommendation based on the information at hand.

Mapping

We have created four maps to illustrate certain relationships between the data.

In all maps, the color of the point represents the size of the park in acres.

Map 1:

In this map, we have used the color of the point to represent the gross species richness.

Map 2:

In this map, we have used the size of the point to represent the total endangered species.

Map 3:

In this map, we have used the color of the point to represent the proportion of species that are threatened or endangered.

Machine Learning

Before we begin with our machine learning segment, we will primarily examine the relationship between park size and biodiversity. This analysis will provide the National Park Service with an invaluable data point. A larger park will require more funding, manpower, and work. If it is assumed that larger park = high biodiversity, the National Park Service will assign the most intensive management plans to the largest parks. However, using machine learning, we can devise a method that will determine the amount of effort to be put into a park based on the relationship between park size and biodiversity.

The very first thing to be done is to determine if this relationship actually exists. To do this, we will construct a correlation matrix of the variables currently used.

As we can see, there is a positive correlation between the number of species and the size of the park. Knowing this, we can forge ahead with our machine learning and examine this relationship in detail. Additionally, it seems like there is a stronger negative correlation between latitude and num_species, which means that as the latitude goes down, the species richness seems to go up. There is also very little correlation between the acres and the latitude, which means that there would be less multicolinearity than if we used longitude as well. We will keep this in mind, and in the case that acres alone is not a great predictor of species richness, we may incorporate the latitude variable into the conversation as well.

Regression Tree:

First, let’s make the data set that we will use for the machine learning methods that have acres predicting the number of species, or species richness in a park.

Additionally, let’s make the full tree and display it!

##               CP nsplit   rel.error   xerror      xstd
## 1   1.917216e-01      0 1.000000000 1.076905 0.3424978
## 2   1.579833e-01      1 0.808278413 1.288367 0.3802257
## 3   8.139187e-02      3 0.492311813 1.601176 0.4442543
## 4   3.792817e-02      5 0.329528068 1.971877 0.5546006
## 5   2.614051e-02      7 0.253671723 1.985202 0.5572047
## 6   2.607324e-02      9 0.201390702 1.927251 0.5487592
## 7   2.394472e-02     10 0.175317461 1.939079 0.5480783
## 8   1.676024e-02     11 0.151372740 1.992975 0.5525561
## 9   1.430971e-02     12 0.134612499 2.055024 0.5650334
## 10  1.412497e-02     13 0.120302785 2.061391 0.5646189
## 11  1.248156e-02     14 0.106177817 2.061391 0.5646189
## 12  9.129231e-03     17 0.068733139 2.065951 0.5643551
## 13  6.595098e-03     19 0.050474676 2.173326 0.5610788
## 14  4.870957e-03     21 0.037284480 2.224380 0.5585792
## 15  3.771330e-03     22 0.032413524 2.215251 0.5589617
## 16  3.768575e-03     23 0.028642194 2.232841 0.5588225
## 17  2.583411e-03     25 0.021105044 2.231511 0.5591628
## 18  1.973686e-03     26 0.018521634 2.236377 0.5587913
## 19  1.530448e-03     27 0.016547948 2.263461 0.5585908
## 20  1.457292e-03     28 0.015017500 2.256776 0.5567555
## 21  1.062820e-03     29 0.013560207 2.268545 0.5558410
## 22  1.029685e-03     31 0.011434568 2.272922 0.5554616
## 23  9.208195e-04     32 0.010404883 2.272922 0.5554616
## 24  7.349211e-04     33 0.009484063 2.265701 0.5558067
## 25  6.392987e-04     34 0.008749142 2.258839 0.5560172
## 26  4.655623e-04     35 0.008109843 2.258839 0.5560172
## 27  1.349855e-04     36 0.007644281 2.287675 0.5668045
## 28  1.034583e-04     37 0.007509296 2.283069 0.5670546
## 29  8.845989e-05     38 0.007405837 2.284245 0.5669843
## 30  5.172914e-05     39 0.007317378 2.284245 0.5669843
## 31  3.673075e-06     40 0.007265648 2.290505 0.5670065
## 32  1.224358e-06     41 0.007261975 2.291509 0.5671327
## 33  3.060896e-07     43 0.007259527 2.291544 0.5671295
## 34 -1.000000e+00     44 0.007259221 2.291544 0.5671295

In this next chunk, our goal is to find the CP Value of the tree that will be the simplest but also have an xerror that is less than the lowest xerror plus standard deviation of that lowest xerror.

xerror < min(xerror) + xstd

##   xcutoff  CP value 
## 1.4194027 0.1917216

So now we have the pruned regression tree for when we use acres to predict species richness; in the next code chunk, we will display the tree:

As you might have been able to predict based on the plotcp, our predictor variable of acres is not useful for predicting the species richness. Our row in the cptable with the lowest xerror is the first row, where we have zero splits, and thus one node with 100% of the data. This signals that we are better off guessing the species richness of a national park than using acres to guess the species richness - this makes sense because the relationship that we saw earlier between acres and num_species was not very linear, and the correlation was only .4.

For this reason, we will try using latitude and acres going forward to predict the number of species in a park:

Latitude:

In the next code chunk, we will make a new data set with latitude included as a predictor variable, and two scatterplots to help visualize the relationship between each of the predictor variables and the response variable side by side.

It seems that latitude has a relationship bith num_species that is a bit more linear than that of acres, but we will have to see how the machine learning methods go using both variables to predict.

Regression Tree with Latitude:

First, let’s make the data set that we will use for the machine learning methods that have acres predicting the number of species, or species richness in a park, this time with latitude included as an additional predictor variable.

Additionally, let’s make the full tree and display it!

##               CP nsplit    rel.error   xerror      xstd
## 1   3.159777e-01      0 1.000000e+00 1.050493 0.3376328
## 2   1.380668e-01      1 6.840223e-01 1.041011 0.3678984
## 3   8.136361e-02      2 5.459555e-01 1.150635 0.3877524
## 4   7.377506e-02      3 4.645919e-01 1.428414 0.4271225
## 5   3.729888e-02      7 1.694917e-01 1.540639 0.4241320
## 6   1.757330e-02      8 1.321928e-01 1.463468 0.4292990
## 7   1.362741e-02      9 1.146195e-01 1.356941 0.3900036
## 8   1.205160e-02     10 1.009921e-01 1.422830 0.4065133
## 9   7.284487e-03     12 7.688890e-02 1.422779 0.4046727
## 10  7.146179e-03     14 6.231993e-02 1.425486 0.3910723
## 11  6.871150e-03     15 5.517375e-02 1.423860 0.3911783
## 12  6.770212e-03     16 4.830260e-02 1.438912 0.3967329
## 13  6.096649e-03     17 4.153238e-02 1.438451 0.3967692
## 14  5.172914e-03     18 3.543574e-02 1.440900 0.3966936
## 15  4.555837e-03     19 3.026282e-02 1.438505 0.3968763
## 16  3.683278e-03     20 2.570698e-02 1.464868 0.3956493
## 17  3.048856e-03     21 2.202371e-02 1.475258 0.3950575
## 18  2.204763e-03     23 1.592599e-02 1.477160 0.3941340
## 19  2.068553e-03     24 1.372123e-02 1.492142 0.3954849
## 20  1.676147e-03     26 9.584124e-03 1.481311 0.3957503
## 21  1.323684e-03     27 7.907977e-03 1.481559 0.3957301
## 22  1.176608e-03     28 6.584293e-03 1.479268 0.3955876
## 23  9.876053e-04     29 5.407685e-03 1.503149 0.4020318
## 24  6.694179e-04     32 2.444869e-03 1.528797 0.4070020
## 25  4.655623e-04     33 1.775451e-03 1.529095 0.4071901
## 26  4.027264e-04     34 1.309889e-03 1.534271 0.4071563
## 27  1.619214e-04     36 5.044356e-04 1.539350 0.4073578
## 28  8.845989e-05     37 3.425142e-04 1.536120 0.4075836
## 29  7.346150e-05     39 1.655945e-04 1.535660 0.4076199
## 30  5.172914e-05     40 9.213296e-05 1.535660 0.4076199
## 31  3.305767e-05     41 4.040382e-05 1.535693 0.4076172
## 32  4.897433e-06     42 7.346150e-06 1.535296 0.4076423
## 33  1.224358e-06     43 2.448717e-06 1.534221 0.4072171
## 34 -1.000000e+00     45 0.000000e+00 1.534221 0.4072171

In this next chunk, our goal is to find the CP Value of the tree that will be the simplest but also have an xerror that is less than the lowest xerror plus standard deviation of that lowest xerror; like we did last time, but with latitude this time.

##   xcutoff  CP value 
## 1.4089097 0.3159777

So now we have the pruned regression tree for when we use acres to predict species richness; in the next code chunk, we will display the tree:

We still only have one node! It seems like, to make a regression tree to predict num_species, we would probably want to be able to identify more predictor variables in order to give the National Parks Service a more useful method

For the scope of our project, however, we will not be able to identify those other variables, as we only have so many available in the data set that we are working with. That said, we can try out some other machine learning methods to see if they have any more success:

KNN Regression with Latitude:

Now, we will try engaging in K Nearest Neighbors regression. For this machine learning method, we will need to rescale the explanatory variables, either using normalization of standardization, since KNN regression uses distance to classify the points of data, and since we have multiple explanatory variables.

Normalization: \[\frac{x - \min(x)}{\max(x) - \min(x)}\]

Standardization: \[\frac{x - \bar{x}}{s}\]

In the below code chunk, we will create the two functions in our rmd and normalize and standardize the explanatory columns in two different new data sets:

Now, we will use the normalized data to create a data frame to record the fit statistics, both the R^2 value and the MAE, for each value of k, using a for loop:

## # A tibble: 46 × 3
##        k      R2   MAE
##    <int>   <dbl> <dbl>
##  1     1 -0.570   165.
##  2     2 -0.0859  143.
##  3     3  0.0637  132.
##  4     4  0.155   124.
##  5     5  0.0815  132.
##  6     6  0.196   120.
##  7     7  0.207   114.
##  8     8  0.204   114.
##  9     9  0.203   111.
## 10    10  0.195   111.
## # ℹ 36 more rows

Next, we will use the standardized data to create a data frame to record the fit statistics, both the R^2 value and the MAE, for each value of k, using a for loop:

## # A tibble: 46 × 3
##        k      R2   MAE
##    <int>   <dbl> <dbl>
##  1     1 -0.556   161.
##  2     2 -0.0448  138.
##  3     3  0.202   120.
##  4     4  0.183   122.
##  5     5  0.149   126.
##  6     6  0.137   121.
##  7     7  0.184   114.
##  8     8  0.180   113.
##  9     9  0.163   111.
## 10    10  0.172   111.
## # ℹ 36 more rows

Okay, now that we have all of the rows of k for both the normalization and standardization methods, with all of the fit statistics, we will plot the data in graphs to visualize where there is a balance between MAE being low and R^2 being high in each of the methods for resizing the explanatory variables.

Okay, so we see that there is a pattern, where as we increase k, there is a spot where R^2 has a maximum and MAE has a minimum, but it’s hard to pinpoint that exactly.

In this next code chunk, we will use filter functions on the data set that we made before with the combined data to find the rows with the lowest MAE and the highest R^2

## # A tibble: 2 × 4
##   rescale     k    R2   MAE
##   <chr>   <int> <dbl> <dbl>
## 1 norm        7 0.207  114.
## 2 norm       11 0.190  109.

So we have two rows now to choose from, and, since we don’t have a preference on whether to prefer the row that looks at R^2 or the one that has the lowest MAE, we will choose the row with the higher k value to reduce overfitting of the data, since we want our data to be able to be applied to new data that is coming in, not only the training set that we used.

In this next code chunk, we will make a new knn regression model where k = 11, and find all of the fit statistics for that knn regression model again so we can discuss them:

## # A tibble: 1 × 4
##      R2   MAE MAE_mean  MAER
##   <dbl> <dbl>    <dbl> <dbl>
## 1 0.190  109.     138. 0.206

So, essentially. we learn from these fit statistics that, on average, the predicted value is off by 109.3 species from the actual number of species, that just using the mean of all of the values to get a predicted value would be off by 137.6 species, and that our method of using KNN regression increases our accuracy by about 20%. All things considered, this is not a whole lot, we could be doing a lot better if we had more predictor variables and if those variables had a clearer relationship with the number of species in a park. That said, this method has proven more useful than the regression tree.

Now, we will try making a Linear regression model using the multiple variables.

Linear Regression with Latitude:

As a final machine learning method, we will use a linear regression model with acres and latitude being used to predict num_species. Since acres and latitude have a correlation of 0.01, we should not run into any issues of multicollinearity at all.

In this first code chunk, our goal is to make the model for this eager learner machine learning method, and to save it and display the summary of the model.

## 
## Call:
## lm(formula = num_species ~ acres + latitude, data = predicting_species)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -187.07 -106.53   -6.93   34.25  575.61 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.003e+03  1.448e+02   6.930 1.62e-08 ***
## acres        9.528e-05  2.867e-05   3.324 0.001823 ** 
## latitude    -1.491e+01  3.697e+00  -4.033 0.000221 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 152.1 on 43 degrees of freedom
## Multiple R-squared:  0.3906, Adjusted R-squared:  0.3623 
## F-statistic: 13.78 on 2 and 43 DF,  p-value: 2.372e-05

Now, usng the linear model that we just made, we will make a data frame with the model to look at some of the summary statisticsm in a more condensed form.

## # A tibble: 3 × 5
##   term        estimate std.error statistic p.value
##   <chr>          <dbl>     <dbl>     <dbl>   <dbl>
## 1 (Intercept)   1003.     145.        6.93   0    
## 2 acres            0        0         3.32   0.002
## 3 latitude       -14.9      3.70     -4.03   0

The p-values of both of the predictor variables are both low (0.002 and o.ooo for acres and latitude respectively). That means that we don’t have to be concerned with multicollinearity in this regard, and can use the information that we can gather with both of the predictor variables to make the machine learning model:

## # A tibble: 1 × 12
##   r.squared adj.r.squared sigma statistic   p.value    df logLik   AIC   BIC
##       <dbl>         <dbl> <dbl>     <dbl>     <dbl> <dbl>  <dbl> <dbl> <dbl>
## 1     0.391         0.362  152.      13.8 0.0000237     2  -295.  598.  605.
## # ℹ 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>
## $mae
## [1] 99.88238
## 
## $reduction
## [1] 0.2741964
## # A tibble: 1 × 3
##      R2   MAE Reduction
##   <dbl> <dbl>     <dbl>
## 1 0.391  99.9     0.274

With this information, we learn that our average error is 99.9 species, and our error is 27.4% less than if we were to just guess. Still, this method, while an improvement, is not exactly what were looking for for a consistent predictor of species richness in national parks.

CONCLUSION:::

The use of data analytics in conservation is a growing field. The elimination of guesswork can allow managers to more effectively allocate manpower and funds. Our task in this scenario is to devise a management plan for the United States National Park service to maximize biodiversity across the country within the land they manage. Our major conclusions, were as follows:

  1. The lack of consistent insect surveying across the parks creates a barrier to accurately understanding biodiversity. More than half of the parks had no reported insect species.

  2. The parks with the highest raw species richness are those that are largely aquatic, with some exceptions (Redwood, Death Valley).

  3. However, these parks have a relatively low proportion of endangered species. The parks with the highest proportion of endangered species are concentrated in the Western and Southwestern states.

  4. The category with the most representation in the data is birds. This is likely due to birds being more highly migratory than other groups.

  5. There is little to no association between park size and species richness.

  6. However, there is an association between park latitude and species richness. The parks in the Southern regions of the United States, on average, display a higher biodiversity.

From these six points, we can make recommendations for management.

  1. To address this limitation, a consistent insect surveying plan should be developed and implemented across the parks. The Great Smokey Mountains National Park should lead the development of this plan, as their insect reporting is the most thorough of any park, and should be the gold standard that other parks strive for.

  2. If the National Parks are interested in conserving raw biodiversity numbers, the parks that should be prioritized are aquatic parks in the Southern part of the country, namely Biscayne, the Everglades, and the Dry Tortugas.

  3. If the National Parks Service is concerned with prioritizing the conservation of land with a high proportion of endangered species, parks in California and surrounding states are of the highest priority.

  4. To tackle the other major limitation in our study, the potential skew provided by migratory birds, a secondary analysis should be conducted, this time accounting for seasonality and land usage rather than strictly observation. Weighting species by the amount of time a year they spend relying on the natural resources present in the park could be one way of accomplishing this, but that is beyond the scope of our analysis.

  5. While larger parks are always likely to require more attention, the biodiversity return may not be correlated with size. As such, the service can be confident in the future that small parks will yield a worthwhile return, and can empower the service to conserve small, high biodiversity patches of land as national parks.

  6. Lastly, while it is important to not neglect the northern reaches of the country, the finding that the highest biodiversity parks are in the southern United States implies that, for the establishment of future national parks, this part of the country should be the highest priority.

With this clear understanding of the patterns of biodiversity within the national parks, those concerned with the delegation of funds and manpower for conservation can know with clearer certainty how best to allocate resources. The national parks system has the potential to be an incredible conservation force, and the more accurate and precise the managers of this land can be with their decisions, the more the organisms within will benefit.