Description Usage Arguments Details Value Author(s) References See Also Examples
TheilSen slope estimates and tests for trend.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  TheilSen(
mydata,
pollutant = "nox",
deseason = FALSE,
type = "default",
avg.time = "month",
statistic = "mean",
percentile = NA,
data.thresh = 0,
alpha = 0.05,
dec.place = 2,
xlab = "year",
lab.frac = 0.99,
lab.cex = 0.8,
x.relation = "same",
y.relation = "same",
data.col = "cornflowerblue",
trend = list(lty = c(1, 5), lwd = c(2, 1), col = c("red", "red")),
text.col = "darkgreen",
slope.text = NULL,
cols = NULL,
shade = "grey95",
auto.text = TRUE,
autocor = FALSE,
slope.percent = FALSE,
date.breaks = 7,
date.format = NULL,
plot = TRUE,
silent = FALSE,
...
)

mydata 
A data frame containing the field 
pollutant 
The parameter for which a trend test is required. Mandatory. 
deseason 
Should the data be dedeasonalized first? If 
type 
It is also possible to choose Type can be up length two e.g. 
avg.time 
Can be “month” (the default), “season” or “year”. Determines the time over which data should be averaged. Note that for “year”, six or more years are required. For “season” the data are split up into spring: March, April, May etc. Note that December is considered as belonging to winter of the following year. 
statistic 
Statistic used for calculating monthly values. Default is
“mean”, but can also be “percentile”. See 
percentile 
Single percentile value to use if 
data.thresh 
The data capture threshold to use (
the data using 
alpha 
For the confidence interval calculations of the slope. The default is 0.05. To show 99% confidence intervals for the value of the trend, choose alpha = 0.01 etc. 
dec.place 
The number of decimal places to display the trend estimate at. The default is 2. 
xlab 
xaxis label, by default 
lab.frac 
Fraction along the yaxis that the trend information should be printed at, default 0.99. 
lab.cex 
Size of text for trend information. 
x.relation 
This determines how the xaxis scale is plotted. “same” ensures all panels use the same scale and “free” will use panelspecfic scales. The latter is a useful setting when plotting data with very different values. 
y.relation 
This determines how the yaxis scale is plotted. “same” ensures all panels use the same scale and “free” will use panelspecfic scales. The latter is a useful setting when plotting data with very different values. 
data.col 
Colour name for the data 
trend 
list containing information on the line width, line type and line colour for the main trend line and confidence intervals respectively. 
text.col 
Colour name for the slope/uncertainty numeric estimates 
slope.text 
The text shown for the slope (default is ‘units/year’). 
cols 
Predefined colour scheme, currently only enabled for

shade 
The colour used for marking alternate years. Use “white” or “transparent” to remove shading. 
auto.text 
Either 
autocor 
Should autocorrelation be considered in the trend uncertainty
estimates? The default is 
slope.percent 
Should the slope and the slope uncertainties be
expressed as a percentage change per year? The default is For 
date.breaks 
Number of major xaxis intervals to use. The function
will try and choose a sensible number of dates/times as well as formatting
the date/time appropriately to the range being considered. This does not
always work as desired automatically. The user can therefore increase or
decrease the number of intervals by adjusting the value of

date.format 
This option controls the date format on the
xaxis. While 
plot 
Should a plot be produced. 
silent 
When 
... 
Other graphical parameters passed onto 
The TheilSen
function provides a collection of functions to
analyse trends in air pollution data. The TheilSen
function
is flexible in the sense that it can be applied to data in many
ways e.g. by day of the week, hour of day and wind direction. This
flexibility makes it much easier to draw inferences from data
e.g. why is there a strong downward trend in concentration from
one wind sector and not another, or why trends on one day of the
week or a certain time of day are unexpected.
For data that are strongly seasonal, perhaps from a background
site, or a pollutant such as ozone, it will be important to
deseasonalise the data (using the option deseason =
TRUE
.Similarly, for data that increase, then decrease, or show
sharp changes it may be better to use smoothTrend
.
A minimum of 6 points are required for trend estimates to be made.
Note! that since version 0.511 openair uses TheilSen to derive the p values also for the slope. This is to ensure there is consistency between the calculated p value and other trend parameters i.e. slope estimates and uncertainties. The p value and all uncertainties are calculated through bootstrap simulations.
Note that the symbols shown next to each trend estimate relate to how statistically significant the trend estimate is: p $<$ 0.001 = ***, p $<$ 0.01 = **, p $<$ 0.05 = * and p $<$ 0.1 = $+$.
Some of the code used in TheilSen
is based on that from
Rand Wilcox https://dornsife.usc.edu/labs/rwilcox/software/. This mostly
relates to the TheilSen slope estimates and uncertainties.
Further modifications have been made to take account of correlated
data based on Kunsch (1989). The basic function has been adapted
to take account of autocorrelated data using block bootstrap
simulations if autocor = TRUE
(Kunsch, 1989). We follow the
suggestion of Kunsch (1989) of setting the block length to n(1/3)
where n is the length of the time series.
The slope estimate and confidence intervals in the slope are plotted and numerical information presented.
As well as generating the plot itself, TheilSen
also returns
an object of class “openair”. The object includes three main components:
call
, the command used to generate the plot; data
, the data
frame of summarised information used to make the plot; and plot
,
the plot itself. If retained, e.g. using output < TheilSen(mydata,
"nox")
, this output can be used to recover the data, reproduce or rework
the original plot or undertake further analysis.
An openair output can be manipulated using a number of generic operations,
including print
, plot
and summary
.
The data
component of the TheilSen
output includes two
subsets: main.data
, the monthly data res2
the trend
statistics. For output < TheilSen(mydata, "nox")
, these can be
extracted as object$data$main.data
and object$data$res2
,
respectively.
Note: In the case of the intercept, it is assumed the yaxis crosses the xaxis on 1/1/1970.
David Carslaw with some trend code from Rand Wilcox
Helsel, D., Hirsch, R., 2002. Statistical methods in water resources. US Geological Survey. Note that this is a very good resource for statistics as applied to environmental data.
Hirsch, R. M., Slack, J. R., Smith, R. A., 1982. Techniques of trend analysis for monthly waterquality data. Water Resources Research 18 (1), 107121.
Kunsch, H. R., 1989. The jackknife and the bootstrap for general stationary observations. Annals of Statistics 17 (3), 12171241.
Sen, P. K., 1968. Estimates of regression coefficient based on Kendall's tau. Journal of the American Statistical Association 63(324).
Theil, H., 1950. A rank invariant method of linear and polynomial regression analysis, i, ii, iii. Proceedings of the Koninklijke Nederlandse Akademie Wetenschappen, Series A  Mathematical Sciences 53, 386392, 521525, 13971412.
... see also several of the Air Quality Expert Group (AQEG) reports for the use of similar tests applied to UK/European air quality data.
See smoothTrend
for a flexible approach to estimating
trends using nonparametric regression. The smoothTrend
function is
suitable for cases where trends are not monotonic and is probably better
for exploring the shape of trends.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  # load example data from package
data(mydata)
# trend plot for nox
TheilSen(mydata, pollutant = "nox")
# trend plot for ozone with p=0.01 i.e. uncertainty in slope shown at
# 99 % confidence interval
## Not run: TheilSen(mydata, pollutant = "o3", ylab = "o3 (ppb)", alpha = 0.01)
# trend plot by each of 8 wind sectors
## Not run: TheilSen(mydata, pollutant = "o3", type = "wd", ylab = "o3 (ppb)")
# and for a subset of data (from year 2000 onwards)
## Not run: TheilSen(selectByDate(mydata, year = 2000:2005), pollutant = "o3", ylab = "o3 (ppb)")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.