evalcor: Evaluate tide and sun correlation

View source: R/evalcor.R

evalcorR Documentation

Evaluate tide and sun correlation

Description

Evaluate the correlation between tide change and sun angle to determine potential effectiveness of weighted regression

Usage

evalcor(
  dat_in,
  tz,
  lat,
  long,
  depth_val = "Tide",
  daywin = 6,
  method = "pearson",
  plot = TRUE,
  lims = c(-0.5, 0.5),
  progress = FALSE,
  harm = TRUE,
  chk_tide = FALSE,
  constituents = c("M2", "S2", "N2", "K2", "K1", "O1", "P1", "Q1", "MF", "MM", "SSA",
    "M4", "M6", "S4", "MS4")
)

Arguments

dat_in

Input data.frame

tz

chr string for timezone, e.g., 'America/Chicago', must match the time zone in dat_in$DateTimeStamp

lat

numeric for latitude

long

numeric for longitude (negative west of prime meridian)

depth_val

chr indicating name of the tidal height column in dat_in

daywin

numeric for half-window width used in moving window correlation

method

chr string for corrrelation method, passed to cor

plot

logical to return a plot

lims

two element numeric vector indicating y-axis limits on plot

progress

logical if progress is saved to a text file named 'log.txt' in the working directory

harm

logical indicating if the tidal height vector indicated in depth_val is modelled using harmonic regression, see details

chk_tide

logical indicating if harmonic regression output is returned for diagnostics

constituents

chr string of harmonic constituents to predict if harm = TRUE

Details

This function can be used before weighted regression to identify locations in the time series when tidal and solar changes are not correlated. In general, the wtreg will be most effective when correlations between the two are zero, whereas wtreg will remove both the biological and physical components of the dissolved oxygen time series when the sun and tide are correlated. The correlation between tide change and sun angle is estimated using a moving window for the time series, where the half-window width is defined by daywin (i.e., the default value is a moving window with six days on each side for 12 days total). Tide changes are estimated as angular rates for the tidal height vector and sun angles are estimated from the time of day and geographic location.

The foreach function is used to execute the moving window correlation in parallel and will be run automatically if a backend is created.

Setting harm = TRUE will predict the tidal time series with harmonic regression using the tidem function. This is useful if there are missing observations in the observed tidal vector. The correlation time series in the plot will also be smoother. Use the chk_tide function before applying this option to verify the harmonic regression model is adequate for the observed time series. The predicted tidal constituents in the default argument should account for a majority of the variation in the observed data. These include M2: principal lunar semidiurnal, S2: principal solar semidiurnal, N2: larger lunar elliptic semidiurnal, K2: lunisolar semidiurnal, K1: lunisolar declinational diurnal, O1: principal lunar diurnal, P1: principal solar diurnal, Q1: larger lunar elliptic diurnal, MF: lunar fortnightly, MM: lunar monthly, SSA: solar semi annual, M4: first overtide of M2, M6: second overtide of M2, S4: first overtide of S2, and MS4: compound tide of M2 and S2.

Figure 9 in Beck et al. 2015 was created using this function.

Value

A ggplot object if plot = TRUE, otherwise a numeric vector of the correlations for each row in the input dataset. A two-element list will be returned for the tidal model and predicted resutls of chk_tide = TRUE

References

Beck MW, Hagy III JD, Murrell MC. 2015. Improving estimates of ecosystem metabolism by reducing effects of tidal advection on dissolved oxygen time series. Limnology and Oceanography Methods. DOI: 10.1002/lom3.10062

See Also

wtreg

Examples

## Not run: 

data(SAPDC)

# metadata
tz <- 'America/Jamaica'
lat <- 31.39
long <- -81.28

# setup parallel backend
library(doParallel)
registerDoParallel(cores = 7)

evalcor(SAPDC, tz, lat, long, progress = TRUE)

# check fit of tidal predictions
# in this case, predictions = observed because sample data are already predicted
tochk <- evalcor(SAPDC, tz, lat, long, progress = TRUE, chk_tide = TRUE)
tochk <- tochk$tide_pred
plot(tide_obs ~ tide_pred, tochk)


## End(Not run)

fawda123/WtRegDO documentation built on March 18, 2024, 9:04 p.m.