# 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