\name{ACC_bootstrap}
\alias{ACC_bootstrap}
\title{
  Computes Anomaly Correlation Coefficient (Spatial Correlation)
}
\description{
  Matrix var_exp & var_obs should have dimensions (nexp/nobs,  nsdates,  
  nltimes,  nlat,  nlon).
  ACC computes the Anomaly Correlation Coefficient for each jexp in 
  1:nexp and each jobs in 1:nobs which gives nexp x nobs ACC for each 
  startdate and each leadtime.
  A domain can be selected by providing the list of longitudes/latitudes
  (lon/lat) of the grid together with the corner of the domain:
  lonlatbox = c(lonmin,  lonmax,  latmin,  latmax)
  The confidence intervale and the p-values are estimated from
  a bootstrap or permutation method
}

\usage{
ACC_bootstrap(var_exp, var_obs, sampmet, lon = NULL, lat = NULL,
                          lonlatbox = NULL, nrspa=1000,
                          blocspa=1, center = TRUE)
} 
\arguments{
  \item{var_exp}{
    Matrix of experimental data with dimensions: 
    c(nexp, nsdates, nltimes, nlat, nlon)
  }
  \item{var_obs}{
    Matrix of observational data with the same dimensions as var_exp except 
    along the first dimension:
    c(nobs, nsdates, nltimes, nlat, nlon)
  }
  \item{sampmet}{
    "bootstrap"/"permutation". If "bootstrap" set, observation
    and experiment fields are re-sampled together. The original
    correlation should be included with a 95% probability in the
    confidence interval. In this case, the p-value can not be use to
    estimate the significance. Instead of using the p-value, the
    ACC or MACC will be considered significant if the confident
    interval does not include 0.
    If "permutation" set, a simple spatial permutation of the
    experiment field is done. The confidence interval will be center
    over 0 and can not be used directly as a "real confidence interval".
    The p-value is used to estimate the significance of the result and
    is defined as the percent of the sampled distribition higher than the
    estimated correlation.
  }
  \item{lon}{
    Array of longitudes of the var_exp/var_obs grids, optional.
  }
  \item{lat}{
    Array of latitudes of the var_exp/var_obs grids, optional.
  }
  \item{lonlatbox}{
    Domain to select : c(lonmin, lonmax, latmin, latmax), optional.
  }
  \item{nrspa}{
    number of sample for the bootstrap  (default: 1000)
  }
  \item{blocspa}{
    Length of spatial blocks used for resampling the field (default: 1)
  }
   \item{center}{
    TRUE/FALSE if TRUE (default) compute the center anomaly correlation
    coefficient (using pearson correlation).
    if FALSE, the mean map anomalies are not substracted from both
    oberved and and experiement fields.
  }
}
\value{
  \item{ACC}{
    Matrix with c(nexp,  nobs,  nsdates,  nleadtimes,  4) dimensions.
    The fifth dimension of length 4 corresponds to the lower limit of
    the 95\% confidence interval, which is the 2.5 percentile of the
    bootstrap distribution,  the computed ACC,  the upper limit of 
    the 95\% confidence interval, which is the 97.5 percentile of the
    bootstrap distribution,  and the p-value.
    (see the detail of sampmet arguments)
  }
  \item{MACC}{
    Matrix with c(nexp,  nobs,  nleadtimes,  4) dimensions.
    The fourth dimension of length 4 corresponds to the lower limit of
    the 95\% confidence interval, which is the 2.5 percentile of the
    bootstrap distribution,  the computed ACC,  the upper limit of 
    the 95\% confidence interval, which is the 97.5 percentile of the
    bootstrap distribution,  and the p-value.
    (see the detail of sampmet arguments)
  }
}
\author{
  History:
  1.0 -  2014-05  (C. Prodhomme, \email{chloe.prodhomme@ic3.cat})  -  Original code
}
\examples{
  startDates <- c('19901101', '19951101', '20001101')
  sampleData <- Load('tos', c('i00k'), c('ERSST'), startDates, nleadtime = 124, 
                     leadtimemin = 1, leadtimemax = 20, output = 'lonlat', 
                     latmin = 30, latmax = 45, lonmin = 0, lonmax = 40)
  enmeanmod=Mean1Dim(sampleData$mod,2)
  enmeanobs=Mean1Dim(sampleData$obs,2)

  skill=ACC_bootstrap(enmeanmod,enmeanobs,"bootstrap",nrspa=100)

}
\keyword{datagen}
