Learn R Programming

pastecs (version 1.0-2)

regul: Regulation of one or several time series using various methods

Description

Regulate irregular time series or regular time series with gaps. Create a regul object from whose one or several regular time series can be extracted using extract() or tseries(). This is the function to apply most of the time to create regular time series ('rts' objects in Splus or 'ts' objects in R) that will be further analyzed by other functions that apply to regular time series.

Usage

regul(x, y=NULL, xmin=min(x), n=length(x), units="days", frequency=NULL,
        deltat=1/frequency, datemin=NULL, dateformat="m/d/Y", tol=NULL,
        tol.type="both", methods="linear", rule=1, f=0, periodic=F,
        window=(max(x) - min(x))/(n - 1), split=100, specs=NULL)
## S3 method for class 'regul':
summary(reg)
## S3 method for class 'regul':
plot(reg, series=1, col=c(1, 2), lty, plot.pts=TRUE,
        leg=FALSE, llab=c("initial", x$specs$methods[series]),
        lpos=c(1.5, 10), ...)
## S3 method for class 'regul':
lines(reg, series=1, col=3, lty=1, plot.pts=TRUE, \dots)
## S3 method for class 'regul':
identify(reg, series=1, col=3, label="#", \dots)
## S3 method for class 'regul':
hist(reg, nclass=30, col=c(4, 5, 2), plotit=TRUE, ...)
## S3 method for class 'regul':
extract(reg, n=ncol(reg$y), series=NULL)
## S3 method for class 'regul':
specs(reg)

Arguments

x
a vector containing times at which observations are sampled in the initial irregular time series. It can be expressed in any unit ("years", "days", "weeks", "hours", "min", "sec",...) as defined by the argument units. It is often expressed in
y
a vector (single series) or a matrix/data frame whose columns correspond to the various irregular time series to regulate. Rows are observations made at corresponding times in x. The number of rows must thus match the length of vector x
xmin
allows to respecify the origin of time in x. By default, the origin is not redefined and thus, the smallest value in x is used
n
the number of observations in the regular time series. By default, it is the same number than in the original irregular time series (i.e., length(x)
units
the time unit for the x vector. By default units="days". A special value, units="daystoyears" indicates that x is expressed in "days" (1 unit = 1 day) but that we want to obtain the final regular time se
frequency
the frequency of the regulated time series in the corresponding time unit. For instance, frequency=12 with units="years" means montly sampled observations. Warning! When using units="daystoyears", specify frequ
deltat
the interval between two observations in the regulated time series. It is the inverse of frequency. If both frequency and deltat are provided, then frequency supersedes deltat
datemin
this is mostly useful for converting "days" in "years" time-scales (units="daystoyears"). If the x vector contains: 1, 3, 6,... (day #1, day #3, day #6,... of the experiment), one can give here the exact date of the first observa
dateformat
indicate how datemin is formated. For instance: "d/m/Y", or m/d/Y" (by default), see daystoyears() for more info on date formatting
tol
the tolerance in the time-scale to determine if a measured value is used to approximate a regulated value. If tol=0, observations in each respective series must match exactly, otherwise observations in the regulated series are interpolated. <
tol.type
the type of adjustment to use for the time-tolerance: "left", "right", "both" (by default) or "none". If tol.type="left", corresponding x values are seeked in a window ]xregul-t
methods
the method(s) to use to regulate the time series. Currently, it can be: "constant", "linear", "spline" or "area" (or a unique abbreviation of them). If several time series are provided (y is
rule
the rule to use for extrapolated values (observations in the final regular time series that are outside the range of observed values in the initial time series). With rule=1 (by default), these entries are not calculated and get NA; with
f
parameter for the "constant" regulation method. Coefficient giving more weight to the observation at left (f=0, by default), to the observation at right (f=1), or give an intermediate weight to both of these observat
periodic
parameter for the "spline" regulation method. Indicate if the time series should be considered as periodic (periodic=TRUE, first value must be equal to the last one). If this is the case, first and second derivates used to calcul
window
parameter for the "area" regulation method. Size of the window to consider (see regarea()). By default, the mean interval between observations in the initial irregular time series is used. Give the same value as for deltat for wo
split
other parameter for the "area" method. To optimise calculation time and to avoid to saturate memory, very long time series are splitted into smaller subunits (see regarea()). This is transparent for the user. The default value of
specs
a specs.regul object returned by the function specs() applied to a regul object. Allows to collect parameterization of the regul() function and to apply them to another regulation
reg
A regul object as obtained after using the regul() function
series
the series to plot. By default, series=1, corresponding to the first (or possibly the unique) series in the regul object
col
(1) for plot(): the two colors to use to draw respectively the initial irregular series and the final regulated series. col=c(1,2) by default. (2) for hist(): the three colors to use to represent respectively the fis
lty
the style to use to draw lines for the initial series and the regulated series, respectively. The default style is used for both lines if this argument is not provided
plot.pts
if plot.pts=TRUE (by default) then points are also drawn for the regulated series (+). Those points that match observations in the initial irregular series, and are not interpolated, are further marked with a circle
leg
do we add a legend to the graph? By default, leg=FALSE, no legend is added
llab
the labels to use for the initial irregular and the final regulated series, respectively. By default, it is "initial" for the first one and the name of the regulation method used for the second one (see methods argument)
lpos
the position of the top-left corner of the legend box (x,y), in the graph coordinates
...
additional graph parameters
label
the character to use to mark points interactively selected on the graph. By default, label="#"
nclass
the number of classes to calculate in the histogram. This is indicative and this value is automatically adjusted to obtain a nicely-formatted histogram. By default, nclass=30
plotit
If plotit=TRUE then the histogram is plotted. Otherwise, it is only calculated

Value

  • An object of type 'regul' is returned. It has methods print(), summary(), plot(), lines(), identify(), hist(), extract() and specs().

synopsis

regul(x, y=NULL, xmin=min(x), n=length(x), units="days", frequency=NULL, deltat=1/frequency, datemin=NULL, dateformat="m/d/Y", tol=NULL, tol.type="both", methods="linear", rule=1, f=0, periodic=F, window=(max(x) - min(x))/(n - 1), split=100, specs=NULL) extract.regul(e, n, series=NULL, ...) hist.regul(x, nclass=30, col=c(4, 5, 2), xlab=paste("Time distance in", x$units, "with start =", min(x$x), , ylab=paste("Frequency, tol =", x$specs$tol), main="Number of matching observations", plotit=TRUE, ...) identify.regul(x, series=1, col=3, label="#", ...) lines.regul(x, series=1, col=3, lty=1, plot.pts=TRUE, ...) plot.regul(x, series=1, col=c(1, 2), lty=c(par("lty"), par("lty")), plot.pts=TRUE, leg=FALSE, llab=c("initial", x$specs$methods[series]), lpos=c(1.5, 10), xlab=paste("Time (", x$units, ")", sep = ""), ylab="Series", main=paste("Regulation of", names(x$y)[series]), ...) print.regul(x, ...) print.specs.regul(x, ...) print.summary.regul(x, ...) specs.regul(x, ...) summary.regul(object, ...)

Details

Several irregular time series (for instance, contained in a data frame) can be treated at once. Specify a vector with "constant", "linear", "spline" or "area" for the argument methods to use a different regulation method for each series. See corresponding fonctions (regconst(), reglin(), regspline() and regarea()), respectively, for more details on these methods. Arguments can be saved in a specs object and reused for other similar regulation processes. Functions regul.screen() and regul.adj() are useful to chose best time interval in the computed regular time series. If you want to work on seasonal effects in the time series, you will better use a "years" time-scale (1 unit = 1 year), or convert into such a scale. If initial time unit is "days" (1 unit = 1 day), a conversion can be operated at the same time as the regulation by specifying units="daystoyears".

References

Lancaster, P. & K. Salkauskas, 1986. Curve and surface fitting. Academic Press, England, 280 pp. Fox, W.T. & J.A. Brown, 1965. The use of time-trend analysis for environmental interpretation of limestones. J. Geol., 73:510-518. Ibanez, F., 1991. Treatment of the data deriving from the COST 647 project on coastal benthic ecology: The within-site analysis. In: B. Keegan (ed). Space and Time Series Data Analysis in Coastal Benthic Ecology. Pp 5-43. Ibanez, F. & J.C. Dauvin, 1988. Long-term changes (1977-1987) on a muddy fine sand Abra alba - Melinna palmata population community from the Western English Channel. J. Mar. Ecol. Prog. Ser., 49:65-81.

See Also

regul.screen, regul.adj, tseries, is.tseries, regconst, reglin, regspline, regarea, daystoyears

Examples

Run this code
data(releve)
# The series in this data frame are very irregularly sampled in time:
releve$Day
length(releve$Day)
intervals <- releve$Day[2:61]-releve$Day[1:60]
intervals
range(intervals)
mean(intervals)
# The series must be regulated to be converted in a 'rts' or 'ts object
rel.reg <- regul(releve$Day, releve[3:8], xmin=9, n=63, deltat=21,
        tol=1.05, methods=c("s","c","l","a","s","a"), window=21)
rel.reg
plot(rel.reg, 5)
specs(rel.reg)
# Now we can extract one or several regular time series
melo.ts <- extract(rel.reg, series="Melosul")
is.tseries(melo.ts)

# One can convert time-scale from "days" to "years" during regulation
# This is most useful for analyzing seasonal cycles in a second step
melo.regy <- regul(releve$Day, releve$Melosul, xmin=6, n=87,
        units="daystoyears", frequency=24, tol=2.2, methods="linear",
        datemin="21/03/1989", dateformat="d/m/Y")
melo.regy
plot(melo.regy, main="Regulation of Melosul")
# In this case, we have only one series in 'melo.regy'
# We can use also 'tseries()' instead of 'extract()'
melo.tsy <- tseries(melo.regy)
is.tseries(melo.tsy)

Run the code above in your browser using DataLab