# 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)
# }
Run the code above in your browser using DataLab