minmax.periodic: Search for minimum and maximum indices in periodic timeseries

View source: R/minmax.periodic.R

minmax.periodicR Documentation

Search for minimum and maximum indices in periodic timeseries

Description

Search for minimum and maximum for periodic timeseries when only intermediate values are known.
For each couple of value with an increasing or decreasing segment of the sinusoid function, it is possible to estimate a minimum and maximum values using analytical algebra.
Then the average and standard deviations of all minima and maxima are evaluated.
It should be noted that any extremum can be estimated at least twice, one by increasing segment and one by decreasing segment. Both are used here to produce SD.
time.minmax.daily should be used when the time at which maximum and minimum indices are regular and time.minmax permits to define this time day by day.

Usage

minmax.periodic(
  time.minmax.daily = NULL,
  time.minmax = NULL,
  progressbar = FALSE,
  observed = stop("data.frame with observed indices"),
  period = 24,
  colname.time = "time",
  colname.index = "index",
  colname.SD = "SD",
  plot = FALSE
)

Arguments

time.minmax.daily

A named vector with Min and Max being the time in the day with minimum and maximum indices (temperature or level)

time.minmax

A named vector daily with time in the day at which minimum and maximum indices are observed

progressbar

Tell if a progression bar must be shown

observed

A dataframe with at least two columns: time and temperatures. A third column SD can indicate the know error in index

period

The unit of day period (24 for hours, 24*60 for minutes)

colname.time

The name of the column for time in observed

colname.index

The name of the column for indices in observed

colname.SD

The name of the column for SD in observed

plot

If TRUE, show a plot with the different estimates

Details

minmax.periodic search for minimum and maximum indices (temperatures or levels) in periodic timeseries

Value

A data.frame with a column time, a column index and a column SD

Author(s)

Marc Girondot marc.girondot@gmail.com

See Also

Other Periodic patterns of indices: index.periodic(), moon.info(), sun.info(), tide.info()

Examples

## Not run: 
library("HelpersMG")
# Generate a timeserie of time
time.obs <- NULL
for (i in 0:9) time.obs <- c(time.obs, c(0, 6, 12, 18)+i*24)
# For these time, generate a timeseries of temperatures
temp.obs <- rep(NA, length(time.obs))
temp.obs[3+(0:9)*4] <- rnorm(10, 25, 3)
temp.obs[1+(0:9)*4] <- rnorm(10, 10, 3)
for (i in 1:(length(time.obs)-1)) 
  if (is.na(temp.obs[i])) 
  temp.obs[i] <- mean(c(temp.obs[i-1], temp.obs[i+1]))
  if (is.na(temp.obs[length(time.obs)])) 
  temp.obs[length(time.obs)] <- temp.obs[length(time.obs)-1]/2
observed <- data.frame(time=time.obs, temperature=temp.obs)
# Search for the minimum and maximum values
r <- minmax.periodic(time.minmax.daily=c(Min=2, Max=15), 
observed=observed, period=24, colname.index="temperature")

# Estimate all the temperatures for these values
t <- index.periodic(minmax=r)

plot_errbar(x=t[,"time"], y=t[,"index"],
errbar.y=ifelse(is.na(t[,"sd"]), 0, 2*t[,"sd"]),
type="l", las=1, bty="n", errbar.y.polygon = TRUE, 
xlab="hours", ylab="Temperatures", ylim=c(0, 35), 
errbar.y.polygon.list = list(col="grey"))

plot_add(x=t[,"time"], y=t[,"index"], type="l")

plot_add(observed$time, observed$temperature, pch=19, cex=0.5)

## End(Not run)

HelpersMG documentation built on Sept. 12, 2024, 9:35 a.m.