Skip to content

Commit

Permalink
version 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
config-i1 authored and cran-robot committed Apr 28, 2019
1 parent c158348 commit 03eaa18
Show file tree
Hide file tree
Showing 43 changed files with 782 additions and 485 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: greybox
Type: Package
Title: Toolbox for Model Building and Forecasting
Version: 0.5.0
Date: 2019-04-20
Version: 0.5.1
Date: 2019-04-27
Authors@R: person("Ivan", "Svetunkov", email = "ivan@svetunkov.ru", role = c("aut", "cre"),
comment="Lecturer at Centre for Marketing Analytics and Forecasting, Lancaster University, UK")
URL: https://github.com/config-i1/greybox
Expand All @@ -26,9 +26,9 @@ RoxygenNote: 6.1.1
VignetteBuilder: knitr
Encoding: UTF-8
NeedsCompilation: yes
Packaged: 2019-04-19 20:23:28 UTC; config
Packaged: 2019-04-27 14:48:25 UTC; config
Author: Ivan Svetunkov [aut, cre] (Lecturer at Centre for Marketing Analytics
and Forecasting, Lancaster University, UK)
Maintainer: Ivan Svetunkov <ivan@svetunkov.ru>
Repository: CRAN
Date/Publication: 2019-04-21 15:20:07 UTC
Date/Publication: 2019-04-28 06:50:03 UTC
83 changes: 42 additions & 41 deletions MD5
@@ -1,56 +1,57 @@
5120e6f9fd3f26e9466848f468f63a05 *DESCRIPTION
a59fdaba5a2d59f5c9616ef6e9dbf4dc *NAMESPACE
89dc95af2ca3d643a1bd3153da39ebc4 *NEWS
ea3d2b1fb8c698a0357e514f1315adbf *DESCRIPTION
d23badbe67af373909ac1bae7af88dc6 *NAMESPACE
f24e5b171a152f34f699690e5f98778c *NEWS
b04f00196442fad912053f13321c737f *R/RcppExports.R
85c21a9b53ef02d0e144fc10457e8299 *R/alaplace.R
03e8b2c483efe8bc4e7a1cd82a788777 *R/alm.R
33b094f9dbcedf3b193a8294bf03bbb5 *R/alm.R
30cb2968efe444dce761b47aa481fdfd *R/association.R
8b20ed80c388c24e107b84d7963d9cc6 *R/cramer.R
6c2c272c7f476538f72df85e976f5feb *R/determination.R
7dbc8c821cf84f94a9d89dd3c7b3645c *R/error-measures.R
979ca02906be18365a3890b4c6b59d64 *R/depricator.R
865edfd94ff16b32829c64bde6dbc56e *R/determination.R
950c8410b827e16a4f3f7871edd409a6 *R/error-measures.R
8a9e233ba5a65a27944d0d85bd94a6be *R/fnorm.R
cbc4215ab53b8b6b604a133e50826f24 *R/graphmaker.R
0f32d843d2182f6d220d7f6bed8853ff *R/greybox-package.R
816dff34a584c66c3469dd6e78991a42 *R/isFunctions.R
10b327bb93afbd6a69ad57b78d31600b *R/laplace.R
7d3a2c44903766f9276014d673470561 *R/lmCombine.R
0cfeacafc5f325c792963572844a4dfd *R/lmDynamic.R
bf0051b5ddb0826a6af63cda10acab0f *R/lmCombine.R
89d49f709dda2650d784179699c5035d *R/lmDynamic.R
c6f59f39b989d287ce0b6b816f3ea10c *R/mcor.R
88c917c5d254e25ec7143eaf1279bdca *R/methods.R
45caedf18e0295d9337600cd8b4db28b *R/nemenyi.R
76ae2c970424270b4b4e51fe3685e08e *R/rmc.R
18459294b633e7c031b1b516459c0c2d *R/ro.R
10be0680e42df82adbe2968d4ae13eec *R/methods.R
4eb0114d8e61620b2764a57598044d98 *R/nemenyi.R
77af49a47b17e4ab8478072870235457 *R/rmc.R
92770d59ccff4777da69126b3c75b641 *R/ro.R
52013bcf9dc41a285a6ce7e52b6d0e73 *R/spread.R
f51bd47573c6ae96dde9b4948e9ac6a6 *R/stepwise.R
8ad0baff60ccfaeb0326786164ad3005 *R/stepwise.R
9bc298937656a271c984d7b44ca69acc *R/svet.R
b3386e40999273985e10aa224e55d8b7 *R/tableplot.R
ade567ae65171c7757b3c200965dff97 *R/tplnorm.R
f818b81c6bf3b90cf6f56d537cd2fd33 *R/xregExpander.R
cf91a0f5526bc577ebea8c22aae476c8 *R/xregMultiplier.R
620aff92f8390742bfff78921c022b46 *R/xregTransformer.R
36e17abd26fc40fc48f9804d04c95157 *R/xregExpander.R
6767a122b503ba8c6f17f2fa1cf3ad3c *R/xregMultiplier.R
b24003a3efb4e32312d6dd50c743dcd7 *R/xregTransformer.R
44ef5a5acc7030f87429da3f638a8bf9 *R/zzz.R
c21ca491ef7a1f8601700175d6c4220c *README.md
9b7278bfbfa7380d961abc96c8a7ddc8 *build/partial.rdb
7d0e2f6ae51386a230af5c1f9870f9c3 *README.md
65251d6927749f053044ae4e3b247727 *build/partial.rdb
a5d02f5a2e927d5630fb9e824580c94f *build/vignette.rds
b8849ab68567bef8294971d1a1f8062f *inst/doc/alm.R
77f5c1698b0805b4ee08c71a94262ab7 *inst/doc/alm.Rmd
5337e48da483402ba01af9335a9e949f *inst/doc/alm.html
34b8d6dbd9447295256603c890809251 *inst/doc/greybox.R
47b097201bb516498457f3c5c2c4e289 *inst/doc/greybox.Rmd
5fb17f8c949e6c6bba0b10fc769e0b00 *inst/doc/greybox.html
261b2676401ed77ade6629fdb123da82 *inst/doc/alm.R
229ee10828fb87bc551ab19bb687a672 *inst/doc/alm.Rmd
707d26df78795ef9fa936226481fd49d *inst/doc/alm.html
de89fbff243d1e9e45d6dce6d12637eb *inst/doc/greybox.R
16e442b993a2d27f172a9b5929b66552 *inst/doc/greybox.Rmd
8ef8cf6db356775fc719fce062835615 *inst/doc/greybox.html
06c0f9122123824d32350fe08d2602f1 *inst/doc/maUsingGreybox.R
993abaa870428627b3e228fbaafa0c0e *inst/doc/maUsingGreybox.Rmd
bc6bf27c35be861795863486e6d8eb7a *inst/doc/maUsingGreybox.html
ee0763bd0572b541210394c7d271f0fc *inst/doc/maUsingGreybox.html
00c4b1df235949a7bfd28a0ce53c4c25 *inst/doc/ro.R
9dcae2bc19d86bfb5cddf8067823fe8d *inst/doc/ro.Rmd
0907e3b1c827605a4393544f60a79f87 *inst/doc/ro.html
22150bbbb82cb704495e8bd1f3d1abc3 *inst/doc/ro.html
289e8c5fa923dd43039cfabae03445a0 *man/InformationCriteria.Rd
b9020e719cce89a6877652348d1f44f5 *man/actuals.Rd
cb2b4b7e514fbfef6547dad20aa89f29 *man/alaplace-distribution.Rd
73ae0fc31d657def6a78895462c05676 *man/alm.Rd
59b241f738760750dc0943f3d5ae7fe7 *man/alm.Rd
4e4fa840514ec11ead4a8dd3788f25db *man/association.Rd
310d3560a6a2368d0db155f8ac76d5df *man/cramer.Rd
f3ede78db376113c8a0de586ec21477b *man/determination.Rd
c762561d3eb625cc8381ad7698021b8b *man/determination.Rd
d65ead5be787e26f70a7dc83dd86ba94 *man/error-measures.Rd
7107d89e7d1666697d37f3ffe06b2ff9 *man/errorType.Rd
b834b75de6d1a3223dab7d2c1ea33cf4 *man/fnorm-distribution.Rd
Expand All @@ -59,30 +60,30 @@ b834b75de6d1a3223dab7d2c1ea33cf4 *man/fnorm-distribution.Rd
c5e98637bfcfc56b63d3db17f1bf00b4 *man/hm.Rd
2d4f3a117c9753dc267093b56d53790b *man/isFunctions.Rd
7798f3873ab82e9a328544beca1a1985 *man/laplace-distribution.Rd
4f46c195e5f80c71f6b436a5518db7e2 *man/lmCombine.Rd
1e0c5244b4c9a9c84ab6fa99a6511001 *man/lmDynamic.Rd
0e2628228a63bdb169df0cd398f422a8 *man/lmCombine.Rd
3e705cbb68866d684197f1c883cc730a *man/lmDynamic.Rd
65e76738c4d650cb902700d2a4459f0f *man/mcor.Rd
1ff2fe86ba023ed7a23b94a67398e07f *man/measures.Rd
2b38ed83d1094051dd1dfe6987d5ebcb *man/nparam.Rd
6641a990e71465b2dc98b1f365651732 *man/measures.Rd
0c8158bf966af11a646027c506b3f90c *man/nparam.Rd
b3b5e1666ffdc078b439c058ff8b20c2 *man/pinball.Rd
adcbb10444b1715904a8270a96fba5f3 *man/pointIC.Rd
2329b1a5db9e98f6328ee8a888a6c7c1 *man/pointLik.Rd
c6ebc1c587ffc34c6161c9a0051dbaeb *man/polyprod.Rd
89dbf1349d86af07999975c0a3468d4b *man/predict.greybox.Rd
76b532e9db2f249cd5704ce73b63d92a *man/rmc.Rd
783f313b049ae8a234c5fd561e282987 *man/ro.Rd
170787ed5a244288ee0ad65bc8327ad4 *man/predict.greybox.Rd
646411d7acf62d6936d44540fc0c0174 *man/rmc.Rd
3331f937425b44fa1f164f2687d1cb72 *man/ro.Rd
1222fa1380ef1f2cc2dc099b9a37b5bd *man/s-distribution.Rd
5f415868101d7038afba79bd5ac7d584 *man/spread.Rd
32a1e1208afdd87e3a09e3e5f795be1d *man/stepwise.Rd
6117c87fc41b5411ad3a3045bc40a06c *man/stepwise.Rd
9d6dddb2e8a11c2b939bc71dde7466d1 *man/tableplot.Rd
35386b7aacb453e2d4a06e1a86e11272 *man/tplnorm-distribution.Rd
f18a73c1ad722b3c5a7b0e1182e7d74d *man/xregExpander.Rd
ecaff1d893d0e2226b358df3b6e18cd8 *man/xregMultiplier.Rd
f12ae6912dd367d0f39d80dfcb5aca80 *man/xregTransformer.Rd
d21e50e7ddf5ec39ed3714e46125c791 *man/xregExpander.Rd
103d8d8e980e3ba1b7ddd6588768e60b *man/xregMultiplier.Rd
cb49a89759ba4929b99bf527870f68c1 *man/xregTransformer.Rd
471a2428a7493a27c2f59c352b429357 *src/RcppExports.cpp
977761aa6ae19c9fe2466383536ea331 *src/polyMult.cpp
77f5c1698b0805b4ee08c71a94262ab7 *vignettes/alm.Rmd
47b097201bb516498457f3c5c2c4e289 *vignettes/greybox.Rmd
229ee10828fb87bc551ab19bb687a672 *vignettes/alm.Rmd
16e442b993a2d27f172a9b5929b66552 *vignettes/greybox.Rmd
8401400e9158cfc020fa9477e42d1fd6 *vignettes/img/ROProcessCO.gif
da71fe35eb5beb45dc2cc8ef16da371a *vignettes/img/ROProcessCOCI.gif
7f2a09e79b06d202de45672aa9762d16 *vignettes/img/ROProcessNoCO.gif
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Expand Up @@ -17,7 +17,6 @@ S3method(errorType,ets)
S3method(forecast,alm)
S3method(forecast,greybox)
S3method(logLik,alm)
S3method(nParam,default)
S3method(nobs,alm)
S3method(nobs,greybox)
S3method(nobs,varest)
Expand Down Expand Up @@ -104,7 +103,6 @@ export(lmCombine)
export(lmDynamic)
export(mcor)
export(measures)
export(nParam)
export(nparam)
export(pAIC)
export(pAICc)
Expand Down
19 changes: 19 additions & 0 deletions NEWS
@@ -1,3 +1,22 @@
greybox v0.5.1 (Release data: 2019-04-27)
==============

Changes:
* The parameter "silent" is now renamed into "quiet" in ro(), xregExpander(), xregMultiplier() and xregTransformer() functions. It only specifies the output in console now.
* Similarly, "bruteForce" is now "bruteforce" in lmCombine(), lmDynamic() and determ(),
* "B" is now "parameters" in alm(),
* "checks" is now "fast" (note, the opposite meaning),
* "style" is now "outplot" in rmc().
* All the functions now return "fitted" instead of "fitted.values". This is not a big deal, the fitted() method will work as always.
* forecast() function now accepts h - the forecast horizon. If h!=nrow(newdata), then the function will either cut off values, or produce forecasts for the explanatory variables.

Bugfixes:
* alm() would not do checks properly when only one explanatory variable was used.
* lmCombine() and lmDynamic() would not work because they would refer to non-existent "ourModel". Thanks leungi for the bug report!
* lmCombine() and lmDynamic() used to warn about the computational time after doing things, not before that.
* predict.alm() would not work well if only one-step-ahead prediction was needed.


greybox v0.5.0 (Release data: 2019-04-20)
==============

Expand Down
26 changes: 15 additions & 11 deletions R/alm.R
Expand Up @@ -66,12 +66,12 @@
#' orders are accepted.
#' @param i the order of I to include in the model. Only non-seasonal
#' orders are accepted.
#' @param B vector of parameters of the linear model. When \code{NULL}, it
#' @param parameters vector of parameters of the linear model. When \code{NULL}, it
#' is estimated.
#' @param vcovProduce whether to produce variance-covariance matrix of
#' coefficients or not. This is done via hessian calculation, so might be
#' computationally costly.
#' @param checks if \code{FALSE}, then the function won't check whether
#' @param fast if \code{FALSE}, then the function won't check whether
#' the data has variability and whether the regressors are correlated. Might
#' cause trouble, especially in cases of multicollinearity.
#' @param ... additional parameters to pass to distribution functions. This
Expand All @@ -91,7 +91,7 @@
#' \item coefficients - estimated parameters of the model,
#' \item vcov - covariance matrix of parameters of the model (based on Fisher
#' Information). Returned only when \code{vcovProduce=TRUE},
#' \item fitted.values - fitted values,
#' \item fitted - fitted values,
#' \item residuals - residuals of the model,
#' \item mu - the estimated location parameter of the distribution,
#' \item scale - the estimated scale parameter of the distribution,
Expand Down Expand Up @@ -199,11 +199,15 @@ alm <- function(formula, data, subset, na.action,
"plogis","pnorm"),
occurrence=c("none","plogis","pnorm"),
ar=0, i=0,
B=NULL, vcovProduce=FALSE, checks=TRUE, ...){
parameters=NULL, vcovProduce=FALSE, fast=TRUE, ...){
# Useful stuff for dnbinom: https://scialert.net/fulltext/?doi=ajms.2010.1.15

cl <- match.call();

#### This is temporary and needs to be removed at some point! ####
B <- depricator(parameters, list(...));
fast <- depricator(fast, list(...));

distribution <- distribution[1];
if(all(distribution!=c("dnorm","dlogis","dlaplace","dalaplace","ds","dt","dfnorm","dlnorm","dchisq",
"dpois","dnbinom","dbeta","plogis","pnorm"))){
Expand Down Expand Up @@ -664,11 +668,11 @@ alm <- function(formula, data, subset, na.action,
obsZero <- 0;
}

if(checks){
if(!fast){
#### Checks of the exogenous variables ####
# Remove the data for which sd=0
noVariability <- vector("logical",nVariables);
noVariability[] <- apply((matrixXreg==matrix(matrixXreg[1,],obsInsample,nVariables,byrow=TRUE))[otU,],2,all);
noVariability[] <- apply((matrixXreg==matrix(matrixXreg[1,],obsInsample,nVariables,byrow=TRUE))[otU,,drop=FALSE],2,all);
if(any(noVariability)){
if(all(noVariability)){
warning("None of exogenous variables has variability. Fitting the straight line.",
Expand All @@ -691,7 +695,7 @@ alm <- function(formula, data, subset, na.action,
corThreshold <- 0.999;
if(nVariables>1){
# Check perfectly correlated cases
corMatrix <- cor(matrixXreg[otU,]);
corMatrix <- cor(matrixXreg[otU,,drop=FALSE]);
corHigh <- upper.tri(corMatrix) & abs(corMatrix)>=corThreshold;
if(any(corHigh)){
removexreg <- unique(which(corHigh,arr.ind=TRUE)[,1]);
Expand All @@ -708,7 +712,7 @@ alm <- function(formula, data, subset, na.action,
# Do these checks only when intercept is needed. Otherwise in case of dummies this might cause chaos
if(nVariables>1 & interceptIsNeeded){
# Check dummy variables trap
detHigh <- determination(matrixXreg[otU,])>=corThreshold;
detHigh <- determination(matrixXreg[otU,,drop=FALSE])>=corThreshold;
if(any(detHigh)){
while(any(detHigh)){
removexreg <- which(detHigh>=corThreshold)[1];
Expand Down Expand Up @@ -737,7 +741,7 @@ alm <- function(formula, data, subset, na.action,
nVariablesExo <- nVariables;

#### Estimate parameters of the model ####
if(is.null(B)){
if(is.null(parameters)){
#### Add AR and I elements in the regression ####
# This is only done, if the regression is estimated. In the other cases it will already have the expanded values
if(ariModel){
Expand All @@ -750,7 +754,7 @@ alm <- function(formula, data, subset, na.action,
yNew[] <- log(yNew / (1-yNew));
}
else{
yNew <- smooth::iss(y,intermittent="l",model="ANN",h=1)$states[1:obsInsample]
yNew <- smooth::oes(y, occurrence="i", model="MNN", h=1)$states[1:obsInsample]
}
ariElements <- xregExpander(yNew, lags=-c(1:ariOrder), gaps="auto")[,-1,drop=FALSE];
ariZeroes <- matrix(TRUE,nrow=obsInsample,ncol=ariOrder);
Expand Down Expand Up @@ -1326,7 +1330,7 @@ alm <- function(formula, data, subset, na.action,
mu <- yFitted;
}

finalModel <- list(coefficients=B, vcov=vcovMatrix, fitted.values=yFitted, residuals=as.vector(errors),
finalModel <- list(coefficients=B, vcov=vcovMatrix, fitted=yFitted, residuals=as.vector(errors),
mu=mu, scale=scale, distribution=distribution, logLik=-CFValue,
df.residual=obsInsample-nParam, df=nParam, call=cl, rank=nParam,
data=dataWork,
Expand Down
29 changes: 29 additions & 0 deletions R/depricator.R
@@ -0,0 +1,29 @@
depricator <- function(newValue, ellipsis){
if(!is.null(ellipsis$silent)){
warning("You have provided 'silent' parameter. This is deprecated. Please, use 'quite' instead.");
return(ellipsis$silent);
}
else if(!is.null(ellipsis$style)){
warning("You have provided 'style' parameter. This is deprecated. Please, use 'outplot' instead.");
return(ellipsis$style);
}
if(!is.null(ellipsis$B)){
warning("You have provided 'B' parameter. This is deprecated. Please, use 'parameters' instead.");
return(ellipsis$B);
}
if(!is.null(ellipsis$checks)){
warning("You have provided 'checks' parameter. This is deprecated. Please, use 'fast' instead.");
return(!ellipsis$checks);
}
else if(!is.null(ellipsis$style)){
warning("You have provided 'style' parameter. This is deprecated. Please, use 'outplot' instead.");
return(ellipsis$style);
}
else if(!is.null(ellipsis$bruteForce)){
warning("You have provided 'bruteForce' parameter. This is deprecated. Please, use 'bruteforce' instead.");
return(ellipsis$bruteForce);
}
else{
return(newValue);
}
}
17 changes: 10 additions & 7 deletions R/determination.R
Expand Up @@ -16,7 +16,7 @@
#' @keywords models
#'
#' @param xreg Data frame or a matrix, containing the exogenous variables.
#' @param bruteForce If \code{TRUE}, then all the variables will be used
#' @param bruteforce If \code{TRUE}, then all the variables will be used
#' for the regression construction (sink regression). If the number of
#' observations is smaller than the number of series, the function will
#' use \link[greybox]{stepwise} function and select only meaningful
Expand All @@ -38,35 +38,38 @@
#' @rdname determination
#' @aliases determ
#' @export determination
determination <- function(xreg, bruteForce=TRUE, ...){
determination <- function(xreg, bruteforce=TRUE, ...){

#### This is temporary and needs to be removed at some point! ####
bruteforce[] <- depricator(bruteforce, list(...));

nVariables <- ncol(xreg);
nSeries <- nrow(xreg);
# Form the vector to return
vectorCorrelationsMultiple <- rep(NA,nVariables);
names(vectorCorrelationsMultiple) <- colnames(xreg);
if(nSeries<=nVariables & bruteForce){
if(nSeries<=nVariables & bruteforce){
# vectorCorrelationsMultiple[] <- 1;
warning(paste0("The number of variables is larger than the number of observations. ",
"Sink regression cannot be constructed. Using stepwise."),
call.=FALSE);
bruteForce <- FALSE;
bruteforce <- FALSE;
}

if(!bruteForce){
if(!bruteforce){
determinationCalculator <- function(residuals, actuals){
return(1 - sum(residuals^2) / sum((actuals-mean(actuals))^2));
}
}

# Calculate the multiple determinations
if(bruteForce & nVariables>1){
if(bruteforce & nVariables>1){
for(i in 1:nVariables){
vectorCorrelationsMultiple[i] <- suppressWarnings(mcor(xreg[,-i],xreg[,i])$value);
}
vectorCorrelationsMultiple <- vectorCorrelationsMultiple^2;
}
else if(!bruteForce & nVariables>1){
else if(!bruteforce & nVariables>1){
testXreg <- xreg;
testModel <- suppressWarnings(stepwise(testXreg));
vectorCorrelationsMultiple[1] <- determinationCalculator(residuals(testModel),
Expand Down
2 changes: 1 addition & 1 deletion R/error-measures.R
Expand Up @@ -470,7 +470,7 @@ sMIS <- function(actual,lower,upper,scale,level=0.95){
#' \item cbias,
#' \item sPIS.
#' }
#' For the details on these errors, see \link[smooth]{Errors}.
#' For the details on these errors, see \link[greybox]{Errors}.
#' @references \itemize{
#' \item Svetunkov, I. (2017). Naughty APEs and the quest for the holy grail.
#' \url{https://forecasting.svetunkov.ru/en/2017/07/29/naughty-apes-and-the-quest-for-the-holy-grail/}
Expand Down

0 comments on commit 03eaa18

Please sign in to comment.