@@ -23,6 +23,8 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
23
23
# ' @template ssAuthor
24
24
# ' @template ssKeywords
25
25
# '
26
+ # ' @template ADAMDataFormulaRegLossSilentHHoldout
27
+ # '
26
28
# ' @template smoothRef
27
29
# ' @template ssADAMRef
28
30
# ' @template ssGeneralRef
@@ -48,12 +50,6 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
48
50
# ' @param formula Formula to use in case of explanatory variables. If \code{NULL},
49
51
# ' then all the variables are used as is. Can also include \code{trend}, which would add
50
52
# ' the global trend. Only needed if \code{data} is a matrix or if \code{trend} is provided.
51
- # ' @param regressors The variable defines what to do with the provided explanatory
52
- # ' variables:
53
- # ' \code{"use"} means that all of the data should be used, while
54
- # ' \code{"select"} means that a selection using \code{ic} should be done,
55
- # ' \code{"adapt"} will trigger the mechanism of time varying parameters for the
56
- # ' explanatory variables.
57
53
# ' @param initial Should be a character, which can be \code{"optimal"},
58
54
# ' meaning that all initial states are optimised, or \code{"backcasting"},
59
55
# ' meaning that the initials of dynamic part of the model are produced using
@@ -69,46 +65,11 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
69
65
# ' @param b Second complex smoothing parameter. Can be real if
70
66
# ' \code{seasonality="partial"}. In case of \code{seasonality="full"} must be
71
67
# ' complex number.
72
- # ' @param ic The information criterion to use in the model selection.
73
- # ' @param loss The type of Loss Function used in optimization. \code{loss} can
74
- # ' be:
75
- # ' \itemize{
76
- # ' \item \code{likelihood} - the model is estimated via the maximisation of the
77
- # ' likelihood of the function specified in \code{distribution};
78
- # ' \item \code{MSE} (Mean Squared Error),
79
- # ' \item \code{MAE} (Mean Absolute Error),
80
- # ' \item \code{HAM} (Half Absolute Moment),
81
- # ' \item \code{LASSO} - use LASSO to shrink the parameters of the model;
82
- # ' \item \code{RIDGE} - use RIDGE to shrink the parameters of the model;
83
- # ' \item \code{TMSE} - Trace Mean Squared Error,
84
- # ' \item \code{GTMSE} - Geometric Trace Mean Squared Error,
85
- # ' \item \code{MSEh} - optimisation using only h-steps ahead error,
86
- # ' \item \code{MSCE} - Mean Squared Cumulative Error.
87
- # ' }
88
- # '
89
- # ' Note that model selection and combination works properly only for the default
90
- # ' \code{loss="likelihood"}.
91
- # '
92
- # ' Furthermore, just for fun the absolute and half analogues of multistep estimators
93
- # ' are available: \code{MAEh}, \code{TMAE}, \code{GTMAE}, \code{MACE},
94
- # ' \code{HAMh}, \code{THAM}, \code{GTHAM}, \code{CHAM}.
95
- # '
96
- # ' Last but not least, user can provide their own function here as well, making sure
97
- # ' that it accepts parameters \code{actual}, \code{fitted} and \code{B}. Here is an
98
- # ' example:
99
- # '
100
- # ' \code{lossFunction <- function(actual, fitted, B) return(mean(abs(actual-fitted)))}
101
- # '
102
- # ' \code{loss=lossFunction}
103
- # ' @param h The forecast horizon. Mainly needed for the multistep loss functions.
104
- # ' @param holdout Logical. If \code{TRUE}, then the holdout of the size \code{h}
105
- # ' is taken from the data (can be used for the model testing purposes).
106
68
# ' @param bounds The type of bounds for the persistence to use in the model
107
69
# ' estimation. Can be either \code{admissible} - guaranteeing the stability of the
108
70
# ' model, or \code{none} - no restrictions (potentially dangerous).
109
- # ' @param silent Specifies, whether to provide the progress of the function or not.
110
- # ' If \code{TRUE}, then the function will print what it does and how much it has
111
- # ' already done.
71
+ # ' @param model A previously estimated GUM model, if provided, the function
72
+ # ' will not estimate anything and will use all its parameters.
112
73
# ' @param ... Other non-documented parameters. See \link[smooth]{adam} for
113
74
# ' details
114
75
# '
@@ -119,7 +80,6 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
119
80
# '
120
81
# ' @examples
121
82
# ' y <- rnorm(100,10,3)
122
- # ' ces(y, h=20, holdout=TRUE)
123
83
# ' ces(y, h=20, holdout=FALSE)
124
84
# '
125
85
# ' y <- 500 - c(1:100)*0.5 + rnorm(100,10,3)
@@ -136,11 +96,10 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
136
96
ces <- function (data , seasonality = c(" none" ," simple" ," partial" ," full" ), lags = c(frequency(data )),
137
97
formula = NULL , regressors = c(" use" ," select" ," adapt" ),
138
98
initial = c(" optimal" ," backcasting" ," complete" ), a = NULL , b = NULL ,
139
- ic = c(" AICc" ," AIC" ," BIC" ," BICc" ),
99
+ # ic=c("AICc","AIC","BIC","BICc"),
140
100
loss = c(" likelihood" ," MSE" ," MAE" ," HAM" ," MSEh" ," TMSE" ," GTMSE" ," MSCE" ),
141
- h = 0 , holdout = FALSE ,
142
- bounds = c(" admissible" ," none" ),
143
- silent = TRUE , ... ){
101
+ h = 0 , holdout = FALSE , bounds = c(" admissible" ," none" ), silent = TRUE ,
102
+ model = NULL , ... ){
144
103
# Function estimates CES in state space form with sigma = error
145
104
# and returns complex smoothing parameter value, fitted values,
146
105
# residuals, point and interval forecasts, matrix of CES components and values of
@@ -166,31 +125,31 @@ ces <- function(data, seasonality=c("none","simple","partial","full"), lags=c(fr
166
125
profilesRecentTable <- NULL ;
167
126
168
127
# If a previous model provided as a model, write down the variables
169
- if (! is.null(ellipsis $ model )){
170
- if (is.null(ellipsis $ model $ model )){
128
+ if (! is.null(model )){
129
+ if (is.null(model $ model )){
171
130
stop(" The provided model is not CES." ,call. = FALSE );
172
131
}
173
- else if (smoothType(ellipsis $ model )!= " CES" ){
132
+ else if (smoothType(model )!= " CES" ){
174
133
stop(" The provided model is not CES." ,call. = FALSE );
175
134
}
176
135
# This needs to be fixed to align properly in case of various seasonals
177
- profilesRecentInitial <- profilesRecentTable <- ellipsis $ model $ profileInitial ;
136
+ profilesRecentInitial <- profilesRecentTable <- model $ profileInitial ;
178
137
profilesRecentProvided [] <- TRUE ;
179
138
# This is needed to save initials and to avoid the standard checks
180
- initialValueProvided <- ellipsis $ model $ initial ;
181
- initialOriginal <- initial <- ellipsis $ model $ initialType ;
182
- a <- ellipsis $ model $ parameters $ a ;
183
- b <- ellipsis $ model $ parameters $ b ;
184
- seasonality <- ellipsis $ model $ seasonality ;
185
- matVt <- t(ellipsis $ model $ states );
186
- matWt <- ellipsis $ model $ measurement ;
187
- matF <- ellipsis $ model $ transition ;
188
- vecG <- ellipsis $ model $ persistence ;
189
- ellipsis $ B <- coef(ellipsis $ model );
190
- lags <- lags(ellipsis $ model );
191
-
192
- model <- ellipsis $ model $ model ;
193
- ellipsis $ model <- NULL ;
139
+ initialValueProvided <- model $ initial ;
140
+ initialOriginal <- initial <- model $ initialType ;
141
+ a <- model $ parameters $ a ;
142
+ b <- model $ parameters $ b ;
143
+ seasonality <- model $ seasonality ;
144
+ matVt <- t(model $ states );
145
+ matWt <- model $ measurement ;
146
+ matF <- model $ transition ;
147
+ vecG <- model $ persistence ;
148
+ ellipsis $ B <- coef(model );
149
+ lags <- lags(model );
150
+
151
+ model <- model $ model ;
152
+ model <- NULL ;
194
153
modelDo <- modelDoOriginal <- " use" ;
195
154
}
196
155
else {
@@ -237,7 +196,9 @@ ces <- function(data, seasonality=c("none","simple","partial","full"), lags=c(fr
237
196
constant = FALSE , arma = NULL ,
238
197
outliers = " ignore" , level = 0.99 ,
239
198
persistence = NULL , phi = NULL , initial ,
240
- distribution = " dnorm" , loss , h , holdout , occurrence = " none" , ic , bounds = bounds [1 ],
199
+ distribution = " dnorm" , loss , h , holdout , occurrence = " none" ,
200
+ # This is not needed by the function
201
+ ic = " AICc" , bounds = bounds [1 ],
241
202
regressors = regressors , yName = yName ,
242
203
silent , modelDo , ParentEnvironment = environment(), ellipsis , fast = FALSE );
243
204
0 commit comments