\name{Toymodel}
\alias{Toymodel}
\title{
  Synthetic forecast generator imitating seasonal to decadal forecasts. Tg 
  components of a forecast: (1) predictabiltiy (2) forecast error (3) non-stationarity
  and (4) ensemble generation. The forecast can be computed for real observations or 
  observations generated artifically. 
}
\description{
  The toymodel is based on the model presented in Weigel et al. (2008) QJRS
  with an extension to consider non-stationary distributions prescribing a
  linear trend. The toymodel allows to generate an aritifical forecast
  based on obsevations provided by the input (from Load) or artificially
  generated observations based on the input parameters (sig, trend). 
  The forecast can be specfied for any number of start-dates, lead-time and 
  ensemble members. It imitates components of a forecast: (1) predictabiltiy
  (2) forecast error (3) non-stationarity and (4) ensemble generation. 
  The forecast can be computed for real observations or observations generated
  artifically.

}
 # Returns:
 #   $mod: Forecast based on toymodel using s2dverification structure
 #   $obs: Observations based on toymodel or input using 
 #         s2dverification structure
 # History:
 #   1.0  #  2014-08  (O. Bellprat, omar.bellprat@ic3.cat)  #  Original code  
}
\usage{
   Toymodel(alpha,beta,gamma,sig,trend,nstartd,nleadt,nmbem,obstmp)
}
\arguments{
  \item{alpha}{
    Predicabiltiy of the forecast on the observed residuals 
    Must be a scalar 0<alpha<1
  }
  \item{beta}{
    Standard deviation of forecast error 
    Must be a scalar 0<beta<1
  }
  \item{gamma}{
    Factor on the linear trend to sample model uncertainty.                                                       
    Can be a scalar or a vector of scalars -inf<gammay<inf.
    Defining a scalar results in multiple forecast, 
    corresponding to different models with different trends. 
  }
  \item{sig}{
    Standard deviation of the residual variability of the forecast.
    If observations are provided 'sig' is computed from the observations.
  }

  \item{trend}{
    Linear trend of the forecast. The same trend is used for each lead-time. 
    If observations are provided the 'trend' is computed from the observations,
    with potentially different trends for each lead-time. 
  }
  \item{nstartd}{
    Number of start-dates of the forecast. 
    If observations are provided the 'nstartd' is computed from the observations.
 
  }
  \item{nleadt}{
    Number of lead-times of the forecats.
    If observations are provided the 'nleadt' is computed from the observations.
  }
  \item{obsini}{
    Observations that can be used in the synthetic forecast coming from Load.
    If no observations are provided artifical observations are generated
    based on Gaussian variaiblity with standard deviation from 'sig' and linear
    trend from 'trend'.
  } 
}
\value{
  List of forecast with $mod including the forecast and $obs the observations
  The dimensions correspond to c(length(gamma), nmemb, nstartd, nleadt)
}

\examples{
# Example 1: Generate forecast with artifical observations
#            Seasonal prediction example

a=0.1;b=0.3;g=1;sig=1;t=0.02;ntd=30;nlt=4;nm=10
toyforecast<-Toymodel(alpha=a,beta=b,gamma=g,sig=sig,trend=t,nstartd=ntd,nleadt=nlt,nmemb=nm)

# Example 2: Generate forecast from loaded observations
#            Decadal prediction example

sdates=c('19801101','19851101','19901101','19951101','20001101','20051101')
data<-Load('tas',exp=NULL,'ERAInt',sdates=sdates,lonmin=0,lonmax=359,latmin=-90,latmax=90,
                          nleadtime=NULL,leadtimemin=2,leadtimemax=4, nmember = NULL, storefreq = "monthly", sampleperiod = 1,
                          output = "areave", method = "conservative",grid=NULL)

a=0.1;b=0.3;g=1;nm=10

toyforecast<-Toymodel(alpha=a,beta=b,gamma=g,nmemb=nm,obsini=data$obs)
PlotAno(toyforecast$mod,toyforecast$obs,sdates,toptitle = c("Synthetic decadal temperature prediction"),fileout="ex_toymodel.eps")

}
\author{
  History:
  1.0  -  2014-08  (O.Bellprat)  -  Original code
}
\keyword{datagen}
