Author: Brian Maitner
Date: 2025-01-12

# OpenRange R package

#### Brian Maitner

#### 2025-01-12

# Open Range

Open Range is a database containing Open Access species range maps and associated metadata. The database is currently in a pre-alpha, proof-of-concept stage. While the methods underlying the range maps are documented in the metadata, and the maps follow reasonable best practices, they have not been peer-reviewed. They are provided to show a working example of what could be done with an Open Access range database, and to provide an example of what the underlying database might look like. The maps should not be used without critical evaluation.

## Licensing

The maps currently contained in the Open Range database are available with a CC-BY license, but we note that additional maps using alternative licenses may be applied in the future.

### Accessing the maps

The easiest way to access the species range maps is by querying a species name.

    library(OpenRange)

    ## Loading required package: RPostgreSQL

    ## Loading required package: DBI

    pcontorta <- OpenRange_load_species(species = "Pinus contorta")

    plot(pcontorta[2])

### Checking map quality

This is a bit cumbersome, but keep in mind this is a pre-alpha version. For now, you can use the function OpenRange_get_stats

    library(tidyverse)

    ## -- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
    ## v dplyr     1.1.4     v readr     2.1.5
    ## v forcats   1.0.0     v stringr   1.5.1
    ## v ggplot2   3.5.1     v tibble    3.2.1
    ## v lubridate 1.9.3     v tidyr     1.3.1
    ## v purrr     1.0.2
    ## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
    ## x dplyr::filter() masks stats::filter()
    ## x dplyr::lag()    masks stats::lag()
    ## i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

    # Grab the stats
      model_stats <- OpenRange_get_stats()

    # Reformat them into a single table

      model_stats_wide <- bind_rows(model_stats$rangebagging %>%
                         mutate(algorithm = "rangebagging"),
                       model_stats$ppm %>%
                         mutate(algorithm = "ppm"),
                       model_stats$points %>%
                         mutate(algorithm = "points"))

    # Get relevant model stats

      model_stats_wide %>%
        filter(model_id == pcontorta$model_id)->test

      test %>%
        select(cv_mean_train_npresence,cv_mean_test_n_presence,cv_mean_test_auc,cv_mean_train_auc)

    ##   cv_mean_train_npresence cv_mean_test_n_presence cv_mean_test_auc
    ## 1                  1348.8                   337.2            0.859
    ##   cv_mean_train_auc
    ## 1             0.899