Title: | Estimation of Dynamic Finite Mixtures |
---|---|
Description: | Allows to perform the dynamic mixture estimation with state-space components and normal regression components, and clustering with normal mixture. Quasi-Bayesian estimation, as well as, that based on the Kerridge inaccuracy approximation are implemented. Main references: Nagy and Suzdaleva (2013) <doi:10.1016/j.apm.2013.05.038>; Nagy et al. (2011) <doi:10.1002/acs.1239>. |
Authors: | Krzysztof Drachal [aut, cre] (Faculty of Economic Sciences, University of Warsaw, Poland) |
Maintainer: | Krzysztof Drachal <[email protected]> |
License: | GPL-3 |
Version: | 2.0 |
Built: | 2024-11-10 06:25:27 UTC |
Source: | CRAN |
This function estimates causal inference through counterfactual predictions from a mixture estimation with state-space components. Multi-step ahead predictions are generated by the Monte Carlo method.
cauimp(object,x.post,y.post,alpha=0.05,n.sim=100)
cauimp(object,x.post,y.post,alpha=0.05,n.sim=100)
object |
object of class |
x.post |
|
y.post |
one column |
alpha |
optional, |
n.sim |
optional, |
list
of
$statistics |
|
$significance |
|
$p |
|
$y.hat |
|
$alpha |
|
$n.sim |
|
$y.sim |
|
Brodersen, K. H., Gallusser, F., Koehler, J., Remy, N., Scott, S. L., 2015, Inferring causal impact using Bayesian structural time-series models. Annals of Applied Statistics 9, 247–274.
Morgan, S. L., Winship, C., 2007, Counterfactuals and Causal Inference, Cambridge University Press.
data(oil) m1 <- mixest1(y=oil[1:300,1,drop=FALSE],x=oil[1:300,-1,drop=FALSE],ftype=0,V=1,W=1,kappa=0.97) x.1 <- oil[301:323,-1,drop=FALSE] y.1 <- oil[301:323,1,drop=FALSE] ci <- cauimp(object=m1,x.post=x.1,y.post=y.1,alpha=0.05,n.sim=100)
data(oil) m1 <- mixest1(y=oil[1:300,1,drop=FALSE],x=oil[1:300,-1,drop=FALSE],ftype=0,V=1,W=1,kappa=0.97) x.1 <- oil[301:323,-1,drop=FALSE] y.1 <- oil[301:323,1,drop=FALSE] ci <- cauimp(object=m1,x.post=x.1,y.post=y.1,alpha=0.05,n.sim=100)
mixest
and tvpreg
Objects.This function renames rows of selected outcomes stored in mixest
and tvpreg
objects. It can be useful in generating better looking plots.
convts(x,ind=NULL, ...)
convts(x,ind=NULL, ...)
x |
object of class |
ind |
optional, |
... |
optional, alternatively, instead of providing |
object of the same class as x
but with renamed rownames of selected outcomes
data(oil) t1 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) plot(t1) t1a <- convts(x=t1,from=as.Date("1990-02-15"),by="month",length.out=nrow(oil[,1,drop=FALSE])) plot(t1a) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100) plot(m1) ind <- as.character(seq(from=as.Date("1990-02-15"),by="month",length.out=nrow(oil[,1,drop=FALSE]))) m1a <- convts(x=m1,ind=ind) plot(m1a)
data(oil) t1 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) plot(t1) t1a <- convts(x=t1,from=as.Date("1990-02-15"),by="month",length.out=nrow(oil[,1,drop=FALSE])) plot(t1a) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100) plot(m1) ind <- as.character(seq(from=as.Date("1990-02-15"),by="month",length.out=nrow(oil[,1,drop=FALSE]))) m1a <- convts(x=m1,ind=ind) plot(m1a)
This function decomposes matrix into
, where
is a lower triangular matrix with unit diagonal and
is a diagonal matrix with non-negative terms.
ldlt(A)
ldlt(A)
A |
symmetric positive-definite |
list
of
$L |
|
$D |
Zhuang, X., 2020, Lecture Notes in Numerical Analysis (MATH 381), University of Alberta.
A <- matrix(c(5,1,1,3),2,2) V <- ldlt(A) V$L V$D V$L %*% V$D %*% t(V$L) A
A <- matrix(c(5,1,1,3),2,2) V <- ldlt(A) V$L V$D V$L %*% V$D %*% t(V$L) A
This function decomposes matrix into
, where
is a lower triangular matrix with unit diagonal and
is a diagonal matrix with non-negative terms.
ltdl(A)
ltdl(A)
A |
symmetric positive-definite |
list
of
$L |
|
$D |
de Jonge, P., Tiberius, C., 1996, The LAMBDA Method for Integer Ambiguity Estimation: Implementation Aspects, Universiteitsdrukkerij TU Delft.
A <- matrix(c(5,1,1,3),2,2) V <- ltdl(A) V$L V$D t(V$L) %*% V$D %*% V$L A
A <- matrix(c(5,1,1,3),2,2) V <- ltdl(A) V$L V$D t(V$L) %*% V$D %*% V$L A
This function estimates recursively mixtures with state-space components with a dynamic model of switching. The components are normal linear models. Suppose there are available potentially important predictors of
y
, i.e., . Then up to
linear models including constant term can be created by inclding or not including each of these predictors in the individual model, i.e., component of the mixture.
mixest1(y,x,mods=NULL,ftype=NULL,lambda=NULL,kappa=NULL,V=NULL,W=NULL,atype=NULL)
mixest1(y,x,mods=NULL,ftype=NULL,lambda=NULL,kappa=NULL,V=NULL,W=NULL,atype=NULL)
y |
one column |
x |
|
mods |
optional, |
ftype |
optional, |
lambda |
optional, |
kappa |
optional, |
V |
optional, |
W |
optional, |
atype |
optional, |
object of class mixest
, i.e., list
of
$y.hat |
|
$rvi |
|
$coef |
|
$weights |
|
$V |
|
$R |
|
$components |
|
$parameters |
|
$data.last |
|
Nagy, I., Suzdaleva, E., 2013, Mixture estimation with state-space components and Markov model of switching. Applied Mathematical Modelling 37, 9970–9984.
Barbieri, M. M., Berger, J. O., 2004, Optimal predictive model selection. The Annals of Statistics 32, 870–897.
Burnham, K. P., Anderson, D. R., 2002, Model Selection and Multimodel Inference, Springer.
Karny, M. (ed.), 2006, Optimized Bayesian Dynamic Advising, Springer.
Koop, G., Korobilis, D., 2012, Forecasting inflation using Dynamic Model Averaging. International Economic Review 53, 867–886.
Nagy, I., Suzdaleva, E., 2017, Algorithms and Programs of Dynamic Mixture Estimation, Springer.
Quarteroni, A., Sacco, R., Saleri, F., 2007, Numerical Mathematics, Springer.
Raftery, A. E., Karny, M., Ettler, P., 2010, Online prediction under model uncertainty via Dynamic Model Averaging: Application to a cold rolling mill. Technometrics 52, 52–66.
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100) # Models with only one variable mods <- diag(1,nrow=ncol(oil[,-1,drop=FALSE]),ncol=ncol(oil[,-1,drop=FALSE])) mods <- cbind(1,mods) m2 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],mods=mods,ftype=1,V=100,W=100)
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100) # Models with only one variable mods <- diag(1,nrow=ncol(oil[,-1,drop=FALSE]),ncol=ncol(oil[,-1,drop=FALSE])) mods <- cbind(1,mods) m2 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],mods=mods,ftype=1,V=100,W=100)
This function estimates recursively mixtures with normal regression components with a dynamic model of switching.
mixest2(y,x,mods=NULL,ftype=NULL,V=NULL,W=NULL,atype=NULL,Tvar=NULL)
mixest2(y,x,mods=NULL,ftype=NULL,V=NULL,W=NULL,atype=NULL,Tvar=NULL)
y |
one column |
x |
|
mods |
see |
ftype |
optional, |
V |
optional, |
W |
optional, |
atype |
optional, |
Tvar |
optional, |
object of class mixest
, i.e., list
of
$y.hat |
|
$rvi |
|
$coef |
|
$weights |
|
$V |
|
$R |
|
$components |
|
$parameters |
|
Nagy, I., Suzdaleva, E., Karny, M., Mlynarova, T., 2011, Bayesian estimation of dynamic finite mixtures. International Journal of Adaptive Control and Signal Processing 25, 765–787.
Barbieri, M. M., Berger, J. O., 2004, Optimal predictive model selection. The Annals of Statistics 32, 870–897.
Burnham, K. P., Anderson, D. R., 2002, Model Selection and Multimodel Inference, Springer.
Dedecius, K., 2010, Partial Forgetting in Bayesian Estimation, Czech Technical University in Prague.
Karny, M. (ed.), 2006, Optimized Bayesian Dynamic Advising, Springer.
Nagy, I., 2015, Mixture Models and Their Applications, Czech Technical University in Prague.
Nagy, I., Suzdaleva, E., 2017, Algorithms and Programs of Dynamic Mixture Estimation, Springer.
Quarteroni, A., Sacco, R., Saleri, F., 2007, Numerical Mathematics, Springer.
data(oil) m1 <- mixest2(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100)
data(oil) m1 <- mixest2(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=1,V=100,W=100)
Selected data from oil market.
data(oil)
data(oil)
oil
is matrix
object such that columnwise are
WTI – WTI spot price in USD per barrel
MSCI – MSCI World Index
TB3MS – U.S. 3-month treasury bill secondary market rate
TWEXM – Trade weighted U.S. dollar index (Mar, 1973 = 100)
PROD – U.S. product supplied for crude oil and petroleum products in thousands of barrels
The data are in monthly frequency. They cover the period between Feb, 1990 and Dec, 2016. MSCI, TB3MS, TWEXM and PROD are lagged one period back.
The data are provided by Federal Reserve Bank of St. Louis, MSCI and U.S. Energy Information Administration.
https://www.msci.com/end-of-day-data-search
data(oil)
data(oil)
mixest
Object.The function plots selected outcomes from mixest
object.
## S3 method for class 'mixest' plot(x, ...)
## S3 method for class 'mixest' plot(x, ...)
x |
an object of |
... |
not used |
The function plots a few outcomes from mixest
object. First, the estimated regression coefficients are plotted separately for each variable. Credible intervals of 90% are added. Next, if averaging was chosen for forecasting, then relative variable importances are plotted, i.e., sum of weights of models containing the given variable. If selection procedure was chosen for forecasting, it is plotted whether the given variable is included in the selected model at the given time. Finally weights from all component models are presented in one plot.
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=2,V=100,W=100) plot(m1)
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=2,V=100,W=100) plot(m1)
qbnmix
Object.The function plots selected outcomes from qbnmix
object.
## S3 method for class 'qbnmix' plot(x, ...)
## S3 method for class 'qbnmix' plot(x, ...)
x |
an object of |
... |
not used |
The function plots a few outcomes from qbnmix
object. First, it plots means for each cluster. Then, it plots posterior probabilities for each cluster. Finally, estimates of mixing weights for each cluster.
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0) plot(est)
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0) plot(est)
tvpreg
Object.The function plots selected outcomes from tvpreg
object.
## S3 method for class 'tvpreg' plot(x, ...)
## S3 method for class 'tvpreg' plot(x, ...)
x |
an object of |
... |
not used |
The function plots the estimated regression coefficients, separately for each variable. 90% credible intervals are added.
data(oil) t1<- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) plot(t1)
data(oil) t1<- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) plot(t1)
mixest
Object.The function prints selected outcomes obtained from object mixest
.
## S3 method for class 'mixest' print(x, ...)
## S3 method for class 'mixest' print(x, ...)
x |
an object of |
... |
not used |
The function prints the general structure of the model, i.e., names of predictors. It also prints the number of observations (length of time-series) and the number of component models used in estimations (mixing). Additionally it prints the model's parameters (i.e., forecasting method, values of the initial parameters, etc.).
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=2,V=100,W=100) print(m1)
data(oil) m1 <- mixest1(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],ftype=2,V=100,W=100) print(m1)
qbnmix
Object.The function prints selected outcomes obtained from qbnmix
.
## S3 method for class 'qbnmix' print(x, ...)
## S3 method for class 'qbnmix' print(x, ...)
x |
an object of |
... |
not used |
The function prints estimated means and covariance matrices from the last step.
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0) print(est)
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0) print(est)
tvpreg
Object.The function prints selected outcomes obtained from object tvpreg
.
## S3 method for class 'tvpreg' print(x, ...)
## S3 method for class 'tvpreg' print(x, ...)
x |
an object of |
... |
not used |
The function prints the general structure of the model, i.e., names of predictors. It also prints the number of observations (length of time-series) and the regression coefficients as estimated in the last period.
data(oil) t1<- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) print(t1)
data(oil) t1<- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) print(t1)
This function performs a recursive clustering for normal mixtures. Quasi-Bayesian approximation is performed.
qbnmix(y,m=2,mu0=NULL,R0=NULL)
qbnmix(y,m=2,mu0=NULL,R0=NULL)
y |
|
m |
|
mu0 |
optional, initial means, should be a |
R0 |
optional, initial covariance matrices, should be a |
object of class qbnmix
, i.e., list
of
$mu |
|
$R |
|
$alpha |
|
$w |
|
$mu0 |
|
$R0 |
|
Karny, M., Kadlec, J., Sutanto, E.L., 1998, Quasi-Bayes estimation applied to normal mixture, Preprints of The 3rd European IEEE Workshop on Computer-Intensive Methods in Control and Data Processing, Rojicek, J., Valeckova, M., Karny, M., Warwick K. (eds.), UTIA AV CR, 77–82.
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0)
R <- list(matrix(c(1,0.3,0, 0.3,0.3,0, 0,0,0.15),3,3), matrix(c(1,0,0, 0,0.5,0, 0,0,0.2),3,3)) data <- rbind(MASS::mvrnorm(n=180,c(5,2,3),R[[1]]), MASS::mvrnorm(n=20,c(1,2,3),R[[2]])) data <- data[sample(nrow(data)),] mu0 <- list(matrix(c(4.8689,1.9417,3.0175),nrow=1,ncol=3), matrix(c(1.0182,1.9903,2.8847),nrow=1,ncol=3)) est <- qbnmix(y=data,mu0=mu0)
This function computes the square root of a matrix.
sqrtmat(A)
sqrtmat(A)
A |
symmetric positive-definite |
matrix
such that
https://en.wikipedia.org/wiki/Square_root_of_a_matrix
A <- matrix(c(5,1,1,3),2,2) B <- sqrtmat(A) B %*% t(B) A
A <- matrix(c(5,1,1,3),2,2) B <- sqrtmat(A) B %*% t(B) A
This function estimates Time-Varying Parameters regression.
tvp.reg(y,x,lambda=NULL,kappa=NULL,V=NULL,W=NULL)
tvp.reg(y,x,lambda=NULL,kappa=NULL,V=NULL,W=NULL)
y |
one column |
x |
|
lambda |
optional, see |
kappa |
optional, see |
V |
optional, |
W |
optional, |
If lambda
is specified, then the method described by Raftery et al. (2010) is used, with possible extentsion to the one described by Koop and Korobilis (2012). Otherwise, the Kalman filter described as by Nagy and Suzdaleva (2013) is used.
object of class tvpreg
, i.e., list
of
$y.hat |
|
$coef |
|
$R |
|
$V |
|
Koop, G., Korobilis, D., 2012, Forecasting inflation using Dynamic Model Averaging. International Economic Review 53, 867–886.
Nagy, I., Suzdaleva, E., 2017, Algorithms and Programs of Dynamic Mixture Estimation, Springer.
Raftery, A. E., Karny, M., Ettler, P., 2010, Online prediction under model uncertainty via Dynamic Model Averaging: Application to a cold rolling mill. Technometrics 52, 52–66.
data(oil) t1 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) t2 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],V=100,W=100)
data(oil) t1 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],lambda=0.99,V=100,W=100) t2 <- tvp.reg(y=oil[,1,drop=FALSE],x=oil[,-1,drop=FALSE],V=100,W=100)