% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Trend.R
\name{Trend}
\alias{.Trend}
\alias{Trend}
\title{Computes the Trend of the Ensemble Mean}
\usage{
Trend(var, posTR = 2, interval = 1, siglev = 0.95, conf = TRUE,
  pldegree = 1)

.Trend(exp, interval = 1, siglev = 0.95, conf = TRUE)
}
\arguments{
\item{var}{Array of any number of dimensions up to 10.}

\item{posTR}{Position along which to compute the trend.cr
Default = 2.}

\item{interval}{Number of months/years between 2 points along posTR dimension.\cr
Default = 1.\cr
The trend would be provided in number of units per month or year.}

\item{siglev}{Confidence level for the computation of confidence interval. 
Default = 0.95.}

\item{conf}{Whether to compute the confidence levels or not.\cr
Default = TRUE.}

\item{pldegree}{The degree/order of the polynomial to be fitted and removed
(keep in mind that the degree must be smaller than the number of points 
along posTR dimension). Default = 1 (linear fit)}

\item{exp}{M by N matrix of M forecasts from N ensemble members.}
}
\value{
\item{$trend}{
 Same dimensions as var except along posTR dimension which is replaced
 by a dimension:\cr
 \itemize{
   \item{conf = TRUE:\cr
         dimension length = 3 * (pldegree + 1)\cr
         Along the dimension shows: \cr
         a^(lo)_pldegree, a_pldegree, a^(hi)_pldegree,\cr
         a^(lo)_(pldegree-1), a_(pldegree-1), a^(hi)_(pldegree-1), ...\cr
         a_0 (intercept), a^(lo)_0, and a^(hi)_0, \cr
         where (lo)/(hi) is the lower/upper limit of the confidence interval
         for each point of the var along all other dimensions.
   }
   \item{conf = FALSE:\cr
         dimension length = pldegree + 3 \cr
      Along the dimension shows: \cr
         a_pldegree,\cr
         a_(pldegree-1), ...\cr
         a_0 (intercept), a^(lo)_0, and a^(hi)_0.
   }
 }
}
\item{$detrended}{
 Same dimensions as var with residual values (after removing polynomial
 fit of pldegree order) along the posTR dimension.
}

Only in .Trend:
\item{$conf.int}{
 Corresponding to the limits of the \code{siglev}\% confidence interval 
 (only present if \code{conf = TRUE}) for the slope coefficient.
}
}
\description{
Computes the trend along the forecast time of the ensemble mean by least 
square fitting, and the associated error interval.\cr
Trend() also provides the time series of the detrended ensemble mean 
forecasts.\cr
The confidence interval relies on a student-T distribution.\cr\cr
.Trend provides the same functionality but taking a matrix ensemble members 
as input (exp).
}
\examples{
example(Load)
months_between_startdates <- 60
trend <- Trend(sampleData$obs, 3, months_between_startdates)
tmp <- Subset(trend$trend, c('dataset', 'member', 'sdate', 'ftime'), 
             list(1, 1, 1:4, 1), drop = FALSE)
PlotVsLTime(tmp, toptitle = "trend", ytitle = "K / (5 year)",
           monini = 11, limits = c(-1,1), listexp = c('CMIP5 IC3'),
           listobs = c('ERSST'), biglab = FALSE, hlines = 0,
           fileout = 'tos_obs_trend.eps')
PlotAno(trend$detrended, NULL, startDates, 
       toptitle = 'detrended anomalies (along the startdates)', ytitle = 'K',
       legends = 'ERSST', biglab = FALSE, fileout = 'tos_detrended_obs.eps')

 # A simple test of a nonlinear fit:
 y0 <- c(10.1, 8.8, 7.3, 4.12, -0.314, -5, -10.6, -18.2)
 y1 <- Trend(var = y0, posTR = 1)                 # linear fit
 y2 <- Trend(var = y0, posTR = 1, pldegree = 2)   # quadratic fit
 plot(y0)
 lines(y0 - y1$detrended, col = 'blue')       # linear fit
 lines(y0 - y2$detrended, col = 'red')        # quadratic fit

}
\author{
History:\cr
0.1  -  2011-05  (V. Guemas, \email{virginie.guemas@ic3.cat})  -  Original code\cr
1.0  -  2013-09  (N. Manubens, \email{nicolau.manubens@ic3.cat})  -  Formatting to CRAN\cr
2.0  -  2017-02  (A. Hunter, \email{alasdair.hunter@bsc.es})  -  Adapt to veriApply()
2.8.6  -  2019-08  (A. Ho, \email{an.ho@bsc.es})  -  Adapt polynomial regression
}
\keyword{datagen}

