Skip to content

Commit

Permalink
version 0.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
config-i1 authored and cran-robot committed Dec 10, 2019
1 parent 1a3355b commit d018a6a
Show file tree
Hide file tree
Showing 18 changed files with 860 additions and 697 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: greybox
Type: Package
Title: Toolbox for Model Building and Forecasting
Version: 0.5.6
Date: 2019-10-29
Version: 0.5.7
Date: 2019-12-10
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 @@ -18,7 +18,8 @@ Description: Implements functions and instruments for regression model building
that allow producing forecasts from these models and visualising them.
License: GPL (>= 2)
Depends: R (>= 3.0.2)
Imports: forecast, stats, graphics, utils, lamW, numDeriv, nloptr
Imports: forecast, stats, graphics, utils, lamW, numDeriv, nloptr,
statmod
LinkingTo: Rcpp
Suggests: smooth (>= 2.5.1), doMC, doParallel, foreach, testthat,
rmarkdown, knitr
Expand All @@ -27,9 +28,9 @@ RoxygenNote: 6.1.1
VignetteBuilder: knitr
Encoding: UTF-8
NeedsCompilation: yes
Packaged: 2019-10-29 00:32:58 UTC; config
Packaged: 2019-12-10 18:10:14 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-10-29 12:20:02 UTC
Date/Publication: 2019-12-10 19:10:02 UTC
34 changes: 17 additions & 17 deletions MD5
@@ -1,9 +1,9 @@
9fdc7d422fd64cc17749e62e4aef34ba *DESCRIPTION
f63b807f73d6ba667118e3c1ab52f3c7 *NAMESPACE
d4e827d75607572c09dd71ea13d87c0f *NEWS
caeae5241bf32148bebc41619f401f0a *DESCRIPTION
88f6b62c2505cd923acb533aa71a45f9 *NAMESPACE
79a548cb6cf9bd4c15f1caf20b5f268a *NEWS
b04f00196442fad912053f13321c737f *R/RcppExports.R
b4cd3781320f7ad18d4aa2c73b1f0816 *R/alaplace.R
13877545456a0cb1061e84838563298c *R/alm.R
9f38a61460c97661a72aee02e8b7b6a4 *R/alm.R
0500006c4fa867061474bbc6b8bc7e13 *R/association.R
fdbad566ff76a378a0baf27be1dcec47 *R/bcnorm.R
9162a49ecbca3900f5da3222c67c35ac *R/cramer.R
Expand All @@ -18,38 +18,38 @@ a191aa85adec68be7bde4dae9d1ef377 *R/greybox-package.R
aa738ea67d2604fce32570f839acf384 *R/lmCombine.R
6bd3c7dc41c2ef2ff60ccc2c455daedd *R/lmDynamic.R
796ec4a77b3426bd3e1d83050bdcee04 *R/mcor.R
e213bee6a258f0e9d0dc23c5f580ebbb *R/methods.R
a1a1cf776af1f43b0aea0ac4d9f09de9 *R/methods.R
4eb0114d8e61620b2764a57598044d98 *R/nemenyi.R
8b8f911c0c70280ed219e581e6313006 *R/rmc.R
b9110e000176cc28ef7cd6fb13f1b195 *R/ro.R
17f1c9ed5675a47a18dc4657769e3376 *R/spread.R
1a038dae1155b438014bf71d5c169dc0 *R/stepwise.R
ee6b602ed64fef9a106d74dd0b965b79 *R/svet.R
c5126d222f9974391af07ab09e83a92b *R/tableplot.R
a3aa25e9c96c36e416aa00bd8e941795 *R/tableplot.R
ade567ae65171c7757b3c200965dff97 *R/tplnorm.R
63d2b0c03f75c7b3ce293821d00d352d *R/xregExpander.R
d81aecb9bdfee4958378ddf7722070ca *R/xregMultiplier.R
ce39c45f7941e5bdb51aef59ef77959c *R/xregTransformer.R
44ef5a5acc7030f87429da3f638a8bf9 *R/zzz.R
812aa6871775f0444a5b253b34068106 *README.md
74d0d12fa24c659b8042371912702b05 *build/partial.rdb
6eb5133bc20ebf6cb0f5ca828338f14b *README.md
23b68f70e36e668500ac610ec184a05e *build/partial.rdb
b8f1463a2c73edf1dd9614f6467d6d5c *build/vignette.rds
261b2676401ed77ade6629fdb123da82 *inst/doc/alm.R
a08c3f8bafd9bde202c2e1c97021261c *inst/doc/alm.Rmd
16f335608ea6f24cf2141d0ef6abc73a *inst/doc/alm.html
59763438c2ad716503b6aba3728e94bc *inst/doc/alm.Rmd
d4f9ff21b3915487d6cac6e70942d444 *inst/doc/alm.html
de89fbff243d1e9e45d6dce6d12637eb *inst/doc/greybox.R
fb1c6e34a89bf961c058e374b8ff6cb7 *inst/doc/greybox.Rmd
d2d9bc281b966dcdcdff19f833f4bb75 *inst/doc/greybox.html
7a25e94cc037c5cfe1bc527898ea1170 *inst/doc/greybox.html
06c0f9122123824d32350fe08d2602f1 *inst/doc/maUsingGreybox.R
993abaa870428627b3e228fbaafa0c0e *inst/doc/maUsingGreybox.Rmd
559ae0721e6db5b3c6f409f25aedd89b *inst/doc/maUsingGreybox.html
5dca8fd06dc1958e8ec05004b84690d2 *inst/doc/maUsingGreybox.html
00c4b1df235949a7bfd28a0ce53c4c25 *inst/doc/ro.R
9dcae2bc19d86bfb5cddf8067823fe8d *inst/doc/ro.Rmd
3b122bfa5e966beef91b4ffd001d9a3f *inst/doc/ro.html
e29251035abc061079acfa891b4e3cd3 *inst/doc/ro.html
289e8c5fa923dd43039cfabae03445a0 *man/InformationCriteria.Rd
b9020e719cce89a6877652348d1f44f5 *man/actuals.Rd
cb2b4b7e514fbfef6547dad20aa89f29 *man/alaplace-distribution.Rd
e81767e2f7de7992a6117d54d022f042 *man/alm.Rd
efe39c7102139a4a5af0a2df6a9ba13d *man/alm.Rd
e8b44bcd31cdf83aa08f416501d6107e *man/association.Rd
1de77fee7d52e89c0b4227f10804df53 *man/bcnorm-distribution.Rd
dd4df3dd66d4a3aafc593b5b2f3ad79b *man/cramer.Rd
Expand All @@ -68,7 +68,7 @@ c5e98637bfcfc56b63d3db17f1bf00b4 *man/hm.Rd
d5d43ddeba1f658dced94e4e7cfc7fa4 *man/measures.Rd
0c8158bf966af11a646027c506b3f90c *man/nparam.Rd
b3b5e1666ffdc078b439c058ff8b20c2 *man/pinball.Rd
44d33d89591c6f82d2e058facb94cb3e *man/plot.greybox.Rd
d6184c29bbca736c0b621779ee48b323 *man/plot.greybox.Rd
adcbb10444b1715904a8270a96fba5f3 *man/pointIC.Rd
2329b1a5db9e98f6328ee8a888a6c7c1 *man/pointLik.Rd
c6ebc1c587ffc34c6161c9a0051dbaeb *man/polyprod.Rd
Expand All @@ -78,14 +78,14 @@ c6ebc1c587ffc34c6161c9a0051dbaeb *man/polyprod.Rd
1222fa1380ef1f2cc2dc099b9a37b5bd *man/s-distribution.Rd
434ed5e6f28e75f16e049552d926f51b *man/spread.Rd
1438b393d81bf6a76a5f791326579bbd *man/stepwise.Rd
a8549efba233cb2e08628dee8da47f61 *man/tableplot.Rd
6e75842d13a488a1f839ac7a63c658e5 *man/tableplot.Rd
35386b7aacb453e2d4a06e1a86e11272 *man/tplnorm-distribution.Rd
22d9f61275e386ee7344dd0a31a6a467 *man/xregExpander.Rd
db95d10f4d7d1be64b615faa54a21dc9 *man/xregMultiplier.Rd
887824e5fab2396082e7cd905e902c81 *man/xregTransformer.Rd
471a2428a7493a27c2f59c352b429357 *src/RcppExports.cpp
b0129f5614ed7877c7af10bd9dce93b0 *src/polyMult.cpp
a08c3f8bafd9bde202c2e1c97021261c *vignettes/alm.Rmd
59763438c2ad716503b6aba3728e94bc *vignettes/alm.Rmd
fb1c6e34a89bf961c058e374b8ff6cb7 *vignettes/greybox.Rmd
8401400e9158cfc020fa9477e42d1fd6 *vignettes/img/ROProcessCO.gif
da71fe35eb5beb45dc2cc8ef16da371a *vignettes/img/ROProcessCOCI.gif
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -172,6 +172,8 @@ importFrom(graphics,title)
importFrom(lamW,lambertWm1)
importFrom(nloptr,nloptr)
importFrom(numDeriv,hessian)
importFrom(statmod,dinvgauss)
importFrom(statmod,qinvgauss)
importFrom(stats,.lm.fit)
importFrom(stats,AIC)
importFrom(stats,BIC)
Expand Down Expand Up @@ -199,6 +201,7 @@ importFrom(stats,frequency)
importFrom(stats,is.ts)
importFrom(stats,lm)
importFrom(stats,logLik)
importFrom(stats,lowess)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,nobs)
Expand Down
14 changes: 14 additions & 0 deletions NEWS
@@ -1,3 +1,17 @@
greybox v0.5.7 (Release data: 2019-12-10)
==============

Changes:
* plot.greybox() now also produces LOWESS lines on the scatterplots. There is a parameters that regulates this.
* A bit of tuning of plot.greybox() graphs.
* Inverse Gaussian distribution for alm() is now available and works okay. Note that this is a non-conventional model. Check vignette for alm() function.
* Legend for tableplot() is now by default FALSE.

Bugfixes:
* alm() would be stuck in some cases, when determination returns NaNs.
* Fix of a bug in alm() for the new version of R, where class(matrix) is now c("matrix","array"), and not just "matrix".


greybox v0.5.6 (Release data: 2019-10-29)
==============

Expand Down
76 changes: 46 additions & 30 deletions R/alm.R
Expand Up @@ -5,34 +5,34 @@
#' This is a function, similar to \link[stats]{lm}, but for the cases of several
#' non-normal distributions. These include:
#' \enumerate{
#' \item Normal distribution, \link[stats]{dnorm},
#' \item Logistic Distribution, \link[stats]{dlogis},
#' \item Laplace distribution, \link[greybox]{dlaplace},
#' \item Asymmetric Laplace distribution, \link[greybox]{dalaplace},
#' \item T-distribution, \link[stats]{dt},
#' \item S-distribution, \link[greybox]{ds},
#' \item Folded normal distribution, \link[greybox]{dfnorm},
#' \item Log normal distribution, \link[stats]{dlnorm},
#' \item Chi-Squared Distribution, \link[stats]{dchisq},
#' \item Beta distribution, \link[stats]{dbeta},
#' \item Poisson Distribution, \link[stats]{dpois},
#' \item Negative Binomial Distribution, \link[stats]{dnbinom},
#' \item Cumulative Logistic Distribution, \link[stats]{plogis},
#' \item Cumulative Normal distribution, \link[stats]{pnorm}.
#' \item \link[stats]{dnorm} - Normal distribution,
#' \item \link[stats]{dlogis} - Logistic Distribution,
#' \item \link[greybox]{dlaplace} - Laplace distribution,
#' \item \link[greybox]{dalaplace} - Asymmetric Laplace distribution,
#' \item \link[stats]{dt} - T-distribution,
#' \item \link[greybox]{ds} - S-distribution,
#' \item \link[greybox]{dfnorm} - Folded normal distribution,
#' \item \link[stats]{dlnorm} - Log normal distribution,
#' \item \link[greybox]{dbcnorm} - Box-Cox normal distribution,
#' \item \link[stats]{dchisq} - Chi-Squared Distribution,
#' \item \link[statmod]{dinvgauss} - Inverse Gaussian distribution,
#' \item \link[stats]{dbeta} - Beta distribution,
#' \item \link[stats]{dpois} - Poisson Distribution,
#' \item \link[stats]{dnbinom} - Negative Binomial Distribution,
#' \item \link[stats]{plogis} - Cumulative Logistic Distribution,
#' \item \link[stats]{pnorm} - Cumulative Normal distribution.
#' }
#'
#' This function can be considered as an analogue of \link[stats]{glm}, but with the
#' focus on time series. This is why, for example, the function has \code{ar} and
#' \code{i} parameters and produces time series analysis plots with \code{plot(alm(...))}.
#'
#' This function is slower than \code{lm}, because it relies on likelihood estimation
#' of parameters, hessian calculation and matrix multiplication. So think twice when
#' using \code{distribution="dnorm"} here.
#'
#' Probably some other distributions will be added to this function at some point...
#'
#' The estimation is done using likelihood of respective distributions.
#'
#' ALM function currently does not work with factors and does not accept
#' transformations of variables in the formula. So you need to do transformations
#' separately before using the function.
#'
#' See more details and examples in the vignette "ALM":
#' \code{vignette("alm","greybox")}
#'
Expand Down Expand Up @@ -192,11 +192,12 @@
#' @importFrom stats model.frame sd terms model.matrix
#' @importFrom stats dchisq dlnorm dnorm dlogis dpois dnbinom dt dbeta
#' @importFrom stats plogis
#' @importFrom statmod dinvgauss
#' @importFrom forecast Arima
#' @export alm
alm <- function(formula, data, subset, na.action,
distribution=c("dnorm","dlogis","dlaplace","dalaplace","ds","dt",
"dfnorm","dlnorm","dchisq","dbcnorm",
"dfnorm","dlnorm","dbcnorm","dinvgauss",
"dpois","dnbinom",
"dbeta",
"plogis","pnorm"),
Expand All @@ -212,7 +213,8 @@ alm <- function(formula, data, subset, na.action,
fast <- depricator(fast, list(...));

distribution <- distribution[1];
if(all(distribution!=c("dnorm","dlogis","dlaplace","dalaplace","ds","dt","dfnorm","dlnorm","dchisq","dbcnorm",
if(all(distribution!=c("dnorm","dlogis","dlaplace","dalaplace","ds","dt","dfnorm","dlnorm",
"dchisq","dbcnorm","dinvgauss",
"dpois","dnbinom","dbeta","plogis","pnorm"))){
if(any(distribution==c("norm","fnorm","lnorm","laplace","s","chisq","logis"))){
warning(paste0("You are using the old value of the distribution parameter.\n",
Expand Down Expand Up @@ -346,10 +348,11 @@ alm <- function(formula, data, subset, na.action,
"dnbinom" = exp(matrixXreg %*% B),
"dchisq" = ifelseFast(any(matrixXreg %*% B <0),1E+100,(matrixXreg %*% B)^2),
"dbeta" = exp(matrixXreg %*% B[1:(length(B)/2)]),
"dbcnorm"=,
"dnorm" =,
"dfnorm" =,
"dlnorm" =,
"dbcnorm"=,
"dinvgauss" =,
"dlaplace" =,
"dalaplace" =,
"dlogis" =,
Expand All @@ -365,6 +368,7 @@ alm <- function(formula, data, subset, na.action,
"dfnorm" = abs(other),
"dlnorm" = sqrt(sum((log(y[otU])-mu[otU])^2)/obsInsample),
"dbcnorm" = sqrt(sum((bcTransform(y[otU],other)-mu[otU])^2)/obsInsample),
"dinvgauss" = sum((y[otU]/mu[otU]-1)^2 / (y[otU]/mu[otU]))/obsInsample,
"dlaplace" = sum(abs(y[otU]-mu[otU]))/obsInsample,
"dalaplace" = sum((y[otU]-mu[otU]) * (other - (y[otU]<=mu[otU])*1))/obsInsample,
"dlogis" = sqrt(sum((y[otU]-mu[otU])^2)/obsInsample * 3 / pi^2),
Expand Down Expand Up @@ -416,6 +420,8 @@ alm <- function(formula, data, subset, na.action,
"dlnorm" = dlnorm(y[otU], meanlog=fitterReturn$mu[otU], sdlog=fitterReturn$scale, log=TRUE),
"dbcnorm" = dbcnorm(y[otU], mu=fitterReturn$mu[otU], sigma=fitterReturn$scale,
lambda=fitterReturn$other, log=TRUE),
"dinvgauss" = dinvgauss(y[otU], mean=fitterReturn$mu[otU],
dispersion=fitterReturn$scale/fitterReturn$mu[otU], log=TRUE),
"dlaplace" = dlaplace(y[otU], mu=fitterReturn$mu[otU], scale=fitterReturn$scale, log=TRUE),
"dalaplace" = dalaplace(y[otU], mu=fitterReturn$mu[otU], scale=fitterReturn$scale,
alpha=fitterReturn$other, log=TRUE),
Expand All @@ -439,6 +445,7 @@ alm <- function(formula, data, subset, na.action,
"dfnorm" =,
"dbcnorm" =,
"dlnorm" = obsZero*(log(sqrt(2*pi)*fitterReturn$scale)+0.5),
"dinvgauss" = obsZero*0.5*(log(pi)+1-suppressWarnings(log(2/fitterReturn$scale))),
"dlaplace" =,
"dalaplace" = obsZero*(1 + log(2*fitterReturn$scale)),
"dlogis" = obsZero*2,
Expand Down Expand Up @@ -679,11 +686,16 @@ alm <- function(formula, data, subset, na.action,
errors <- vector("numeric", obsInsample);
ot <- vector("logical", obsInsample);

if(any(y<0) & any(distribution==c("dfnorm","dlnorm","dbcnorm","dchisq","dpois","dnbinom"))){
if(any(y<0) & any(distribution==c("dfnorm","dlnorm","dbcnorm","dinvgauss","dchisq","dpois","dnbinom"))){
stop(paste0("Negative values are not allowed in the response variable for the distribution '",distribution,"'"),
call.=FALSE);
}

if(any(y==0) & any(distribution==c("dinvgauss")) & !occurrenceModel){
stop(paste0("Zero values are not allowed in the response variable for the distribution '",distribution,"'"),
call.=FALSE);
}

if(any(distribution==c("dpois","dnbinom"))){
if(any(y!=trunc(y))){
stop(paste0("Count data is needed for the distribution '",distribution,"', but you have fractional numbers. ",
Expand Down Expand Up @@ -813,6 +825,7 @@ alm <- function(formula, data, subset, na.action,
if(is.null(parameters)){
# Check, if redundant dummies are left. Remove the first if this is the case
determValues <- determination(matrixXreg[otU, -1, drop=FALSE]);
determValues[is.nan(determValues)] <- 0;
if(any(determValues==1)){
matrixXreg <- matrixXreg[,-(which(determValues==1)[1]+1),drop=FALSE];
variablesNames <- colnames(matrixXreg);
Expand Down Expand Up @@ -1098,7 +1111,7 @@ alm <- function(formula, data, subset, na.action,
}
if(is.null(ellipsis$algorithm)){
# if(recursiveModel){
algorithm <- "NLOPT_LN_BOBYQA";
# algorithm <- "NLOPT_LN_BOBYQA";
# }
# else{
algorithm <- "NLOPT_LN_SBPLX";
Expand Down Expand Up @@ -1242,6 +1255,7 @@ alm <- function(formula, data, subset, na.action,
yFitted[] <- switch(distribution,
"dfnorm" = sqrt(2/pi)*scale*exp(-mu^2/(2*scale^2))+mu*(1-2*pnorm(-mu/scale)),
"dnorm" =,
"dinvgauss" =,
"dlaplace" =,
"dalaplace" =,
"dlogis" =,
Expand Down Expand Up @@ -1269,6 +1283,7 @@ alm <- function(formula, data, subset, na.action,
"dnorm" =,
"dnbinom" =,
"dpois" = y - mu,
"dinvgauss" = y / mu,
"dchisq" = sqrt(y) - sqrt(mu),
"dlnorm"= log(y) - mu,
"dbcnorm"= bcTransform(y,lambda) - mu,
Expand Down Expand Up @@ -1328,14 +1343,15 @@ alm <- function(formula, data, subset, na.action,
if(vcovProduce){
# Only vcov is needed, no point in redoing the occurrenceModel
occurrenceModel <- FALSE;
method.args <- list(eps=1e-4, d=0.1, r=4)
method.args <- list(eps=1e-4, d=0.1, r=4);
# if(CDF){
# method.args <- list(d=1e-6, r=6);
# }
# else{
# if(any(distribution==c("dnbinom","dlaplace","dalaplace","dbcnorm"))){
# method.args <- list(d=1e-6, r=6);
# }
if(distribution==c("dinvgauss")){
method.args <- list(d=1e-6, r=6);
}
# else{
# method.args <- list(d=1e-4, r=4);
# }
Expand Down Expand Up @@ -1370,12 +1386,12 @@ alm <- function(formula, data, subset, na.action,
else{
# See if Choleski works... It sometimes fails, when we don't get to the max of likelihood.
vcovMatrixTry <- try(chol2inv(chol(vcovMatrix)), silent=TRUE);
if(class(vcovMatrixTry)=="try-error"){
if(any(class(vcovMatrixTry)=="try-error")){
warning(paste0("Choleski decomposition of hessian failed, so we had to revert to the simple inversion.\n",
"The estimate of the covariance matrix of parameters might be inaccurate."),
call.=FALSE);
vcovMatrix <- try(solve(vcovMatrix, diag(nVariables), tol=1e-20), silent=TRUE);
if(class(vcovMatrix)=="try-error"){
if(any(class(vcovMatrix)=="try-error")){
warning(paste0("Sorry, but the hessian is singular, so we could not invert it.\n",
"We failed to produce the covariance matrix of parameters."),
call.=FALSE);
Expand Down

0 comments on commit d018a6a

Please sign in to comment.