knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

multivaR

Travis build status

The goal of multivaR is to organize and simplify the process of creating a multivariate analysis. This package can format data as well as caluclate anomalies from raw data, once data is formatted the package can be used to run Principal Components Analysis on multiple variables.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("Echisholm21/multivaR")

multivaR is designed to work with other packages developed by the Data Access team at Bedford Institute of Oceanogrpahy (BIO). Specifically, this package is designed to work with data which is supplied through the azmpdata package. This supplementary package can be installed by using:

devtools::install_github("casaultb/azmpdata")

Example

This is a basic example which shows you how to solve a common problem:

library(multivaR)
library(dplyr)
library(data.table)
library(devtools)
## basic example code

# step 1: assemble data

# search for azmpdata
# if azmpdata is not downloaded:
if(!'azmpdata' %in% installed.packages()){devtools::install_github("casaultb/azmpdata")}
library(azmpdata)
query(search_key = '')

# load in desired data frames
data("Derived_Occupations_Sections")
data("Zooplankton_Occupations_Sections")

# collate data frames

datfr <- right_join(Derived_Occupations_Sections, Zooplankton_Occupations_Sections) 

If anomalies need to be calculated, multivaR has options for calculating monthly, annual or seasonal anomalies with or without normalization. Anomaly calculations use a reference period to calculate a climatology (climatologyYears). This reference period is typically standardized, please check that you are using the current standard climatology period that is relevant to your data.

# monthly anomalies must be caluclated before annual anomalies (annual anomaly function simply combines monthly anomalies)

danomalies <- monthlyAnomaly(datfr, climatologyYears = c(1999, 2010), var = 'integrated_chlorophyll_0_100')

# annual anomalies function creates new data frame with just year and variable
chl_annual_anomalies <- annualAnomaly(danomalies, anomaly = 'integrated_chlorophyll_0_100_anomaly')

# if you are unsure which anomaly calculation to use you can use the wrapper function which will select the appropriate method 
anom_1 <- calculate_anomaly(data = datfr, anomalyType = 'monthly', climatologyYears = c(1999, 2010), var = 'integrated_chlorophyll_0_100', normalizedAnomaly = TRUE)
head(anom_1)


anom_2 <- calculate_anomaly(data = datfr, anomalyType = 'seasonal', climatologyYears = c(1999, 2010))
head(anom_2)

Once data is assembled, PCA can be run

PCA(datfr[,9:15]) # subset dataframe to exclude metadata columns

PCA results can be presented, plotted and analyzed as usual, using packages outside of multivaR.



EOGrady21/multivaR documentation built on March 3, 2022, 12:01 a.m.