Learn R Programming

embryogrowth (version 5.1)

minmax.periodic: Search for minimum and maximum temperatures 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 deareasing 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 incresing segment and one by decreasing segment.

Usage

minmax.periodic(time.minmax.daily, time.obs, temp.obs, period = 24)

Arguments

time.minmax.daily
A named vector with Min and Max being the time in the day with minimum and maximum temperatures
time.obs
A vector with the time at which temperatures are recorded
temp.obs
A vector with the recorded temperatures recorded
period
The unit of day period (24 for hours, 24*60 for minutes)

Value

  • A data.frame with a column time, a column temperature and a column sd

Details

minmax.periodic search for minimum and maximum temperatures in periodic timeseries

Examples

Run this code
# 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

# Search for the minimum and maximum values
r <- minmax.periodic(time.minmax.daily=c(Min=2, Max=15),
time.obs=time.obs, temp.obs=temp.obs, period=24)

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

plot_errbar(x=t[,"time"], y=t[,"temperature"],
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[,"temperature"], type="l")

Run the code above in your browser using DataLab