├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── check-standard.yaml │ ├── lint.yaml │ └── test-coverage.yaml ├── .gitignore ├── .lintr ├── .pre-commit-config.yaml ├── DESCRIPTION ├── LICENCE ├── NAMESPACE ├── NEWS ├── R ├── deriv.R ├── imidasreg.R ├── lagspec.R ├── midas_nlpr.R ├── midas_nlpr_methods.R ├── midas_qr_methods.R ├── midas_r_methods.R ├── midas_sp.R ├── midas_sp_methods.R ├── midaslag.R ├── midasqr.R ├── midasr-package.R ├── midasreg.R ├── modsel.R ├── nonparametric.R ├── simulate.R └── tests.R ├── README.md ├── data ├── USpayems.RData ├── USqgdp.RData ├── USrealgdp.RData ├── USunempr.RData ├── oos_prec.RData └── rvsp500.RData ├── demo ├── 00Index ├── RV.R ├── autoreg.R ├── imidasr.R ├── logRV.R ├── nlpr.R ├── okun.R ├── pl.R └── single_index.R ├── inst └── CITATION ├── man ├── UScpiqs.Rd ├── USeffrw.Rd ├── USpayems.Rd ├── USqgdp.Rd ├── USrealgdp.Rd ├── USunempr.Rd ├── agk.test.Rd ├── almonp.Rd ├── almonp_gradient.Rd ├── amidas_table.Rd ├── amweights.Rd ├── average_forecast.Rd ├── check_mixfreq.Rd ├── coef.midas_nlpr.Rd ├── coef.midas_r.Rd ├── coef.midas_sp.Rd ├── deriv_tests.Rd ├── deviance.midas_nlpr.Rd ├── deviance.midas_r.Rd ├── deviance.midas_sp.Rd ├── dmls.Rd ├── expand_amidas.Rd ├── expand_weights_lags.Rd ├── extract.midas_r.Rd ├── fitted.midas_nlpr.Rd ├── fitted.midas_sp.Rd ├── fmls.Rd ├── forecast.midas_r.Rd ├── genexp.Rd ├── genexp_gradient.Rd ├── get_estimation_sample.Rd ├── gompertzp.Rd ├── gompertzp_gradient.Rd ├── hAh_test.Rd ├── hAhr_test.Rd ├── harstep.Rd ├── harstep_gradient.Rd ├── hf_lags_table.Rd ├── imidas_r.Rd ├── lcauchyp.Rd ├── lcauchyp_gradient.Rd ├── lf_lags_table.Rd ├── lstr.Rd ├── lws_table-add.Rd ├── midas_auto_sim.Rd ├── midas_lstr_plain.Rd ├── midas_lstr_sim.Rd ├── midas_mmm_plain.Rd ├── midas_mmm_sim.Rd ├── midas_nlpr.Rd ├── midas_nlpr.fit.Rd ├── midas_pl_plain.Rd ├── midas_pl_sim.Rd ├── midas_qr.Rd ├── midas_r.Rd ├── midas_r.fit.Rd ├── midas_r_ic_table.Rd ├── midas_r_np.Rd ├── midas_r_plain.Rd ├── midas_si_plain.Rd ├── midas_si_sim.Rd ├── midas_sim.Rd ├── midas_sp.Rd ├── midas_u.Rd ├── midasr-package.Rd ├── mls.Rd ├── mlsd.Rd ├── mmm.Rd ├── modsel.Rd ├── nakagamip.Rd ├── nakagamip_gradient.Rd ├── nbeta.Rd ├── nbetaMT.Rd ├── nbetaMT_gradient.Rd ├── nbeta_gradient.Rd ├── nealmon.Rd ├── nealmon_gradient.Rd ├── oos_prec.Rd ├── plot_lstr.Rd ├── plot_midas_coef.midas_nlpr.Rd ├── plot_midas_coef.midas_r.Rd ├── plot_sp.Rd ├── polystep.Rd ├── polystep_gradient.Rd ├── predict.midas_nlpr.Rd ├── predict.midas_r.Rd ├── predict.midas_sp.Rd ├── prep_hAh.Rd ├── rvsp500.Rd ├── select_and_forecast.Rd ├── simulate.midas_r.Rd ├── split_data.Rd ├── update_weights.Rd └── weights_table.Rd ├── midasr.Rproj └── tests ├── testthat.R └── testthat ├── test_methods.R ├── test_midas_nlpr.R ├── test_midas_sp.R ├── test_midaslag.R └── test_midasr.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | .Rhistory 2 | .gitignore 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^\.travis\.yml$ 6 | ^\.github$ 7 | .lintr 8 | .pre-commit-config.yaml 9 | tags 10 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/check-standard.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: lint 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - uses: r-lib/actions/setup-r@v2 20 | with: 21 | use-public-rspm: true 22 | 23 | - uses: r-lib/actions/setup-r-dependencies@v2 24 | with: 25 | extra-packages: any::lintr, local::. 26 | needs: lint 27 | 28 | - name: Lint 29 | run: lintr::lint_package() 30 | shell: Rscript {0} 31 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: covr::codecov(quiet = FALSE) 31 | shell: Rscript {0} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.Rhistory 2 | #Ignore main .RData 3 | *.RData 4 | #Ignore all R transcript files 5 | *.R~ 6 | *.Rt 7 | #Ignore some picture files 8 | *.jpg 9 | *.ps 10 | #*.html 11 | #Ignore emacs and vim temporary files 12 | *.swp 13 | *.swo 14 | .#* 15 | *# 16 | #Ignore Apple files 17 | .DS_Store 18 | #Ignore tex output files 19 | *.log 20 | *.eps 21 | *.aux 22 | *.toc 23 | *.out 24 | *.gz 25 | #Ignore output 26 | #output/* 27 | *~ 28 | 29 | ##Ignore .gitignore 30 | .Rproj.user 31 | tags 32 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: with_defaults( 2 | line_length_linter = line_length_linter(120), 3 | object_name_linter = NULL) 4 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # All available hooks: https://pre-commit.com/hooks.html 2 | # R specific hooks: https://github.com/lorenzwalthert/precommit 3 | repos: 4 | - repo: https://github.com/lorenzwalthert/precommit 5 | rev: v0.1.3 6 | hooks: 7 | - id: style-files 8 | args: [--style_pkg=styler, --style_fun=tidyverse_style] 9 | - id: lintr 10 | - id: readme-rmd-rendered 11 | - id: parsable-R 12 | - id: no-browser-statement 13 | - repo: https://github.com/pre-commit/pre-commit-hooks 14 | rev: v4.0.1 15 | hooks: 16 | - id: check-added-large-files 17 | args: ['--maxkb=200'] 18 | - id: end-of-file-fixer 19 | exclude: '\.Rd' 20 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: midasr 2 | Title: Mixed Data Sampling Regression 3 | Description: Methods and tools for mixed frequency time series data analysis. 4 | Allows estimation, model selection and forecasting for MIDAS regressions. 5 | URL: http://mpiktas.github.io/midasr/ 6 | Version: 0.9 7 | Depends: 8 | R (>= 2.11.0), 9 | sandwich, 10 | optimx, 11 | quantreg 12 | Imports: 13 | MASS, 14 | numDeriv, 15 | Matrix, 16 | forecast, 17 | zoo, 18 | stats, 19 | graphics, 20 | utils, 21 | Formula, 22 | texreg, 23 | methods 24 | License: GPL-2 | MIT + file LICENCE 25 | BugReports: https://github.com/mpiktas/midasr/issues 26 | Suggests: 27 | testthat, 28 | lubridate, 29 | xts 30 | RoxygenNote: 7.3.2 31 | Encoding: UTF-8 32 | Collate: 33 | 'deriv.R' 34 | 'imidasreg.R' 35 | 'lagspec.R' 36 | 'midas_nlpr.R' 37 | 'midas_r_methods.R' 38 | 'midas_nlpr_methods.R' 39 | 'midas_qr_methods.R' 40 | 'midas_sp.R' 41 | 'midas_sp_methods.R' 42 | 'midaslag.R' 43 | 'midasqr.R' 44 | 'midasr-package.R' 45 | 'midasreg.R' 46 | 'modsel.R' 47 | 'nonparametric.R' 48 | 'simulate.R' 49 | 'tests.R' 50 | Authors@R: c( 51 | person(given = "Vaidotas", 52 | family = "Zemlys-Balevičius", 53 | email = "zemlys@gmail.com", 54 | role = "cre"), 55 | person(given = "Virmantas", 56 | family = "Kvedaras", 57 | email = "virmantas.kvedaras@ec.europa.eu", 58 | role = "aut"), 59 | person(given = "Vaidotas", 60 | family= "Zemlys-Balevičius", 61 | email = "zemlys@gmail.com", 62 | role = "aut")) 63 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | YEAR: 2014-2025 2 | COPYRIGHT HOLDER: Virmantas Kvedaras, Vaidotas Zemlys-Balevičius 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("+",lws_table) 4 | S3method(AIC,midas_r_np) 5 | S3method(BIC,midas_r_np) 6 | S3method(bread,midas_r) 7 | S3method(coef,midas_nlpr) 8 | S3method(coef,midas_qr) 9 | S3method(coef,midas_r) 10 | S3method(coef,midas_sp) 11 | S3method(deriv_tests,midas_r) 12 | S3method(deviance,midas_nlpr) 13 | S3method(deviance,midas_r) 14 | S3method(deviance,midas_sp) 15 | S3method(estfun,midas_r) 16 | S3method(fitted,midas_nlpr) 17 | S3method(fitted,midas_sp) 18 | S3method(forecast,midas_r) 19 | S3method(forecast,midas_r_np) 20 | S3method(forecast,midas_u) 21 | S3method(get_datex,ts) 22 | S3method(get_datex,zoo) 23 | S3method(get_datey,default) 24 | S3method(get_datey,ts) 25 | S3method(get_datey,zoo) 26 | S3method(get_frequency_info,default) 27 | S3method(get_frequency_info,midas_r) 28 | S3method(logLik,midas_r) 29 | S3method(plot_midas_coef,midas_nlpr) 30 | S3method(plot_midas_coef,midas_r) 31 | S3method(plot_midas_coef,midas_sp) 32 | S3method(predict,midas_nlpr) 33 | S3method(predict,midas_r) 34 | S3method(predict,midas_r_np) 35 | S3method(predict,midas_sp) 36 | S3method(predict,midas_u) 37 | S3method(print,lws_table) 38 | S3method(print,midas_nlpr) 39 | S3method(print,midas_qr) 40 | S3method(print,midas_r) 41 | S3method(print,midas_r_ic_table) 42 | S3method(print,midas_r_np) 43 | S3method(print,midas_sp) 44 | S3method(print,summary.midas_nlpr) 45 | S3method(print,summary.midas_qr) 46 | S3method(print,summary.midas_r) 47 | S3method(print,summary.midas_sp) 48 | S3method(simulate,midas_r) 49 | S3method(summary,midas_nlpr) 50 | S3method(summary,midas_qr) 51 | S3method(summary,midas_r) 52 | S3method(summary,midas_r_np) 53 | S3method(summary,midas_sp) 54 | S3method(update,midas_nlpr) 55 | S3method(update,midas_r) 56 | S3method(update,midas_r_ic_table) 57 | S3method(update,midas_sp) 58 | S3method(vcov,midas_r) 59 | export(agk.test) 60 | export(almonp) 61 | export(almonp_gradient) 62 | export(amidas_table) 63 | export(amweights) 64 | export(average_forecast) 65 | export(check_mixfreq) 66 | export(deriv_tests) 67 | export(dmls) 68 | export(expand_amidas) 69 | export(expand_weights_lags) 70 | export(extract.midas_r) 71 | export(fmls) 72 | export(forecast) 73 | export(genexp) 74 | export(genexp_gradient) 75 | export(get_estimation_sample) 76 | export(gompertzp) 77 | export(gompertzp_gradient) 78 | export(hAh_test) 79 | export(hAhr_test) 80 | export(harstep) 81 | export(harstep_gradient) 82 | export(hf_lags_table) 83 | export(imidas_r) 84 | export(lcauchyp) 85 | export(lcauchyp_gradient) 86 | export(lf_lags_table) 87 | export(lstr) 88 | export(midas_auto_sim) 89 | export(midas_lstr_plain) 90 | export(midas_lstr_sim) 91 | export(midas_mmm_plain) 92 | export(midas_mmm_sim) 93 | export(midas_nlpr) 94 | export(midas_pl_plain) 95 | export(midas_pl_sim) 96 | export(midas_qr) 97 | export(midas_r) 98 | export(midas_r_ic_table) 99 | export(midas_r_np) 100 | export(midas_r_plain) 101 | export(midas_si_plain) 102 | export(midas_si_sim) 103 | export(midas_sim) 104 | export(midas_sp) 105 | export(midas_u) 106 | export(mls) 107 | export(mlsd) 108 | export(mmm) 109 | export(modsel) 110 | export(nakagamip) 111 | export(nakagamip_gradient) 112 | export(nbeta) 113 | export(nbetaMT) 114 | export(nbetaMT_gradient) 115 | export(nbeta_gradient) 116 | export(nealmon) 117 | export(nealmon_gradient) 118 | export(plot_lstr) 119 | export(plot_midas_coef) 120 | export(plot_sp) 121 | export(polystep) 122 | export(polystep_gradient) 123 | export(select_and_forecast) 124 | export(simulate) 125 | export(split_data) 126 | export(update_weights) 127 | export(weights_table) 128 | import(Matrix) 129 | import(numDeriv) 130 | import(optimx) 131 | import(quantreg) 132 | import(sandwich) 133 | importFrom(Formula,Formula) 134 | importFrom(MASS,ginv) 135 | importFrom(forecast,forecast) 136 | importFrom(graphics,plot) 137 | importFrom(graphics,points) 138 | importFrom(methods,setMethod) 139 | importFrom(numDeriv,jacobian) 140 | importFrom(stats,AIC) 141 | importFrom(stats,BIC) 142 | importFrom(stats,approx) 143 | importFrom(stats,as.formula) 144 | importFrom(stats,as.ts) 145 | importFrom(stats,coef) 146 | importFrom(stats,cor) 147 | importFrom(stats,delete.response) 148 | importFrom(stats,deltat) 149 | importFrom(stats,density) 150 | importFrom(stats,deviance) 151 | importFrom(stats,dnorm) 152 | importFrom(stats,end) 153 | importFrom(stats,filter) 154 | importFrom(stats,fitted) 155 | importFrom(stats,fitted.values) 156 | importFrom(stats,formula) 157 | importFrom(stats,frequency) 158 | importFrom(stats,getCall) 159 | importFrom(stats,lag) 160 | importFrom(stats,lm) 161 | importFrom(stats,lsfit) 162 | importFrom(stats,model.matrix) 163 | importFrom(stats,model.response) 164 | importFrom(stats,na.omit) 165 | importFrom(stats,na.pass) 166 | importFrom(stats,nobs) 167 | importFrom(stats,optim) 168 | importFrom(stats,optimize) 169 | importFrom(stats,pchisq) 170 | importFrom(stats,pnorm) 171 | importFrom(stats,poly) 172 | importFrom(stats,predict) 173 | importFrom(stats,printCoefmat) 174 | importFrom(stats,pt) 175 | importFrom(stats,quantile) 176 | importFrom(stats,residuals) 177 | importFrom(stats,rnorm) 178 | importFrom(stats,runif) 179 | importFrom(stats,sd) 180 | importFrom(stats,setNames) 181 | importFrom(stats,simulate) 182 | importFrom(stats,terms) 183 | importFrom(stats,time) 184 | importFrom(stats,ts) 185 | importFrom(stats,tsp) 186 | importFrom(stats,update.formula) 187 | importFrom(stats,window) 188 | importFrom(texreg,createTexreg) 189 | importFrom(texreg,extract) 190 | importFrom(utils,capture.output) 191 | importFrom(utils,setTxtProgressBar) 192 | importFrom(utils,txtProgressBar) 193 | importFrom(zoo,index) 194 | importFrom(zoo,index2char) 195 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | midasr 0.9 2 | ========== 3 | * Bugfix release to accomodate links in help pages 4 | 5 | midasr 0.8 6 | ========== 7 | * Bugfix release to accomodate M1 architecture 8 | 9 | midasr 0.7 10 | =========== 11 | Major release with new functionality. 12 | 13 | * Add 5 new models. LSTR-MIDAS and MMM-MIDAS are fitted with midas_nlpr. SI-MIDAS and PL-MIDAS are fitted with midas_sp. Quantile MIDAS model are fitted with midas_qr. 14 | 15 | * Add new midas lag implementation mlsd. It allows using time series attributes of the data and can align high frequency into low frequency when the number of high frequency periods is not the same for all low frequency periods. 16 | 17 | * Add support for texreg package. Fitted midasr models can be outputed to nice tables 18 | 19 | midasr 0.6 20 | =========== 21 | A bug fix release 22 | 23 | * Add a CITATION referencing JSS article 24 | 25 | * Fix a few minor bugs in documentation 26 | 27 | 28 | midasr 0.5 29 | ============ 30 | A bug fix release 31 | 32 | * Adapt to new CRAN policy, where all the functions not belonging to base must 33 | be imported. 34 | 35 | * Add generalized exponential lag specification function 36 | 37 | * Fix a small bug in forecast.midas_r, now correct start is set when time series 38 | info is added. 39 | 40 | * Start using testthat for testing the code. 41 | 42 | * Do not lose time series information in forecast 43 | 44 | midasr 0.4 45 | ============ 46 | * Remove unexported code 47 | 48 | * Remove confusing functions dedicated for working with various parameters of MIDAS regression. All of the parameters can now 49 | be accessed with coef method. By default coef returns the parameters of NLS problem. With option midas=TRUE, coef returns the 50 | MIDAS weights. 51 | 52 | * Add function plot_midas_coef for graphical inspection of MIDAS weights. 53 | 54 | * Refactor simulation code, so it is more like arima.sim. 55 | 56 | * Make forecast return the object of class forecast. Add an option of calculating prediction intervals for forecasts. Currently 57 | they are computed via simple bootstraping. This allows using print, summary and plot methods from package forecast. 58 | 59 | * Move to more consistent naming convention a la Hadley Wickham, this means that dot (.) is only used for S3 method dispatch. If there is 60 | no S3 dispatch, the underscore (_) is used. This changes a lot of functions, such as hAhr.test -> hAh_test, all the gradient functions, 61 | so revisit your code for possible breakages. 62 | 63 | * Add ability to pass user defined weight gradients. See the documentation for weight_gradients option for midas_r function. 64 | 65 | 66 | midasr 0.3 67 | ============ 68 | * Add experimental support for nonparametric MIDAS, see Breitung et al. http://www.ect.uni-bonn.de/mitarbeiter/joerg-breitung/npmidas 69 | 70 | * Add dependency and support to the package optimx. This gives more flexibility in chosing the optimisation method. 71 | 72 | * Add data sets needed for midasr user guide. 73 | 74 | * Add GPL-2 licencing 75 | 76 | * Add function midas_r_simple for fitting MIDAS regressions without formula interface. It can be considerably faster than midas_r. 77 | 78 | midasr 0.2 79 | ============ 80 | A bug fix release 81 | 82 | * Fix a bug, where the midas_r_ic_table would not work with formula containing only one term 83 | 84 | * More explicit error messages are displayed when optimisation fails or when robust covariance matrix cannot be calculated 85 | 86 | * Add progress indicator to average_forecast function 87 | 88 | * Fix a bug in data_to_list function, make forecast.midas_r work with midas_u objects. 89 | 90 | * Fix a bug in average_forecast, rolling samples were turning to recursive ones, thanks to Michael Swan for pointing it out. 91 | 92 | 93 | midasr 0.1 94 | ============ 95 | * Release to CRAN. 96 | 97 | 98 | midasr 0.0.8 99 | ============ 100 | 101 | * Milestone release. 102 | 103 | * Support for the lagged dependent variable. 104 | 105 | * Support for the forecasting and forecast combinations. 106 | 107 | * Support for the model selection based on the information criteria 108 | 109 | * First version of the user guide 110 | 111 | 112 | midasr 0.0.6 113 | ============ 114 | 115 | * Milestone release. Full-fledged support for fitting MIDAS regressions without lagged dependent variable. 116 | 117 | * Robust and non-robust tests for MIDAS restriction. 118 | 119 | * The fitted model object has methods for generic functions `coef`, `deviance`, `fitted`, `residuals`, `predict`, `print`, `residuals`, `summary` and `vcov`. Additionally it has method `logLik` for use with `AIC` and `BIC` and methods `estfun` and `bread` for use with `vcovHAC` from package sandwich, i.e. there is support for computing robust standard errors for the coefficients 120 | 121 | * Three demos illustrating the use of the package. They reproduce the results from the article "The statistical content and empirical testing of the MIDAS restrictions". 122 | 123 | midasr 0.0.2 124 | ============ 125 | 126 | * Support for exogenous variables. Supply using `exo` parameter. 127 | 128 | * Option for using numerical gradients. New dependency on package numDeriv. 129 | 130 | 131 | midasr 0.0.1 132 | ============ 133 | 134 | * Initial release. Very basic functionality. Currently only one predictor variable 135 | is allowed. Full functionality of the package is reflected in help page of 136 | function hAh.test. 137 | 138 | -------------------------------------------------------------------------------- /R/deriv.R: -------------------------------------------------------------------------------- 1 | ##' Check whether non-linear least squares restricted MIDAS regression problem has converged 2 | ##' 3 | ##' Computes the gradient and hessian of the optimisation function of restricted MIDAS regression and 4 | ##' checks whether the conditions of local optimum are met. Numerical estimates are used. 5 | ##' @param x \code{\link{midas_r}} object 6 | ##' @param tol a tolerance, values below the tolerance are considered zero 7 | ##' @return a list with gradient, hessian of optimisation function and convergence message 8 | ##' @rdname deriv_tests 9 | ##' @seealso midas_r 10 | ##' @export 11 | ##' @author Vaidotas Zemlys 12 | deriv_tests <- function(x, tol = 1e-6) UseMethod("deriv_tests") 13 | 14 | #' @rdname deriv_tests 15 | #' @method deriv_tests midas_r 16 | #' @export 17 | deriv_tests.midas_r <- function(x, tol = 1e-6) { 18 | gr <- x$gradient(coef(x)) 19 | hess <- x$hessian(coef(x)) 20 | egh <- eigen(hess)$values 21 | 22 | first <- sqrt(sum(gr^2)) < tol 23 | second <- !any(egh < 0) & !any(abs(egh) < tol) 24 | list(first = first, second = second, gradient = gr, eigenval = egh) 25 | } 26 | -------------------------------------------------------------------------------- /R/imidasreg.R: -------------------------------------------------------------------------------- 1 | ##' Restricted MIDAS regression with I(1) regressors 2 | ##' 3 | ##' Estimate restricted MIDAS regression using non-linear least squares, when the regressor is I(1) 4 | ##' 5 | ##' @param formula formula for restricted MIDAS regression. Formula must include \code{\link{fmls}} function 6 | ##' @param data a named list containing data with mixed frequencies 7 | ##' @param start the starting values for optimisation. Must be a list with named elements 8 | ##' @param Ofunction the list with information which R function to use for optimisation 9 | ##' The list must have element named \code{Ofunction} which contains character string of chosen R 10 | ##' function. Other elements of the list are the arguments passed to this function. 11 | ##' The default optimisation function is \code{\link{optim}} with argument \code{method="BFGS"}. 12 | ##' Other supported functions are \code{\link{nls}} 13 | ##' @param weight_gradients a named list containing gradient functions of weights. The weight gradient 14 | ##' function must return the matrix with dimensions \eqn{d_k \times q}, where \eqn{d_k} and \eqn{q} 15 | ##' are the number of coefficients in unrestricted and restricted regressions correspondingly. 16 | ##' The names of the list should coincide with the names of weights used in formula. 17 | ##' The default value is NULL, which means that the numeric approximation of weight 18 | ##' function gradient is calculated. If the argument is not NULL, but the weight 19 | ##' used in formula is not present, it is assumed that there exists an R 20 | ##' function which has the name of the weight function appended with \code{.gradient}. 21 | ##' @param ... additional arguments supplied to optimisation function 22 | ##' @return a \code{midas_r} object which is the list with the following elements: 23 | ##' 24 | ##' \item{coefficients}{the estimates of parameters of restrictions} 25 | ##' \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 26 | ##' \item{model}{model data} 27 | ##' \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 28 | ##' \item{term_info}{the named list. Each element is a list with the information about the term, 29 | ##' such as its frequency, function for weights, gradient function of weights, etc.} 30 | ##' \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 31 | ##' \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 32 | ##' \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 33 | ##' \item{opt}{the output of optimisation procedure} 34 | ##' \item{argmap_opt}{the list containing the name of optimisation function together with arguments 35 | ##' for optimisation function} 36 | ##' \item{start_opt}{the starting values used in optimisation} 37 | ##' \item{start_list}{the starting values as a list} 38 | ##' \item{call}{the call to the function} 39 | ##' \item{terms}{terms object} 40 | ##' \item{gradient}{gradient of NLS objective function} 41 | ##' \item{hessian}{hessian of NLS objective function} 42 | ##' \item{gradD}{gradient function of MIDAS weight functions} 43 | ##' \item{z_env}{the environment in which data is placed} 44 | ##' \item{use_gradient}{TRUE if user supplied gradient is used, FALSE otherwise} 45 | ##' \item{nobs}{the number of effective observations} 46 | ##' \item{convergence}{the convergence message} 47 | ##' \item{fitted.values}{the fitted values of MIDAS regression} 48 | ##' \item{residuals}{the residuals of MIDAS regression} 49 | ##' @author Virmantas Kvedaras, Vaidotas Zemlys 50 | ##' @rdname imidas_r 51 | ##' @seealso midas_r.midas_r 52 | ##' @examples 53 | ##' theta.h0 <- function(p, dk) { 54 | ##' i <- (1:dk-1)/100 55 | ##' pol <- p[3]*i + p[4]*i^2 56 | ##' (p[1] + p[2]*i)*exp(pol) 57 | ##' } 58 | ##' 59 | ##' theta0 <- theta.h0(c(-0.1,10,-10,-10),4*12) 60 | ##' 61 | ##' xx <- ts(cumsum(rnorm(600*12)), frequency = 12) 62 | ##' 63 | ##' ##Simulate the response variable 64 | ##' y <- midas_sim(500, xx, theta0) 65 | ##' 66 | ##' x <- window(xx, start=start(y)) 67 | ##' 68 | ##' imr <- imidas_r(y~fmls(x,4*12-1,12,theta.h0)-1,start=list(x=c(-0.1,10,-10,-10))) 69 | ##' 70 | ##' @details Given MIDAS regression: 71 | ##' 72 | ##' \deqn{y_t=\sum_{j=0}^k\sum_{i=0}^{m-1}\theta_{jm+i} x_{(t-j)m-i}+\mathbf{z_t}\beta+u_t} 73 | ##' 74 | ##' estimate the parameters of the restriction 75 | ##' 76 | ##' \deqn{\theta_h=g(h,\lambda),} 77 | ##' where \eqn{h=0,...,(k+1)m}, together with coefficients \eqn{\beta} corresponding to additional 78 | ##' low frequency regressors. 79 | ##' 80 | ##' It is assumed that \eqn{x} is a I(1) process, hence the special transformation is made. 81 | ##' After the transformation \link{midas_r} is used for estimation. 82 | ##' 83 | ##' MIDAS regression involves times series with different frequencies. 84 | ##' 85 | ##' The restriction function must return the restricted coefficients of 86 | ##' the MIDAS regression. 87 | ##' 88 | ##' @export 89 | imidas_r <- function(formula, data, start, Ofunction = "optim", weight_gradients = NULL, ...) { 90 | z_env <- new.env(parent = environment(formula)) 91 | 92 | mt <- terms(formula(formula), specials = "fmls") 93 | 94 | 95 | if (missing(data)) { 96 | nms <- all.vars(mt) 97 | insample <- lapply(nms, function(nm) eval(as.name(nm), z_env)) 98 | names(insample) <- nms 99 | insample <- insample[!sapply(insample, is.function)] 100 | } 101 | else { 102 | insample <- data_to_list(data) 103 | } 104 | 105 | vl <- as.list(attr(mt, "variables")) 106 | vl <- vl[-1] 107 | 108 | pl <- attr(mt, "specials")$fmls 109 | if (length(pl) > 1) stop("Only one high frequency term is supported currently") 110 | fr <- vl[[pl]] 111 | 112 | ## Do an ugly hack 113 | xname <- as.character(fr[[2]]) 114 | insample <- c(list(insample[[xname]]), insample) 115 | names(insample)[1] <- ".Level" 116 | 117 | assign(".IMIDASdata", insample, envir = z_env) 118 | 119 | wf <- fr[-4:-5] 120 | wf[[1]] <- fr[[5]] 121 | for (j in 3:length(wf)) { 122 | wf[[j]] <- eval(wf[[j]], z_env) 123 | } 124 | wf[[3]] <- wf[[3]] + 1 125 | pp <- function(p, d) { 126 | wf[[2]] <- p 127 | r <- eval(wf, z_env) 128 | cumsum(r)[1:d] 129 | } 130 | mfg <- wf 131 | mfg[[1]] <- as.name(paste(as.character(wf[[1]]), "gradient", sep = ".")) 132 | pp.gradient <- function(p, d) { 133 | mfg[[2]] <- p 134 | r <- eval(mfg, z_env) 135 | apply(r, 2, cumsum)[1:d, ] 136 | } 137 | 138 | formula <- expandfmls(formula(formula), "pp", z_env, 0) 139 | cl <- match.call(expand.dots = TRUE) 140 | cl <- cl[names(cl) != "model"] 141 | 142 | assign("pp", pp, z_env) 143 | assign("pp.gradient", pp.gradient, z_env) 144 | environment(formula) <- z_env 145 | cl[[2]] <- formula 146 | cl[[1]] <- as.name("midas_r") 147 | cl$data <- as.name(".IMIDASdata") 148 | res <- eval(cl, z_env) 149 | class(res) <- c(class(res), "imidas_r") 150 | return(res) 151 | } 152 | 153 | ## Function for expanding the formula in I(1) case 154 | expandfmls <- function(expr, wfun, z_env, diff = 0, truncate = FALSE) { 155 | if (length(expr) == 3) { 156 | expr[[2]] <- expandfmls(expr[[2]], wfun, z_env, diff, truncate) 157 | expr[[3]] <- expandfmls(expr[[3]], wfun, z_env, diff, truncate) 158 | } 159 | if (length(expr) == 5) { 160 | if (expr[[1]] == as.name("fmls")) { 161 | rr <- modifyfmls(expr, wfun, z_env, diff) 162 | if (truncate) { 163 | return(rr[[2]]) 164 | } 165 | else { 166 | return(rr) 167 | } 168 | } 169 | else { 170 | return(expr) 171 | } 172 | } 173 | return(expr) 174 | } 175 | 176 | ## Substitute fmls with dmls 177 | modifyfmls <- function(expr, wfun, z_env, diff) { 178 | res <- expression(a + b)[[1]] 179 | t2 <- expression(mls(x, a, b))[[1]] 180 | nol <- eval(expr[[3]], z_env) 181 | expr[[3]] <- nol + diff 182 | m <- eval(expr[[4]], z_env) 183 | expr[[1]] <- as.name("dmls") 184 | t2[[2]] <- as.name(".Level") 185 | t2[[3]] <- nol + 1 + diff 186 | t2[[4]] <- m 187 | expr[[5]] <- as.name(wfun) 188 | res[[2]] <- expr 189 | res[[3]] <- t2 190 | res 191 | } 192 | -------------------------------------------------------------------------------- /R/midas_qr_methods.R: -------------------------------------------------------------------------------- 1 | ##' @export 2 | ##' @method print midas_qr 3 | print.midas_qr <- function(x, digits = max(3, getOption("digits") - 3), ...) { 4 | print.midas_r(x) 5 | } 6 | 7 | ##' @export 8 | ##' @method coef midas_qr 9 | coef.midas_qr <- function(object, midas = FALSE, term_names = NULL, ...) { 10 | if (is.null(term_names)) { 11 | coef.midas_r(object, midas, ...) 12 | } else { 13 | if (length(object$tau) > 1) { 14 | mc <- object$midas_coefficients 15 | if (length(setdiff(term_names, names(object$term_info))) > 0) { 16 | stop("Some of the term names are not present in estimated MIDAS regression") 17 | } 18 | if (midas) { 19 | res <- lapply(object$term_info[term_names], function(x) object$midas_coefficients[x$midas_coef_index, ]) 20 | } else { 21 | res <- lapply(object$term_info[term_names], function(x) object$coefficients[x$coef_index, ]) 22 | } 23 | names(res) <- NULL 24 | if (length(res) == 1) { 25 | return(res[[1]]) 26 | } else { 27 | return(unlist(res)) 28 | } 29 | } else { 30 | coef.midas_r(object, midas, term_names, ...) 31 | } 32 | } 33 | } 34 | 35 | ## Code is borrowed from summary.nlrq in quantreg 36 | ##' @export 37 | ##' @method summary midas_qr 38 | summary.midas_qr <- function(object, ...) { 39 | y <- object$residuals 40 | tau <- object$tau 41 | cfs <- coef(object) 42 | 43 | do_f <- function(yy, cf, tau) { 44 | XX <- object$model[, -1] %*% object$gradD(cf) 45 | f <- summary(rq(yy ~ XX - 1, tau), se = "boot", covariance = TRUE, ...) 46 | f$coefficients[, 1] <- cf 47 | f$coefficients[, 3] <- f$coefficients[, 1] / f$coefficients[, 2] 48 | f$coefficients[, 4] <- if (f$rdf > 0) 2 * (1 - pt(abs(f$coef[, 3]), f$rdf)) 49 | dimnames(f$coefficients)[[1]] <- names(cf) 50 | f$call <- object$call 51 | f$tau <- tau 52 | f 53 | } 54 | 55 | if (length(tau) > 1) { 56 | all_f <- vector(mode = "list", length(tau)) 57 | for (i in 1:length(tau)) { 58 | cff <- as.vector(cfs[, i]) 59 | names(cff) <- rownames(cfs) 60 | all_f[[i]] <- do_f(as.vector(y[, i]), cff, tau[i]) 61 | } 62 | cf <- lapply(all_f, coef) 63 | } else { 64 | all_f <- do_f(as.vector(y), cfs, tau) 65 | cf <- coef(all_f) 66 | } 67 | 68 | ans <- list( 69 | formula = formula(object$terms), residuals = y, 70 | call = object$call, 71 | f = all_f, 72 | tau = object$tau, 73 | coefficients = cf, midas_coefficients = coef(object, midas = TRUE), 74 | lhs_start = object$lhs_start, lhs_end = object$lhs_end, class_lhs = class(object$lhs) 75 | ) 76 | 77 | class(ans) <- "summary.midas_qr" 78 | ans 79 | } 80 | 81 | ##' @export 82 | ##' @method print summary.midas_qr 83 | print.summary.midas_qr <- function(x, digits = max(3, getOption("digits") - 3), 84 | signif.stars = getOption("show.signif.stars"), ...) { 85 | cat(paste("\nMIDAS quantile regression model with \"", x$class_lhs[1], 86 | "\" data:\n", 87 | sep = "" 88 | )) 89 | cat(paste("Start = ", x$lhs_start, 90 | ", End = ", x$lhs_end, 91 | "\n", 92 | sep = "" 93 | )) 94 | cat("\n Formula", deparse(formula(x)), "\n") 95 | cat("\n Parameters:\n") 96 | cf <- coef(x) 97 | if (length(x$tau) > 1) { 98 | for (i in 1:length(x$tau)) { 99 | cat("\n tau:", x$tau[i], "\n") 100 | printCoefmat(cf[[i]], digits = digits, signif.stars = signif.stars, ...) 101 | } 102 | } else { 103 | cat("\n tau:", x$tau, "\n") 104 | printCoefmat(coef(x), digits = digits, signif.stars = signif.stars, ...) 105 | } 106 | invisible(x) 107 | } 108 | -------------------------------------------------------------------------------- /R/midaslag.R: -------------------------------------------------------------------------------- 1 | ##' Full MIDAS lag structure 2 | ##' 3 | ##' Create a matrix of MIDAS lags, including contemporaneous lag up to selected order. 4 | ##' 5 | ##' @param x a vector 6 | ##' @param k maximum lag order 7 | ##' @param m frequency ratio 8 | ##' @param ... further arguments 9 | ##' @return a matrix containing the lags 10 | ##' @author Virmantas Kvedaras, Vaidotas Zemlys 11 | ##' @seealso mls 12 | ##' @details This is a convenience function, it calls \code{link{mls}} to perform actual calculations. 13 | ##' @export 14 | ##' 15 | fmls <- function(x, k, m, ...) { 16 | mls(x, 0:k, m, ...) 17 | } 18 | 19 | ##' MIDAS lag structure 20 | ##' 21 | ##' Create a matrix of selected MIDAS lags 22 | ##' 23 | ##' @param x a vector 24 | ##' @param k a vector of lag orders, zero denotes contemporaneous lag. 25 | ##' @param m frequency ratio 26 | ##' @param ... further arguments used in fitting MIDAS regression 27 | ##' @return a matrix containing the lags 28 | ##' @author Virmantas Kvedaras, Vaidotas Zemlys 29 | ##' @details The function checks whether high frequency data is complete, i.e. \code{m} must divide \code{length(x)}. 30 | ##' @examples 31 | ##' ## Quarterly frequency data 32 | ##' x <- 1:16 33 | ##' ## Create MIDAS lag for use with yearly data 34 | ##' mls(x,0:3,4) 35 | ##' 36 | ##' ## Do not use contemporaneous lag 37 | ##' mls(x,1:3,4) 38 | ##' 39 | ##' ## Compares with embed when m=1 40 | ##' embed(x,2) 41 | ##' mls(x,0:1,1) 42 | ##' @export 43 | mls <- function(x, k, m, ...) { 44 | n.x <- length(x) 45 | n <- n.x %/% m 46 | 47 | lk <- k 48 | k <- max(k) + 1 49 | mk <- min(k) 50 | if (mk > 0) mk <- 0 51 | 52 | if (n.x %% m != 0) stop("Incomplete high frequency data") 53 | idx <- m * (((k - 1) %/% m + 1):(n - mk)) 54 | 55 | X <- lapply(mk:(k - 1), function(h.x) x[idx - h.x]) 56 | X <- do.call("cbind", X) 57 | 58 | if (k == 1) X <- matrix(X, ncol = 1) 59 | 60 | colnames(X) <- paste0("X", ".", (mk + 1):k - 1, "/", "m") 61 | padd <- matrix(NA, nrow = n - nrow(X), ncol = ncol(X)) 62 | res <- rbind(padd, X) 63 | res[, lk + 1, drop = FALSE] 64 | } 65 | 66 | 67 | ##' MIDAS lag structure for unit root processes 68 | ##' 69 | ##' Prepares MIDAS lag structure for unit root processes 70 | ##' @param x a vector 71 | ##' @param k maximal lag order 72 | ##' @param m frequency ratio 73 | ##' @param ... further arguments used in fitting MIDAS regression 74 | ##' @return a matrix containing the first differences and the lag k+1. 75 | ##' @author Virmantas Kvedaras, Vaidotas Zemlys 76 | ##' @export 77 | dmls <- function(x, k, m, ...) { 78 | dx <- c(NA, diff(x)) 79 | v <- fmls(dx, k, m) 80 | colnames(v) <- gsub("X", "DX", colnames(v)) 81 | v 82 | } 83 | 84 | 85 | ##' Check data for MIDAS regression 86 | ##' 87 | ##' Given mixed frequency data check whether higher frequency data can be converted to the lowest frequency. 88 | ##' 89 | ##' @param data a list containing mixed frequency data 90 | ##' @return a boolean TRUE, if mixed frequency data is conformable, FALSE if it is not. 91 | ##' @details The number of observations in higher frequency data elements should have a common divisor 92 | ##' with the number of observations in response variable. It is always assumed that the response variable 93 | ##' is of the lowest frequency. 94 | ##' 95 | ##' @author Virmantas Kvedaras, Vaidotas Zemlys 96 | ##' @export 97 | check_mixfreq <- function(data) { 98 | obsno <- sapply(data, function(l) ifelse(is.null(dim(l)), length(l), nrow(l))) 99 | m <- obsno %% min(obsno) 100 | 101 | sum(m > 0) == 0 102 | } 103 | 104 | 105 | #' MIDAS lag structure with dates 106 | #' 107 | #' @param x a vector, of high frequency time series. Must be zoo or ts object 108 | #' @param k lags, a vector 109 | #' @param y a vector of low frequency time series. Must be zoo or ts object 110 | #' @param ... further arguments used in fitting MIDAS regression 111 | #' 112 | #' @return a matrix containing the lags 113 | #' @details High frequency time series is aligned with low frequency time series using date information. 114 | #' Then the high frequency lags are calculated. 115 | #' 116 | #' To align the time series the low frequency series index 117 | #' needs to be extended by one low frequency period into the past and into the future. If supplied time series 118 | #' object does not support extending time index, a simple heuristic is used. 119 | #' 120 | #' It is expected that time index for zoo objects can be converted to POSIXct format. 121 | #' 122 | #' 123 | #' @author Virmantas Kvedaras, Vaidotas Zemlys-Balevičius 124 | #' @importFrom stats lag 125 | #' @export 126 | #' 127 | #' @examples 128 | #' 129 | #' # Example with ts objects 130 | #' x <- ts(c(1:144), start = c(1980, 1), frequency = 12) 131 | #' y <- ts(c(1:12), start = 1980, frequency = 1) 132 | #' 133 | #' 134 | #' # msld and mls should give the same results 135 | #' 136 | #' m1 <- mlsd(x, 0:5, y) 137 | #' 138 | #' m2 <- mls(x, 0:5, 12) 139 | #' 140 | #' sum(abs(m1 - m2)) 141 | #' 142 | #' # Example with zooreg 143 | #' 144 | #' # Convert x to zooreg object using yearmon time index 145 | #' \dontrun{ 146 | #' xz <- zoo::as.zooreg(x) 147 | #' 148 | #' yz <- zoo::zoo(as.numeric(y), order.by = as.Date(paste0(1980 + 0:11, "-01-01"))) 149 | #' 150 | #' # Heuristic works here 151 | #' m3 <- mlsd(xz, 0:5, yz) 152 | #' 153 | #' sum(abs(m3 - m1)) 154 | #' } 155 | mlsd <- function(x, k, y, ...) { 156 | datex <- get_datex(x) 157 | 158 | datey <- get_datey(y, datex) 159 | 160 | x <- as.numeric(x) 161 | 162 | ct <- cut(datex, datey, right = FALSE, labels = FALSE, include.lowest = TRUE) 163 | tct <- table(ct) 164 | uct <- unique(ct) 165 | nuct <- na.omit(uct) 166 | # We do not need the first period, but sometimes it is matched. 167 | # In that case it is dropped. 168 | id <- match(2:(length(datey) - 1), nuct) 169 | 170 | fhx <- function(h.x) { 171 | id <- h.x - k 172 | id[id <= 0] <- NA 173 | x[id] 174 | } 175 | XX <- lapply(cumsum(tct), fhx) 176 | X <- do.call("rbind", XX) 177 | colnames(X) <- paste("X", k, sep = ".") 178 | X[id, ] 179 | } 180 | 181 | get_datex <- function(x) UseMethod("get_datex") 182 | 183 | 184 | ##' @exportS3Method get_datex zoo 185 | get_datex.zoo <- function(x) { 186 | as.POSIXct(index(x)) 187 | } 188 | 189 | ##' @exportS3Method get_datex ts 190 | get_datex.ts <- function(x) { 191 | time(x) 192 | } 193 | 194 | get_datey <- function(y, datex) UseMethod("get_datey") 195 | 196 | ##' @exportS3Method get_datey ts 197 | get_datey.ts <- function(y, datex) { 198 | left <- time(lag(y, 1))[1] 199 | right <- tail(time(lag(y, -1)), n = 1) 200 | if (datex[1] < left) left <- datex[1] 201 | c(left, time(y), right) - 0.001 202 | } 203 | 204 | ##' @exportS3Method get_datey default 205 | get_datey.default <- function(y, datex) { 206 | ## If we get here, we assume that both datey and datex are ordered and comparable 207 | datey <- y 208 | left <- datey[1] - (datey[2] - datey[1]) 209 | if (datex[1] < left) left <- datex[1] 210 | nd <- length(datey) 211 | right <- datey[nd] + (datey[nd] - datey[nd - 1]) 212 | c(left, datey, right) 213 | } 214 | 215 | ##' @exportS3Method get_datey zoo 216 | get_datey.zoo <- function(y, datex) { 217 | ## Test whether the lag extends the dates 218 | datey <- y 219 | lagy <- lag(datey, 1) 220 | fd_lagy <- index(lagy)[1] 221 | fd_y <- index(datey)[1] 222 | datey_p <- as.POSIXct(index(datey)) 223 | ## If the dates are not extended use heuristic for left and right low frequency dates 224 | if (fd_lagy == fd_y) { 225 | get_datey.default(datey_p, datex) 226 | } else { 227 | left <- as.POSIXct(fd_lagy) 228 | right <- as.POSIXct(tail(index(lag(datey, -1)), n = 1)) 229 | if (datex[1] < left) left <- datex[1] 230 | return(c(left, datey_p, right)) 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /R/midasr-package.R: -------------------------------------------------------------------------------- 1 | ##' Package for estimating, testing and forecasting MIDAS regression. 2 | ##' 3 | ##' Methods and tools for mixed frequency time series data analysis. Allows estimation, model selection and forecasting for MIDAS regressions. 4 | ##' 5 | ##' @name midasr-package 6 | ##' @aliases midasr 7 | ##' @title Mixed Data Sampling Regression 8 | ##' @author Virmantas Kvedaras \email{virmantas.kvedaras@@mif.vu.lt}, Vaidotas Zemlys (maintainer) \email{zemlys@@gmail.com} 9 | ##' @keywords internal 10 | "_PACKAGE" 11 | 12 | ##' US monthly unemployment rate 13 | ##' 14 | ##' The monthly unemployment rate for United States from 1948 to 2011. 15 | ##' 16 | ##' @name USunempr 17 | ##' @docType data 18 | ##' @format A \code{\link{ts}} object. 19 | ##' @source \href{https://fred.stlouisfed.org/series/UNRATE}{FRED} 20 | ##' @keywords datasets 21 | NULL 22 | 23 | 24 | ##' US annual gross domestic product in billions of chained 2005 dollars 25 | ##' 26 | ##' The annual gross domestic product in billions of chained 2005 dollars for US from 1948 to 2011. 27 | ##' This data is kept for historical purposes, newer data is in 2012 chained dollars. 28 | ##' 29 | ##' @name USrealgdp 30 | ##' @docType data 31 | ##' @format A \code{\link{ts}} object. 32 | ##' @source \href{https://fred.stlouisfed.org/series/GDPC1}{U.S. Department of Commerce, Bureau of Economic Analysis} 33 | ##' @keywords datasets 34 | NULL 35 | 36 | 37 | ##' US quartely seasonaly adjusted consumer price index 38 | ##' 39 | ##' US quarterly CPI from 1960Q1 to 2017Q3s. Seasonaly adjusted, Index 2015=1 40 | ##' 41 | ##' @name UScpiqs 42 | ##' @docType data 43 | ##' @format A \code{\link{data.frame}} object. 44 | ##' @source \href{https://fred.stlouisfed.org/series/CPALTT01USQ661S}{FRED} 45 | ##' @keywords datasets 46 | NULL 47 | 48 | ##' US weekly effective federal funds rate. 49 | ##' 50 | ##' US weekly effective federal funds rate from 1954-07-07 to 2017-12-13 51 | ##' 52 | ##' @name USeffrw 53 | ##' @docType data 54 | ##' @format A \code{\link{data.frame}} object. 55 | ##' @source \href{https://fred.stlouisfed.org/series/DFF}{FRED} 56 | ##' @keywords datasets 57 | NULL 58 | 59 | 60 | ##' Realized volatility of S&P500 index 61 | ##' 62 | ##' Realized volatility of S&P500(Live) index of the period 2000 01 03 - 2013 11 22 63 | ##' 64 | ##' @name rvsp500 65 | ##' @docType data 66 | ##' @format A \code{data.frame} object with two columns. First column contains date id, and the second the realized volatility for S&P500 index. 67 | ##' @source No longer available. Read the statement here: \href{https://oxford-man.ox.ac.uk/research/realized-library/}{https://oxford-man.ox.ac.uk/research/realized-library/} 68 | ##' @references Heber, Gerd and Lunde, Asger, and Shephard, Neil and Sheppard, Kevin \emph{Oxford-Man Institute's realized library}, Oxford-Man Institute, University of Oxford (2009) 69 | ##' @keywords datasets 70 | ##' @examples 71 | ##' ## Do not run: 72 | ##' ## The original data contained the file OxfordManRealizedVolatilityIndices.csv. 73 | ##' ## The code below reproduces the dataset. 74 | ##' 75 | ##' ## rvi <- read.csv("OxfordManRealizedVolatilityIndices.csv",check.names=FALSE,skip=2) 76 | ##' ## ii <- which(rvi$DateID=="20131112") 77 | ##' ## rvsp500 <- na.omit(rvi[1:ii,c("DataID","SPX2.rv")] 78 | NULL 79 | 80 | ##' Out-of-sample prediction precision data on simulation example 81 | ##' 82 | ##' The code in the example generates the out-of-sample prediction precision data for correctly and incorrectly constrained MIDAS regression model compared to unconstrained MIDAS regression model. 83 | ##' @name oos_prec 84 | ##' @docType data 85 | ##' @format A \code{data.frame} object with four columns. The first column indicates the sample size, the second the type of constraint, the third the value of the precision measure and the fourth the type of precision measure. 86 | ##' @keywords datasets 87 | ##' @examples 88 | ##' ## Do not run: 89 | ##' ## set.seed(1001) 90 | ##' 91 | ##' ## gendata<-function(n) { 92 | ##' ## trend<-c(1:n) 93 | ##' ## z<-rnorm(12*n) 94 | ##' ## fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) 95 | ##' ## y<-2+0.1*trend+mls(z,0:16,12)%*%fn.z+rnorm(n) 96 | ##' ## list(y=as.numeric(y),z=z,trend=trend) 97 | ##' ## } 98 | ##' 99 | ##' ## nn <- c(50,100,200,300,500,750,1000) 100 | ##' 101 | ##' ## data_sets <- lapply(n,gendata) 102 | ##' 103 | ##' ## mse <- function(x) { 104 | ##' ## mean(residuals(x)^2) 105 | ##' ## } 106 | ##' 107 | ##' ## bnorm <- function(x) { 108 | ##' ## sqrt(sum((coef(x, midas = TRUE)-c(2,0.1,nealmon(p=c(2,0.5,-0.1),d=17)))^2)) 109 | ##' ## } 110 | ##' 111 | ##' ## rep1 <- function(n) { 112 | ##' ## dt <- gendata(round(1.25*n)) 113 | ##' ## ni <- n 114 | ##' ## ind <- 1:ni 115 | ##' ## mind <- 1:(ni*12) 116 | ##' ## indt<-list(y=dt$y[ind],z=dt$z[mind],trend=dt$trend[ind]) 117 | ##' ## outdt <- list(y=dt$y[-ind],z=dt$z[-mind],trend=dt$trend[-ind]) 118 | ##' ## um <- midas_r(y~trend+mls(z,0:16,12),data=indt,start=NULL) 119 | ##' ## nm <- midas_r(y~trend+mls(z,0:16,12,nealmon),data=indt,start=list(z=c(1,-1,0))) 120 | ##' ## am <- midas_r(y~trend+mls(z,0:16,12,almonp),data=indt,start=list(z=c(1,0,0,0))) 121 | ##' ## modl <- list(um,nm,am) 122 | ##' ## names(modl) <- c("um","nm","am") 123 | ##' ## list(norms=sapply(modl,bnorm), 124 | ##' ## mse=sapply(modl,function(mod)mean((forecast(mod,newdata=outdt)-outdt$y)^2))) 125 | ##' ## } 126 | ##' 127 | ##' ## repr <- function(n,R) { 128 | ##' ## cc <- lapply(1:R,function(i)rep1(n)) 129 | ##' ## list(norms=t(sapply(cc,"[[","norms")),mse=t(sapply(cc,"[[","mse"))) 130 | ##' ## } 131 | ##' 132 | ##' ## res <- lapply(nn,repr,R=1000) 133 | ##' 134 | ##' ## norms <- data.frame(nn,t(sapply(lapply(res,"[[","norms"),function(l)apply(l,2,mean)))) 135 | ##' ## mses <- data.frame(nn,t(sapply(lapply(res,"[[","mse"),function(l)apply(l,2,mean)))) 136 | ##' 137 | ##' 138 | ##' ## msd <- melt(mses[-1,],id=1) 139 | ##' ## colnames(msd)[2] <- "Constraint" 140 | ##' ## nmd <- melt(norms[-1,],id=1) 141 | ##' ## colnames(nmd)[2] <- "Constraint" 142 | ##' 143 | ##' ## msd$Type <- "Mean squared error" 144 | ##' ## nmd$Type <- "Distance from true values" 145 | ##' ## oos_prec <- rbind(msd,nmd) 146 | ##' ## oos_prec$Type <- factor(oos_prec$Type,levels=c("Mean squared error","Distance from true values")) 147 | NULL 148 | 149 | ##' United States gross domestic product, quarterly, seasonaly adjusted annual rate. 150 | ##' 151 | ##' United States gross domestic product, quarterly, seasonaly adjusted annual rate. Retrieved from FRED, symbol "GDP" at 2014-04-25. 152 | ##' 153 | ##' @name USqgdp 154 | ##' @docType data 155 | ##' @format A \code{\link{ts}} object. 156 | ##' @source \href{https://fred.stlouisfed.org/series/GDP}{FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis} 157 | ##' @keywords datasets 158 | ##' @examples 159 | ##' ## Do not run: 160 | ##' ## library(quantmod) 161 | ##' ## USqgdp <- ts(getSymbols("GDP",src="FRED",auto.assign=FALSE),start=c(1947,1),frequency=4) 162 | NULL 163 | 164 | ##' United States total employment non-farms payroll, monthly, seasonally adjusted. 165 | ##' 166 | ##' United States total employment non-farms payroll, monthly, seasonally adjusted. Retrieved from FRED, symbol "PAYEMS" at 2014-04-25. 167 | ##' 168 | ##' @name USpayems 169 | ##' @docType data 170 | ##' @format A \code{\link{ts}} object. 171 | ##' @source \href{https://fred.stlouisfed.org/series/PAYEMS}{FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis} 172 | ##' @keywords datasets 173 | ##' @examples 174 | ##' 175 | ##' ## Do not run: 176 | ##' ## library(quantmod) 177 | ##' ## USpayems <- ts(getSymbols("PAYEMS",src="FRED",auto.assign=FALSE),start=c(1939,1),frequency=12) 178 | NULL 179 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![codecov.io](https://app.codecov.io/github/mpiktas/midasr?branch=main)](https://app.codecov.io/github/mpiktas/midasr?branch=main) 2 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/midasr)](https://cran.r-project.org/package=midasr 3 | ) 4 | [![Downloads](https://cranlogs.r-pkg.org/badges/midasr)](https://www.r-pkg.org/pkg/midasr) 5 | 6 | The **midasr** R package provides econometric methods for working with mixed frequency data. The package provides tools for estimating time series MIDAS regression, where response and explanatory variables are of different frequency, e.g. quarterly vs monthly. The fitted regression model can be tested for adequacy and then used for forecasting. More specifically, the following main functions are available: 7 | 8 | - ```midas_r``` -- MIDAS regression estimation using NLS. 9 | - ```midas_nlpr``` -- Non-linear parametric MIDAS regression estimation. 10 | - ```midas_sp``` -- Semi-parametric and partialy linear MIDAS regression. 11 | - ```midas_qr``` -- Quantile MIDAS regression. 12 | - ```mls``` -- time series embedding to lower frequency, flexible function for specifying MIDAS models. 13 | - ```mlsd``` -- time series embedding to lower frequency using available date information. 14 | - ```hAh.test``` and ```hAhr.test``` -- adequacy testing of MIDAS regression. 15 | - ```forecast``` -- forecasting MIDAS regression. 16 | - ```midasr_ic_table``` -- lag selection using information criteria. 17 | - ```average_forecast``` -- calculate weighted forecast combination. 18 | - ```select_and_forecast``` -- perform model selection and then use the selected model for forecasting. 19 | 20 | The package provides the usual methods for generic functions which can be used on fitted MIDAS regression object: ```summary```, ```coef```, ```residuals```, ```deviance```, ```fitted```, ```predict```, ```logLik```. It also 21 | has additional methods for estimating robust standard errors: ```estfun``` and ```bread```. 22 | 23 | The package also provides all the popular MIDAS regression restrictions such as normalized Almon exponential, normalized beta and etc. 24 | 25 | The package development was influenced by features of the [MIDAS Matlab toolbox][3] created by Eric Ghysels. 26 | 27 | The package has the project [webpage][1] and you can follow its development on [github][2]. 28 | 29 | The detailed description of the package features can be found in the [JSS article][4]. 30 | 31 | # Development 32 | 33 | The stable versions of the package have version numbers x.y. All the stable versions are submitted to [CRAN][5]. The development versions have version numbers x.y.z. 34 | 35 | To install the development version of midasr, it's easiest to use the `devtools` package: 36 | 37 | # install.packages("devtools") 38 | library(devtools) 39 | install_github("midasr","mpiktas") 40 | 41 | 42 | [1]: https://mpiktas.github.io/midasr/ 43 | [2]: https://github.com/mpiktas/midasr 44 | [3]: https://eghysels.web.unc.edu 45 | [4]: https://www.jstatsoft.org/article/view/v072i04 46 | [5]: https://cran.r-project.org/package=midasr 47 | -------------------------------------------------------------------------------- /data/USpayems.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/USpayems.RData -------------------------------------------------------------------------------- /data/USqgdp.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/USqgdp.RData -------------------------------------------------------------------------------- /data/USrealgdp.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/USrealgdp.RData -------------------------------------------------------------------------------- /data/USunempr.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/USunempr.RData -------------------------------------------------------------------------------- /data/oos_prec.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/oos_prec.RData -------------------------------------------------------------------------------- /data/rvsp500.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpiktas/midasr/e170a40a6e1ff2e8fd7aeaddefdb5517df5f43d1/data/rvsp500.RData -------------------------------------------------------------------------------- /demo/00Index: -------------------------------------------------------------------------------- 1 | okun Okun's law demonstration using MIDAS regression 2 | RV Forecasting realized volatility of SP&500 index with MIDAS regression 3 | logRV Forecasting logarithm of realized volatility of SP&500 index with MIDAS regression 4 | autoreg Simulation example of autoregressive MIDAS model 5 | imidasr Simulation example of estimation with I(1) regressors present 6 | nlpr Simulation example of LSTR and MMM MIDAS models 7 | single_index Simulation example of SI MIDAS model 8 | pl Simulation example of PL MIDAS model 9 | -------------------------------------------------------------------------------- /demo/RV.R: -------------------------------------------------------------------------------- 1 | ## More details about the models can be found in the article 2 | ## "The statistical content and empirical testing of the MIDAS restrictions" 3 | ## by Virmantas Kvedaras and Vaidotas Zemlys 4 | 5 | library(midasr) 6 | data(rvsp500) 7 | 8 | ii <- which(rvsp500$DateID == "20120522") 9 | y <- as.numeric(rvsp500[1:ii, 2]) 10 | 11 | allh <- lapply(c(5, 10, 20, 40), function(h) { 12 | rvh <- filter(c(rep(0, h), y), c(rep(1, h), rep(0, h + 1))) 13 | rvh <- rvh[-h:-1] 14 | y <- y[1:length(rvh)] 15 | update(midas_r(rvh ~ fmls(y, 70 - 1, 1, nealmon), start = list(y = rep(0, 3))), Ofunction = "nls") 16 | }) 17 | 18 | #### Compute the derivative test 19 | dtest <- lapply(allh, deriv_tests) 20 | 21 | ### The first derivative tests, gradient is zero 22 | sapply(dtest, with, first) 23 | 24 | ### The second derivative tests, hessian is positive definite 25 | sapply(dtest, with, second) 26 | 27 | ### View summaries 28 | lapply(allh, summary) 29 | 30 | ## Precompute the meat matrix for robust testing. Takes some time to compute!!! 31 | PHI <- lapply(allh, function(x) meatHAC(x$unrestricted, prewhite = TRUE, weights = weightsAndrews)) 32 | 33 | ### Apply hAh test 34 | lapply(allh, hAh_test) 35 | 36 | ## Apply robust hAh test with precomputed PHI 37 | mapply(hAhr_test, allh, PHI, SIMPLIFY = FALSE) 38 | 39 | ## Parameter j is superfluous, j=0 means no logarithm transformation was 40 | ## applied, j=1 means that logarithm transformation was applied. The graph 41 | ## is made to be the same as in the aforementioned article. 42 | 43 | graph <- function(x, phi, j, h) { 44 | k <- length(coef(x, midas = TRUE, term_names = "y")) 45 | pv0hac <- hAhr_test(x, PHI = phi)$p.value 46 | ttl <- sprintf("k(H=%.0f,j=%.0f) = %.0f: p-val.(hAh_HAC) < %.2f", h, j, k, max(pv0hac, 0.01)) 47 | plot_midas_coef(x, title = ttl, term_name = "y") 48 | } 49 | 50 | dev.new() 51 | par(mfrow = c(2, 2)) 52 | 53 | plot_info <- mapply(graph, allh, PHI, as.list(rep(0, 4)), as.list(c(5, 10, 20, 40)), SIMPLIFY = FALSE) 54 | -------------------------------------------------------------------------------- /demo/autoreg.R: -------------------------------------------------------------------------------- 1 | library(midasr) 2 | theta_h0 <- function(p, dk) { 3 | i <- (1:dk - 1) / 100 4 | pol <- p[3] * i + p[4] * i^2 5 | (p[1] + p[2] * i) * exp(pol) 6 | } 7 | 8 | ## Generate coefficients 9 | theta0 <- theta_h0(c(-0.1, 10, -10, -10), 4 * 12) 10 | 11 | 12 | xx <- ts(arima.sim(model = list(ar = 0.6), 3000 * 12), frequency = 12) 13 | 14 | aa <- lapply(c(50, 100, 200, 500, 1000, 1500, 2000), function(n) { 15 | y <- midas_auto_sim(n, 0.5, xx, theta0, n_start = 200) 16 | x <- window(xx, start = start(y)) 17 | midas_r(y ~ mls(y, 1, 1) + fmls(x, 4 * 12 - 1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10))) 18 | }) 19 | 20 | sapply(aa, function(x) c(nrow(x$model), coef(x))) 21 | 22 | bb <- lapply(c(50, 100, 200, 500, 1000, 1500, 2000), function(n) { 23 | y <- midas_auto_sim(n, c(0.5, 0.1), xx, theta0, n_start = 200) 24 | x <- window(xx, start = start(y)) 25 | midas_r(y ~ mls(y, 1:2, 1) + fmls(x, 4 * 12 - 1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10))) 26 | }) 27 | 28 | sapply(bb, function(x) c(nrow(x$model), coef(x))) 29 | -------------------------------------------------------------------------------- /demo/imidasr.R: -------------------------------------------------------------------------------- 1 | library(midasr) 2 | 3 | theta_h0 <- function(p, dk) { 4 | i <- (1:dk - 1) / 100 5 | pol <- p[3] * i + p[4] * i^2 6 | (p[1] + p[2] * i) * exp(pol) 7 | } 8 | 9 | theta0 <- theta_h0(c(-0.1, 10, -10, -10), 4 * 12) 10 | 11 | xx <- ts(cumsum(rnorm(1000 * 12)), frequency = 12) 12 | y <- midas_auto_sim(500, 0.5, xx, theta0, n_start = 200) 13 | x <- window(xx, start = start(y)) 14 | 15 | dx <- c(NA, diff(x)) 16 | 17 | pp1 <- function(p, d) cumsum(theta_h0(p, d)) 18 | 19 | ### Do the transformation by hand 20 | mr <- midas_r(y ~ fmls(dx, 4 * 12 - 1, 12, pp1) + mls(x, 4 * 12, 12) - 1, start = list(dx = c(-0.1, 10, -10, -10))) 21 | 22 | ### Use the designated function 23 | imr <- imidas_r(y ~ fmls(x, 4 * 12 - 1, 12, theta_h0) - 1, start = list(x = c(-0.1, 10, -10, -10))) 24 | 25 | ### Test the restriction. The usual test hAh can be used. 26 | hAh_test(imr) 27 | -------------------------------------------------------------------------------- /demo/logRV.R: -------------------------------------------------------------------------------- 1 | ## More details about the models can be found in the article 2 | ## "The statistical content and empirical testing of the MIDAS restrictions" 3 | ## by Virmantas Kvedaras and Vaidotas Zemlys 4 | 5 | library(midasr) 6 | data(rvsp500) 7 | 8 | ii <- which(rvsp500$DateID == "20120522") 9 | y <- log(as.numeric(rvsp500[1:ii, 2])) 10 | 11 | nlmn <- function(p, d, m) { 12 | i <- 1:d / 100 13 | plc <- poly(i, degree = length(p) - 1, raw = TRUE) %*% p[-1] 14 | as.vector(p[1] * exp(plc) / sum(exp(plc))) 15 | } 16 | 17 | ## Convergence is harder to achieve, so try to pick better starting values 18 | prestart <- function(start, cfur, k) { 19 | fn0 <- function(p) { 20 | sum((cfur - nlmn(p, k))^2) 21 | } 22 | optim(start, fn0, method = "BFGS", control = list(maxit = 1000))$par 23 | } 24 | 25 | rvhk <- function(h, k) { 26 | rvh <- filter(c(rep(0, h), y), c(rep(1, h), rep(0, h + 1))) 27 | rvh <- rvh[-h:-1] 28 | y <- y[1:length(rvh)] 29 | mu <- midas_u(rvh ~ fmls(y, k, 1)) 30 | cfur <- coef(mu)[grep("fmls", names(coef(mu)))] 31 | update(midas_r(rvh ~ fmls(y, k, 1, nlmn), start = list(y = prestart(c(0.2, -1, 1), cfur, k + 1))), Ofunction = "nls") 32 | } 33 | 34 | allh <- lapply(c(5, 10, 20, 40), rvhk, k = 69) 35 | 36 | #### Compute the derivative test 37 | dtest <- lapply(allh, deriv_tests, tol = 0.5) 38 | 39 | ### The first derivative tests, gradient is zero 40 | sapply(dtest, with, first) 41 | 42 | ### The second derivative tests, hessian is positive definite 43 | sapply(dtest, with, second) 44 | 45 | ### View summaries 46 | lapply(allh, summary) 47 | 48 | ## Precompute the meat matrix for robust testing. Takes some time to compute!!! 49 | PHI <- lapply(allh, function(x) meatHAC(x$unrestricted, prewhite = TRUE, weights = weightsAndrews)) 50 | 51 | ### Apply hAh test 52 | lapply(allh, hAh_test) 53 | 54 | ## Apply robust hAh test with precomputed PHI 55 | mapply(hAhr_test, allh, PHI, SIMPLIFY = FALSE) 56 | 57 | ## Parameter j is superfluous, j=0 means no logarithm transformation was 58 | ## applied, j=1 means that logarithm transformation was applied. The graph 59 | ## is made to be the same as in the aforementioned article. 60 | 61 | graph <- function(x, phi, j, h) { 62 | k <- length(coef(x, midas = TRUE, term_names = "y")) 63 | pv0hac <- hAhr_test(x, PHI = phi)$p.value 64 | ttl <- sprintf("k(H=%.0f,j=%.0f) = %.0f: p-val.(hAh_HAC) < %.2f", h, j, k, max(pv0hac, 0.01)) 65 | plot_midas_coef(x, title = ttl, term_name = "y") 66 | } 67 | 68 | dev.new() 69 | par(mfrow = c(2, 2)) 70 | 71 | plot_info <- mapply(graph, allh, PHI, as.list(rep(1, 4)), as.list(c(5, 10, 20, 40)), SIMPLIFY = FALSE) 72 | -------------------------------------------------------------------------------- /demo/nlpr.R: -------------------------------------------------------------------------------- 1 | set.seed(131313) 2 | 3 | nnbeta <- function(p, k) nbeta(c(1, p), k) 4 | 5 | do_n_lstr <- function(n) { 6 | dgp <- midas_lstr_sim(n, m = 12, theta = nnbeta(c(2, 4), 24), intercept = 1, plstr = c(1.5, 1, 1, 1), ar.x = 0.9, ar.y = 0.5, n.start = 100) 7 | 8 | z <- cbind(1, mls(dgp$y, 1:2, 1)) 9 | colnames(z) <- c("Intercept", "y1", "y2") 10 | X <- mls(dgp$x, 0:23, 12) 11 | 12 | lstr_mod_plain <- midas_lstr_plain(dgp$y, X, z, nnbeta, 13 | start_lstr = c(1.5, 1, 1, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0), 14 | method = "Nelder-Mead", control = list(maxit = 5000) 15 | ) 16 | lstr_mod_nlpr <- midas_nlpr(y ~ mlsd(x, 0:23, y, nnbeta) + mlsd(y, 1:2, y), 17 | data = dgp, 18 | start = list( 19 | x = list( 20 | lstr = c(1.5, 1, 1, 1), 21 | r = c(2, 4) 22 | ), 23 | y = c(0.5, 0), 24 | `(Intercept)` = 1 25 | ) 26 | ) 27 | list(dgp = dgp, plain = lstr_mod_plain, nlpr = lstr_mod_nlpr) 28 | } 29 | 30 | sim_lstr <- lapply(c(250, 500, 1000, 2000, 5000, 10000, 20000), do_n_lstr) 31 | 32 | do_n_mmm <- function(n) { 33 | dgp <- midas_mmm_sim(n, m = 12, theta = nnbeta(c(2, 4), 24), intercept = 1, pmmm = c(1.5, 1), ar.x = 0.9, ar.y = 0.5, n.start = 100) 34 | 35 | z <- cbind(1, mls(dgp$y, 1:2, 1)) 36 | colnames(z) <- c("Intercept", "y1", "y2") 37 | X <- mls(dgp$x, 0:23, 12) 38 | 39 | mmm_plain <- midas_mmm_plain(dgp$y, X, z, nnbeta, 40 | start_mmm = c(1.5, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0), 41 | method = "Nelder-Mead", control = list(maxit = 5000) 42 | ) 43 | 44 | mmm_nlpr <- midas_nlpr(y ~ mlsd(x, 0:23, y, nnbeta) + mlsd(y, 1:2, y), 45 | data = dgp, 46 | start = list( 47 | x = list( 48 | mmm = c(1.5, 1), 49 | r = c(2, 4) 50 | ), 51 | y = c(0.5, 0), 52 | `(Intercept)` = 1 53 | ), 54 | method = "Nelder-Mead", control = list(maxit = 5000) 55 | ) 56 | 57 | list(dgp = dgp, plain = mmm_plain, nlpr = mmm_nlpr) 58 | } 59 | 60 | sim_mmm <- lapply(c(250, 500, 1000, 2000, 5000, 10000, 20000), do_n_mmm) 61 | -------------------------------------------------------------------------------- /demo/okun.R: -------------------------------------------------------------------------------- 1 | ## More details about the models can be found in the article 2 | ## "The statistical content and empirical testing of the MIDAS restrictions" 3 | ## by Virmantas Kvedaras and Vaidotas Zemlys 4 | 5 | library(midasr) 6 | data("USunempr") 7 | data("USrealgdp") 8 | 9 | y <- diff(log(USrealgdp)) 10 | x <- window(diff(USunempr), start = 1949) 11 | trend <- 1:length(y) 12 | 13 | allk <- lapply(c(12, 15, 18, 24) - 1, function(k) { 14 | update(midas_r(y ~ trend + fmls(x, k, 12, nealmon), start = list(x = rep(0, 3))), Ofunction = "nls") 15 | }) 16 | 17 | #### Compute the derivative test 18 | dtest <- lapply(allk, deriv_tests) 19 | 20 | ### The first derivative tests, gradient is zero 21 | sapply(dtest, with, first) 22 | 23 | ### The second derivative tests, hessian is positive definite 24 | sapply(dtest, with, second) 25 | 26 | ### The minimal eigenvalue of hessian is borderline zero, yet positive. 27 | sapply(dtest, with, min(eigenval)) 28 | 29 | ### Apply hAh test 30 | lapply(allk, hAh_test) 31 | 32 | ### Apply robust hAh test 33 | lapply(allk, hAhr_test) 34 | 35 | ### View summaries 36 | lapply(allk, summary) 37 | 38 | ## Plot the coefficients 39 | dev.new() 40 | par(mfrow = c(2, 2)) 41 | 42 | 43 | plot_info <- lapply(allk, function(x) { 44 | k <- length(coef(x, midas = TRUE, term = "x")) 45 | ttl <- sprintf("d = %.0f: p-val.(hAh_HAC) < %.2f", k, max(hAhr_test(x)$p.value, 0.01)) 46 | plot_midas_coef(x, title = ttl) 47 | }) 48 | -------------------------------------------------------------------------------- /demo/pl.R: -------------------------------------------------------------------------------- 1 | set.seed(131313) 2 | 3 | 4 | do_n_pl <- function(n) { 5 | dgp <- midas_pl_sim(n, m = 12, theta = nbeta(c(1.5, 2, 4), 24), gfun = function(x) 0.25 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100) 6 | 7 | X <- mls(dgp$x, 0:23, 12) 8 | 9 | pl_mod <- midas_pl_plain(dgp$y, X, dgp$z, 10 | p.ar = 2L, nbeta, degree = 1, start_bws = 0, start_x = c(1.5, 2, 4), start_ar = c(0.5, 0), 11 | method = "Nelder-Mead", itnmax = 5000 12 | ) 13 | list(dgp = dgp, pl = pl_mod) 14 | } 15 | 16 | t1 <- system.time(sim_pl <- lapply(c(250, 500), do_n_pl)) 17 | 18 | t2 <- system.time(mpl <- midas_sp(y ~ mlsd(y, 1:2, y) + mlsd(x, 0:23, y, nbeta) | z, 19 | bws = 0, degree = 1, data = sim_pl[[1]]$dgp, 20 | start = list(x = c(1.5, 2, 4), y = c(0.5, 0)), method = "Nelder-Mead", control = list(maxit = 5000) 21 | )) 22 | -------------------------------------------------------------------------------- /demo/single_index.R: -------------------------------------------------------------------------------- 1 | set.seed(131313) 2 | 3 | nnbeta <- function(p, k) nbeta(c(1, p), k) 4 | 5 | do_n_si <- function(n) { 6 | dgp <- midas_si_sim(n, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.03 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100) 7 | 8 | X <- mls(dgp$x, 0:23, 12) 9 | y <- as.numeric(dgp$y) 10 | si_mod <- midas_si_plain(y, X, 11 | p.ar = 2L, nnbeta, degree = 1, start_bws = 0, start_x = c(2, 4), start_ar = c(0.5, 0), 12 | method = "Nelder-Mead", itnmax = 5000 13 | ) 14 | list(dgp = dgp, si = si_mod) 15 | } 16 | 17 | t1 <- system.time(sim_si <- lapply(c(250, 500), do_n_si)) 18 | 19 | t2 <- system.time(msi <- midas_sp(y ~ mlsd(y, 1:2, y) | mlsd(x, 0:23, y, nnbeta), 20 | bws = 0, degree = 1, data = sim_si[[1]]$dgp, 21 | start = list(x = c(2, 4), y = c(0.5, 0)), method = "Nelder-Mead", control = list(maxit = 5000) 22 | )) 23 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Article", 2 | title = "Mixed Frequency Data Sampling Regression Models: The {R} Package {midasr}", 3 | author = c(person(given = "Eric", 4 | family = "Ghysels", 5 | email = "eghysels@unc.edu"), 6 | person(given = "Virmantas", 7 | family = "Kvedaras", 8 | email = "virmantas.kvedaras@mif.vu.lt"), 9 | person(given = "Vaidotas", 10 | family = "Zemlys", 11 | email = "vaidotas.zemlys@mif.vu.lt")), 12 | journal = "Journal of Statistical Software", 13 | year = "2016", 14 | volume = "72", 15 | number = "4", 16 | pages = "1--35", 17 | doi = "10.18637/jss.v072.i04", 18 | 19 | header = "To cite midasr in publications use:", 20 | textVersion = 21 | paste("Eric Ghysels, Virmantas Kvedaras, Vaidotas Zemlys (2016).", 22 | "Mixed Frequency Data Sampling Regression Models: The R Package midasr.", 23 | "Journal of Statistical Software, 72(4), 1-35.", 24 | "doi:10.18637/jss.v072.i04") 25 | ) 26 | 27 | -------------------------------------------------------------------------------- /man/UScpiqs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{UScpiqs} 5 | \alias{UScpiqs} 6 | \title{US quartely seasonaly adjusted consumer price index} 7 | \format{ 8 | A \code{\link{data.frame}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/CPALTT01USQ661S}{FRED} 12 | } 13 | \description{ 14 | US quarterly CPI from 1960Q1 to 2017Q3s. Seasonaly adjusted, Index 2015=1 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/USeffrw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{USeffrw} 5 | \alias{USeffrw} 6 | \title{US weekly effective federal funds rate.} 7 | \format{ 8 | A \code{\link{data.frame}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/DFF}{FRED} 12 | } 13 | \description{ 14 | US weekly effective federal funds rate from 1954-07-07 to 2017-12-13 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/USpayems.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{USpayems} 5 | \alias{USpayems} 6 | \title{United States total employment non-farms payroll, monthly, seasonally adjusted.} 7 | \format{ 8 | A \code{\link{ts}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/PAYEMS}{FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis} 12 | } 13 | \description{ 14 | United States total employment non-farms payroll, monthly, seasonally adjusted. Retrieved from FRED, symbol "PAYEMS" at 2014-04-25. 15 | } 16 | \examples{ 17 | 18 | ## Do not run: 19 | ## library(quantmod) 20 | ## USpayems <- ts(getSymbols("PAYEMS",src="FRED",auto.assign=FALSE),start=c(1939,1),frequency=12) 21 | } 22 | \keyword{datasets} 23 | -------------------------------------------------------------------------------- /man/USqgdp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{USqgdp} 5 | \alias{USqgdp} 6 | \title{United States gross domestic product, quarterly, seasonaly adjusted annual rate.} 7 | \format{ 8 | A \code{\link{ts}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/GDP}{FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis} 12 | } 13 | \description{ 14 | United States gross domestic product, quarterly, seasonaly adjusted annual rate. Retrieved from FRED, symbol "GDP" at 2014-04-25. 15 | } 16 | \examples{ 17 | ## Do not run: 18 | ## library(quantmod) 19 | ## USqgdp <- ts(getSymbols("GDP",src="FRED",auto.assign=FALSE),start=c(1947,1),frequency=4) 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/USrealgdp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{USrealgdp} 5 | \alias{USrealgdp} 6 | \title{US annual gross domestic product in billions of chained 2005 dollars} 7 | \format{ 8 | A \code{\link{ts}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/GDPC1}{U.S. Department of Commerce, Bureau of Economic Analysis} 12 | } 13 | \description{ 14 | The annual gross domestic product in billions of chained 2005 dollars for US from 1948 to 2011. 15 | This data is kept for historical purposes, newer data is in 2012 chained dollars. 16 | } 17 | \keyword{datasets} 18 | -------------------------------------------------------------------------------- /man/USunempr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{USunempr} 5 | \alias{USunempr} 6 | \title{US monthly unemployment rate} 7 | \format{ 8 | A \code{\link{ts}} object. 9 | } 10 | \source{ 11 | \href{https://fred.stlouisfed.org/series/UNRATE}{FRED} 12 | } 13 | \description{ 14 | The monthly unemployment rate for United States from 1948 to 2011. 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/agk.test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tests.R 3 | \name{agk.test} 4 | \alias{agk.test} 5 | \title{Andreou, Ghysels, Kourtellos LM test} 6 | \usage{ 7 | agk.test(x) 8 | } 9 | \arguments{ 10 | \item{x}{MIDAS regression object of class \code{\link{midas_r}}} 11 | } 12 | \value{ 13 | a \code{htest} object 14 | } 15 | \description{ 16 | Perform the test whether hyperparameters of normalized exponential Almon lag weights are zero 17 | } 18 | \examples{ 19 | ##' ##Load data 20 | data("USunempr") 21 | data("USrealgdp") 22 | 23 | y <- diff(log(USrealgdp)) 24 | x <- window(diff(USunempr),start=1949) 25 | t <- 1:length(y) 26 | 27 | mr <- midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0))) 28 | 29 | agk.test(mr) 30 | 31 | } 32 | \references{ 33 | Andreou E., Ghysels E., Kourtellos A. \emph{Regression models with mixed sampling frequencies} Journal of Econometrics 158 (2010) 246-261 34 | } 35 | \author{ 36 | Virmantas Kvedaras, Vaidotas Zemlys 37 | } 38 | -------------------------------------------------------------------------------- /man/almonp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{almonp} 4 | \alias{almonp} 5 | \title{Almon polynomial MIDAS weights specification} 6 | \usage{ 7 | almonp(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for Almon polynomial weights} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate Almon polynomial MIDAS weights 21 | } 22 | \author{ 23 | Virmantas Kvedaras, Vaidotas Zemlys 24 | } 25 | -------------------------------------------------------------------------------- /man/almonp_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{almonp_gradient} 4 | \alias{almonp_gradient} 5 | \title{Gradient function for Almon polynomial MIDAS weights} 6 | \usage{ 7 | almonp_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{vector of parameters for Almon polynomial specification} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate gradient for Almon polynomial MIDAS weights specification 21 | } 22 | \author{ 23 | Vaidotas Zemlys 24 | } 25 | -------------------------------------------------------------------------------- /man/amidas_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{amidas_table} 4 | \alias{amidas_table} 5 | \title{Weight and lag selection table for aggregates based MIDAS regression model} 6 | \usage{ 7 | amidas_table( 8 | formula, 9 | data, 10 | weights, 11 | wstart, 12 | type, 13 | start = NULL, 14 | from, 15 | to, 16 | IC = c("AIC", "BIC"), 17 | test = c("hAh_test"), 18 | Ofunction = "optim", 19 | weight_gradients = NULL, 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{formula}{the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula} 25 | 26 | \item{data}{a list containing data with mixed frequencies} 27 | 28 | \item{weights}{the names of weights used in Ghysels schema} 29 | 30 | \item{wstart}{the starting values for the weights of the firs low frequency lag} 31 | 32 | \item{type}{the type of Ghysels schema see \link{amweights}, can be a vector of types} 33 | 34 | \item{start}{the starting values for optimisation excluding the starting values for the last term} 35 | 36 | \item{from}{a named list, or named vector with high frequency (NB!) lag numbers which are the beginnings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero} 37 | 38 | \item{to}{to a named list where each element is a vector with two elements. The first element is the low frequency lag number from which the lag selection starts, the second is the low frequency lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible.} 39 | 40 | \item{IC}{the names of information criteria which should be calculated} 41 | 42 | \item{test}{the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table} 43 | 44 | \item{Ofunction}{see \link{midasr}} 45 | 46 | \item{weight_gradients}{see \link{midas_r}} 47 | 48 | \item{...}{additional parameters to optimisation function, see \link{midas_r}} 49 | } 50 | \value{ 51 | a \code{midas_r_ic_table} object which is the list with the following elements: 52 | 53 | \item{table}{the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure} 54 | \item{candlist}{the list containing fitted models} 55 | \item{IC}{the argument IC} 56 | \item{test}{the argument test} 57 | \item{weights}{the names of weight functions} 58 | \item{lags}{the lags used in models} 59 | } 60 | \description{ 61 | Create weight and lag selection table for the aggregates based MIDAS regression model 62 | } 63 | \details{ 64 | This function estimates models sequentialy increasing the midas lag from \code{kmin} to \code{kmax} and varying the weights of the last term of the given formula 65 | 66 | This function estimates models sequentially increasing the midas lag from \code{kmin} to \code{kmax} and varying the weights of the last term of the given formula 67 | } 68 | \examples{ 69 | 70 | data("USunempr") 71 | data("USrealgdp") 72 | y <- diff(log(USrealgdp)) 73 | x <- window(diff(USunempr),start=1949) 74 | trend <- 1:length(y) 75 | 76 | tb <- amidas_table(y~trend+fmls(x,12,12,nealmon), 77 | data=list(y=y,x=x,trend=trend), 78 | weights=c("nealmon"),wstart=list(nealmon=c(0,0,0)), 79 | start=list(trend=1),type=c("A"), 80 | from=0,to=c(1,2)) 81 | 82 | 83 | } 84 | \author{ 85 | Virmantas Kvedaras, Vaidotas Zemlys 86 | } 87 | -------------------------------------------------------------------------------- /man/amweights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{amweights} 4 | \alias{amweights} 5 | \title{Weights for aggregates based MIDAS regressions} 6 | \usage{ 7 | amweights(p, d, m, weight = nealmon, type = c("A", "B", "C")) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for weight functions, see details.} 11 | 12 | \item{d}{number of high frequency lags} 13 | 14 | \item{m}{the frequency} 15 | 16 | \item{weight}{the weight function} 17 | 18 | \item{type}{type of structure, a string, one of A, B or C.} 19 | } 20 | \value{ 21 | a vector of weights 22 | } 23 | \description{ 24 | Produces weights for aggregates based MIDAS regression 25 | } 26 | \details{ 27 | Suppose a weight function \eqn{w(\beta,\theta)} satisfies the following equation: 28 | \deqn{w(\beta,\theta)=\beta g(\theta)} 29 | 30 | The following combinations are defined, corresponding to structure types 31 | \code{A}, \code{B} and \code{C} respectively: 32 | \deqn{(w(\beta_1,\theta_1),...,w(\beta_k,\theta_k))} 33 | \deqn{(w(\beta_1,\theta),...,w(\beta_k,\theta))} 34 | \deqn{\beta(w(1,\theta),...,w(1,\theta)),} 35 | 36 | where \eqn{k} is the number of low frequency lags, i.e. \eqn{d/m}. If the latter 37 | value is not whole number, the error is produced. 38 | 39 | 40 | The starting values \eqn{p} should be supplied then as follows: 41 | \deqn{(\beta_1,\theta_1,...,\beta_k,\theta_k)} 42 | \deqn{(\beta_1,...,\beta_k,\theta)} 43 | \deqn{(\beta,\theta)} 44 | } 45 | \author{ 46 | Virmantas Kvedaras, Vaidotas Zemlys 47 | } 48 | -------------------------------------------------------------------------------- /man/average_forecast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{average_forecast} 4 | \alias{average_forecast} 5 | \title{Average forecasts of MIDAS models} 6 | \usage{ 7 | average_forecast( 8 | modlist, 9 | data, 10 | insample, 11 | outsample, 12 | type = c("fixed", "recursive", "rolling"), 13 | fweights = c("EW", "BICW", "MSFE", "DMSFE"), 14 | measures = c("MSE", "MAPE", "MASE"), 15 | show_progress = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{modlist}{a list of \code{midas_r} objects} 20 | 21 | \item{data}{a list with mixed frequency data} 22 | 23 | \item{insample}{the low frequency indexes for in-sample data} 24 | 25 | \item{outsample}{the low frequency indexes for out-of-sample data} 26 | 27 | \item{type}{a string indicating which type of forecast to use.} 28 | 29 | \item{fweights}{names of weighting schemes} 30 | 31 | \item{measures}{names of accuracy measures} 32 | 33 | \item{show_progress}{logical, TRUE to show progress bar, FALSE for silent evaluation} 34 | } 35 | \value{ 36 | a list containing forecasts and tables of accuracy measures 37 | } 38 | \description{ 39 | Average MIDAS model forecasts using specified weighting scheme. Produce in-sample and out-of-sample accuracy measures. 40 | } 41 | \details{ 42 | Given the data, split it to in-sample and out-of-sample data. Then given the list of models, reestimate each model with in-sample data and produce out-of-sample forecast. Given the forecasts average them with the specified weighting scheme. Then calculate the accuracy measures for individual and average forecasts. 43 | 44 | The forecasts can be produced in 3 ways. The \code{"fixed"} forecast uses model estimated with in-sample data. The \code{"rolling"} forecast reestimates model each time by increasing the in-sample by one low frequency observation and dropping the first low frequency observation. These reestimated models then are used to produce out-of-sample forecasts. The \code{"recursive"} forecast differs from \code{"rolling"} that it does not drop observations from the beginning of data. 45 | } 46 | \examples{ 47 | set.seed(1001) 48 | ## Number of low-frequency observations 49 | n<-250 50 | ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) 51 | trend<-c(1:n) 52 | x<-rnorm(4*n) 53 | z<-rnorm(12*n) 54 | ## Exponential Almon polynomial constraint-consistent coefficients 55 | fn.x <- nealmon(p=c(1,-0.5),d=8) 56 | fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) 57 | ## Simulated low-frequency series (e.g. yearly) 58 | y<-2+0.1*trend+mls(x,0:7,4)\%*\%fn.x+mls(z,0:16,12)\%*\%fn.z+rnorm(n) 59 | mod1 <- midas_r(y ~ trend + mls(x, 4:14, 4, nealmon) + mls(z, 12:22, 12, nealmon), 60 | start=list(x=c(10,1,-0.1),z=c(2,-0.1))) 61 | mod2 <- midas_r(y ~ trend + mls(x, 4:20, 4, nealmon) + mls(z, 12:25, 12, nealmon), 62 | start=list(x=c(10,1,-0.1),z=c(2,-0.1))) 63 | 64 | ##Calculate average forecasts 65 | avgf <- average_forecast(list(mod1,mod2), 66 | data=list(y=y,x=x,z=z,trend=trend), 67 | insample=1:200,outsample=201:250, 68 | type="fixed", 69 | measures=c("MSE","MAPE","MASE"), 70 | fweights=c("EW","BICW","MSFE","DMSFE")) 71 | } 72 | \author{ 73 | Virmantas Kvedaras, Vaidotas Zemlys 74 | } 75 | -------------------------------------------------------------------------------- /man/check_mixfreq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midaslag.R 3 | \name{check_mixfreq} 4 | \alias{check_mixfreq} 5 | \title{Check data for MIDAS regression} 6 | \usage{ 7 | check_mixfreq(data) 8 | } 9 | \arguments{ 10 | \item{data}{a list containing mixed frequency data} 11 | } 12 | \value{ 13 | a boolean TRUE, if mixed frequency data is conformable, FALSE if it is not. 14 | } 15 | \description{ 16 | Given mixed frequency data check whether higher frequency data can be converted to the lowest frequency. 17 | } 18 | \details{ 19 | The number of observations in higher frequency data elements should have a common divisor 20 | with the number of observations in response variable. It is always assumed that the response variable 21 | is of the lowest frequency. 22 | } 23 | \author{ 24 | Virmantas Kvedaras, Vaidotas Zemlys 25 | } 26 | -------------------------------------------------------------------------------- /man/coef.midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{coef.midas_nlpr} 4 | \alias{coef.midas_nlpr} 5 | \title{Extract coefficients of MIDAS regression} 6 | \usage{ 7 | \method{coef}{midas_nlpr}(object, type = c("plain", "midas", "nlpr"), term_names = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{midas_nlpr} object} 11 | 12 | \item{type}{one of plain, midas, or nlpr. Returns appropriate coefficients.} 13 | 14 | \item{term_names}{a character vector with term names. Default is \code{NULL}, which means that coefficients of all the terms are returned} 15 | 16 | \item{...}{not used currently} 17 | } 18 | \value{ 19 | a vector with coefficients 20 | } 21 | \description{ 22 | Extracts various coefficients of MIDAS regression 23 | } 24 | \details{ 25 | MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters 26 | of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. 27 | The second is the coefficients of the linear model, i.e the values of weight 28 | functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients. 29 | } 30 | \author{ 31 | Vaidotas Zemlys 32 | } 33 | -------------------------------------------------------------------------------- /man/coef.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{coef.midas_r} 4 | \alias{coef.midas_r} 5 | \title{Extract coefficients of MIDAS regression} 6 | \usage{ 7 | \method{coef}{midas_r}(object, midas = FALSE, term_names = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{midas_r} object} 11 | 12 | \item{midas}{logical, if \code{TRUE}, MIDAS coefficients are returned, if \code{FALSE} (default), coefficients of NLS problem are returned} 13 | 14 | \item{term_names}{a character vector with term names. Default is \code{NULL}, which means that coefficients of all the terms are returned} 15 | 16 | \item{...}{not used currently} 17 | } 18 | \value{ 19 | a vector with coefficients 20 | } 21 | \description{ 22 | Extracts various coefficients of MIDAS regression 23 | } 24 | \details{ 25 | MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters 26 | of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. 27 | The second is the coefficients of the linear model, i.e the values of weight 28 | functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients. 29 | } 30 | \examples{ 31 | 32 | #Simulate MIDAS regression 33 | n<-250 34 | trend<-c(1:n) 35 | x<-rnorm(4*n) 36 | z<-rnorm(12*n) 37 | fn.x <- nealmon(p=c(1,-0.5),d=8) 38 | fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) 39 | y<-2+0.1*trend+mls(x,0:7,4)\%*\%fn.x+mls(z,0:16,12)\%*\%fn.z+rnorm(n) 40 | eqr<-midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + 41 | mls(z, 0:16, 12, nealmon), 42 | start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1))) 43 | 44 | coef(eqr) 45 | coef(eqr, term_names = "x") 46 | coef(eqr, midas = TRUE) 47 | coef(eqr, midas = TRUE, term_names = "x") 48 | 49 | } 50 | \author{ 51 | Vaidotas Zemlys 52 | } 53 | -------------------------------------------------------------------------------- /man/coef.midas_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp_methods.R 3 | \name{coef.midas_sp} 4 | \alias{coef.midas_sp} 5 | \title{Extract coefficients of MIDAS regression} 6 | \usage{ 7 | \method{coef}{midas_sp}(object, type = c("plain", "midas", "bw"), term_names = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{midas_nlpr} object} 11 | 12 | \item{type}{one of plain, midas, or nlpr. Returns appropriate coefficients.} 13 | 14 | \item{term_names}{a character vector with term names. Default is \code{NULL}, which means that coefficients of all the terms are returned} 15 | 16 | \item{...}{not used currently} 17 | } 18 | \value{ 19 | a vector with coefficients 20 | } 21 | \description{ 22 | Extracts various coefficients of MIDAS regression 23 | } 24 | \details{ 25 | MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters 26 | of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. 27 | The second is the coefficients of the linear model, i.e the values of weight 28 | functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients. 29 | } 30 | \author{ 31 | Vaidotas Zemlys 32 | } 33 | -------------------------------------------------------------------------------- /man/deriv_tests.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deriv.R 3 | \name{deriv_tests} 4 | \alias{deriv_tests} 5 | \alias{deriv_tests.midas_r} 6 | \title{Check whether non-linear least squares restricted MIDAS regression problem has converged} 7 | \usage{ 8 | deriv_tests(x, tol = 1e-06) 9 | 10 | \method{deriv_tests}{midas_r}(x, tol = 1e-06) 11 | } 12 | \arguments{ 13 | \item{x}{\code{\link{midas_r}} object} 14 | 15 | \item{tol}{a tolerance, values below the tolerance are considered zero} 16 | } 17 | \value{ 18 | a list with gradient, hessian of optimisation function and convergence message 19 | } 20 | \description{ 21 | Computes the gradient and hessian of the optimisation function of restricted MIDAS regression and 22 | checks whether the conditions of local optimum are met. Numerical estimates are used. 23 | } 24 | \seealso{ 25 | midas_r 26 | } 27 | \author{ 28 | Vaidotas Zemlys 29 | } 30 | -------------------------------------------------------------------------------- /man/deviance.midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{deviance.midas_nlpr} 4 | \alias{deviance.midas_nlpr} 5 | \title{Non-linear parametric MIDAS regression model deviance} 6 | \usage{ 7 | \method{deviance}{midas_nlpr}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{a \code{\link{midas_r}} object} 11 | 12 | \item{...}{currently nothing} 13 | } 14 | \value{ 15 | The sum of squared residuals 16 | } 17 | \description{ 18 | Returns the deviance of a fitted MIDAS regression object 19 | } 20 | \author{ 21 | Virmantas Kvedaras, Vaidotas Zemlys 22 | } 23 | -------------------------------------------------------------------------------- /man/deviance.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{deviance.midas_r} 4 | \alias{deviance.midas_r} 5 | \title{MIDAS regression model deviance} 6 | \usage{ 7 | \method{deviance}{midas_r}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{a \code{\link{midas_r}} object} 11 | 12 | \item{...}{currently nothing} 13 | } 14 | \value{ 15 | The sum of squared residuals 16 | } 17 | \description{ 18 | Returns the deviance of a fitted MIDAS regression object 19 | } 20 | \author{ 21 | Virmantas Kvedaras, Vaidotas Zemlys 22 | } 23 | -------------------------------------------------------------------------------- /man/deviance.midas_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp_methods.R 3 | \name{deviance.midas_sp} 4 | \alias{deviance.midas_sp} 5 | \title{Semi-parametric MIDAS regression model deviance} 6 | \usage{ 7 | \method{deviance}{midas_sp}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{a \code{\link{midas_r}} object} 11 | 12 | \item{...}{currently nothing} 13 | } 14 | \value{ 15 | The sum of squared residuals 16 | } 17 | \description{ 18 | Returns the deviance of a fitted MIDAS regression object 19 | } 20 | \author{ 21 | Virmantas Kvedaras, Vaidotas Zemlys 22 | } 23 | -------------------------------------------------------------------------------- /man/dmls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midaslag.R 3 | \name{dmls} 4 | \alias{dmls} 5 | \title{MIDAS lag structure for unit root processes} 6 | \usage{ 7 | dmls(x, k, m, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | 12 | \item{k}{maximal lag order} 13 | 14 | \item{m}{frequency ratio} 15 | 16 | \item{...}{further arguments used in fitting MIDAS regression} 17 | } 18 | \value{ 19 | a matrix containing the first differences and the lag k+1. 20 | } 21 | \description{ 22 | Prepares MIDAS lag structure for unit root processes 23 | } 24 | \author{ 25 | Virmantas Kvedaras, Vaidotas Zemlys 26 | } 27 | -------------------------------------------------------------------------------- /man/expand_amidas.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{expand_amidas} 4 | \alias{expand_amidas} 5 | \title{Create table of weights, lags and starting values for Ghysels weight schema} 6 | \usage{ 7 | expand_amidas(weight, type = c("A", "B", "C"), from = 0, to, m, start) 8 | } 9 | \arguments{ 10 | \item{weight}{the names of weight functions} 11 | 12 | \item{type}{the type of Ghysels schema, \code{"A"}, \code{"B"} or \code{"C"}} 13 | 14 | \item{from}{the high frequency lags from which to start the fitting} 15 | 16 | \item{to}{to a vector of length two, containing minimum and maximum lags, high frequency if \code{m=1}, low frequency otherwise.} 17 | 18 | \item{m}{the frequency ratio} 19 | 20 | \item{start}{the starting values for the weights of the one low frequency lag} 21 | } 22 | \value{ 23 | a \code{lws_table} object, a list with elements \code{weights}, \code{lags} and \code{starts} 24 | } 25 | \description{ 26 | Create table of weights, lags and starting values for Ghysels weight schema, see \link{amweights} 27 | } 28 | \details{ 29 | Given weight function creates lags starting from \code{kmin} to \code{kmax} and replicates starting values for each low frequency lag. 30 | } 31 | \examples{ 32 | expand_amidas("nealmon","A",0,c(1,2),12,c(0,0,0)) 33 | } 34 | \author{ 35 | Virmantas Kvedaras, Vaidotas Zemlys 36 | } 37 | -------------------------------------------------------------------------------- /man/expand_weights_lags.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{expand_weights_lags} 4 | \alias{expand_weights_lags} 5 | \title{Create table of weights, lags and starting values} 6 | \usage{ 7 | expand_weights_lags(weights, from = 0, to, m = 1, start) 8 | } 9 | \arguments{ 10 | \item{weights}{either a vector with names of the weight functions or a named list of weight functions} 11 | 12 | \item{from}{the high frequency lags from which to start the fitting} 13 | 14 | \item{to}{a vector of length two, containing minimum and maximum lags, high frequency if \code{m=1}, low frequency otherwise.} 15 | 16 | \item{m}{the frequency ratio} 17 | 18 | \item{start}{a named list with the starting values for weight functions} 19 | } 20 | \value{ 21 | a \code{lws_table} object, a list with elements \code{weights}, \code{lags} and \code{starts}. 22 | } 23 | \description{ 24 | Creates table of weights, lags and starting values 25 | } 26 | \details{ 27 | For each weight function creates lags starting from \code{kmin} to \code{kmax}. This is a convenience function for easier work with the function \link{midas_r_ic_table}. 28 | } 29 | \examples{ 30 | 31 | expand_weights_lags(c("nealmon","nbeta"),0,c(4,8),1,start=list(nealmon=rep(0,3),nbeta=rep(0,4))) 32 | nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) 33 | nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) 34 | 35 | nlmn+nbt 36 | } 37 | \author{ 38 | Virmantas Kvedaras, Vaidotas Zemlys 39 | } 40 | -------------------------------------------------------------------------------- /man/extract.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{extract.midas_r} 4 | \alias{extract.midas_r} 5 | \title{Extract coefficients and GOF measures from MIDAS regression object} 6 | \usage{ 7 | extract.midas_r( 8 | model, 9 | include.rsquared = TRUE, 10 | include.nobs = TRUE, 11 | include.rmse = TRUE, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{model}{a MIDAS regression object} 17 | 18 | \item{include.rsquared, }{If available: should R-squared be reported?} 19 | 20 | \item{include.nobs}{If available: should the number of observations be reported?} 21 | 22 | \item{include.rmse}{If available: should the root-mean-square error (= residual standard deviation) be reported?} 23 | 24 | \item{...}{additional parameters passed to summary} 25 | } 26 | \value{ 27 | texreg object 28 | } 29 | \description{ 30 | Extract coefficients and GOF measures from MIDAS regression object 31 | } 32 | \author{ 33 | Virmantas Kvedaras, Vaidotas Zemlys 34 | } 35 | -------------------------------------------------------------------------------- /man/fitted.midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{fitted.midas_nlpr} 4 | \alias{fitted.midas_nlpr} 5 | \title{Fitted values for non-linear parametric MIDAS regression model} 6 | \usage{ 7 | \method{fitted}{midas_nlpr}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{a \code{\link{midas_r}} object} 11 | 12 | \item{...}{currently nothing} 13 | } 14 | \value{ 15 | the vector of fitted values 16 | } 17 | \description{ 18 | Returns the fitted values of a fitted non-linear parametric MIDAS regression object 19 | } 20 | \author{ 21 | Virmantas Kvedaras, Vaidotas Zemlys 22 | } 23 | -------------------------------------------------------------------------------- /man/fitted.midas_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp_methods.R 3 | \name{fitted.midas_sp} 4 | \alias{fitted.midas_sp} 5 | \title{Fitted values for semi-parametric MIDAS regression model} 6 | \usage{ 7 | \method{fitted}{midas_sp}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{a \code{\link{midas_r}} object} 11 | 12 | \item{...}{currently nothing} 13 | } 14 | \value{ 15 | the vector of fitted values 16 | } 17 | \description{ 18 | Returns the fitted values of a fitted semi-parametric MIDAS regression object 19 | } 20 | \author{ 21 | Virmantas Kvedaras, Vaidotas Zemlys 22 | } 23 | -------------------------------------------------------------------------------- /man/fmls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midaslag.R 3 | \name{fmls} 4 | \alias{fmls} 5 | \title{Full MIDAS lag structure} 6 | \usage{ 7 | fmls(x, k, m, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | 12 | \item{k}{maximum lag order} 13 | 14 | \item{m}{frequency ratio} 15 | 16 | \item{...}{further arguments} 17 | } 18 | \value{ 19 | a matrix containing the lags 20 | } 21 | \description{ 22 | Create a matrix of MIDAS lags, including contemporaneous lag up to selected order. 23 | } 24 | \details{ 25 | This is a convenience function, it calls \code{link{mls}} to perform actual calculations. 26 | } 27 | \seealso{ 28 | mls 29 | } 30 | \author{ 31 | Virmantas Kvedaras, Vaidotas Zemlys 32 | } 33 | -------------------------------------------------------------------------------- /man/forecast.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{forecast.midas_r} 4 | \alias{forecast.midas_r} 5 | \alias{forecast} 6 | \title{Forecast MIDAS regression} 7 | \usage{ 8 | \method{forecast}{midas_r}( 9 | object, 10 | newdata = NULL, 11 | se = FALSE, 12 | level = c(80, 95), 13 | fan = FALSE, 14 | npaths = 999, 15 | method = c("static", "dynamic"), 16 | insample = get_estimation_sample(object), 17 | show_progress = TRUE, 18 | add_ts_info = FALSE, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{object}{midas_r object} 24 | 25 | \item{newdata}{a named list containing future values of mixed frequency regressors. The default is \code{NULL}, meaning that only in-sample data is used.} 26 | 27 | \item{se}{logical, if \code{TRUE}, the prediction intervals are calculated} 28 | 29 | \item{level}{confidence level for prediction intervals} 30 | 31 | \item{fan}{if TRUE, level is set to seq(50,99,by=1). This is suitable for fan plots} 32 | 33 | \item{npaths}{the number of samples for simulating prediction intervals} 34 | 35 | \item{method}{the forecasting method, either \code{"static"} or \code{"dynamic"}} 36 | 37 | \item{insample}{a list containing the historic mixed frequency data} 38 | 39 | \item{show_progress}{logical, if \code{TRUE}, the progress bar is shown if \code{se = TRUE}} 40 | 41 | \item{add_ts_info}{logical, if \code{TRUE}, the forecast is cast as \code{ts} object. Some attempts are made to guess the correct start, by assuming that the response variable is a \code{ts} object of \code{frequency} 1. If \code{FALSE}, then the result is simply a numeric vector.} 42 | 43 | \item{...}{additional arguments to \code{simulate.midas_r}} 44 | } 45 | \value{ 46 | an object of class \code{"forecast"}, a list containing following elements: 47 | 48 | \item{method}{the name of forecasting method: MIDAS regression, static or dynamic} 49 | \item{model}{original object of class \code{midas_r}} 50 | \item{mean}{point forecasts} 51 | \item{lower}{lower limits for prediction intervals} 52 | \item{upper}{upper limits for prediction intervals} 53 | \item{fitted}{fitted values, one-step forecasts} 54 | \item{residuals}{residuals from the fitted model} 55 | \item{x}{the original response variable} 56 | 57 | The methods \code{print}, \code{summary} and \code{plot} from package \code{forecast} can be used on the object. 58 | } 59 | \description{ 60 | Forecasts MIDAS regression given the future values of regressors. For dynamic models (with lagged response variable) there is an option to calculate dynamic forecast, when forecasted values of response variable are substituted into the lags of response variable. 61 | } 62 | \details{ 63 | Given future values of regressors this function combines the historical values used in the fitting the MIDAS regression model and calculates the forecasts. 64 | } 65 | \examples{ 66 | data("USrealgdp") 67 | data("USunempr") 68 | 69 | y <- diff(log(USrealgdp)) 70 | x <- window(diff(USunempr), start = 1949) 71 | trend <- 1:length(y) 72 | 73 | ##24 high frequency lags of x included 74 | mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) 75 | 76 | ##Forecast horizon 77 | h <- 3 78 | ##Declining unemployment 79 | xn <- rep(-0.1, 12*h) 80 | ##New trend values 81 | trendn <- length(y) + 1:h 82 | 83 | ##Static forecasts combining historic and new high frequency data 84 | forecast(mr, list(trend = trendn, x = xn), method = "static") 85 | 86 | ##Dynamic AR* model 87 | mr.dyn <- midas_r(y ~ trend + mls(y, 1:2, 1, "*") 88 | + fmls(x, 11, 12, nealmon), 89 | start = list(x = rep(0, 3))) 90 | 91 | forecast(mr.dyn, list(trend = trendn, x = xn), method = "dynamic") 92 | 93 | ##Use print, summary and plot methods from package forecast 94 | 95 | fmr <- forecast(mr, list(trend = trendn, x = xn), method = "static") 96 | fmr 97 | summary(fmr) 98 | plot(fmr) 99 | } 100 | \author{ 101 | Vaidotas Zemlys 102 | } 103 | -------------------------------------------------------------------------------- /man/genexp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{genexp} 4 | \alias{genexp} 5 | \title{Generalized exponential MIDAS coefficients} 6 | \usage{ 7 | genexp(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{a vector of parameters} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency, currently ignored} 15 | } 16 | \value{ 17 | a vector of coefficients 18 | } 19 | \description{ 20 | Calculates the MIDAS coefficients for generalized exponential MIDAS lag specification 21 | } 22 | \details{ 23 | Generalized exponential MIDAS lag specification is a generalization of exponential 24 | Almon lag. It is defined as a product of first order polynomial with exponent 25 | of the second order polynomial. This spefication was used by V. Kvedaras and 26 | V. Zemlys (2012). 27 | } 28 | \references{ 29 | Kvedaras V., Zemlys, V. \emph{Testing the functional constraints on 30 | parameters in regressions with variables of different frequency} Economics Letters 116 (2012) 250-254 31 | } 32 | \author{ 33 | Virmantas Kvedaras, Vaidotas Zemlys 34 | } 35 | -------------------------------------------------------------------------------- /man/genexp_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{genexp_gradient} 4 | \alias{genexp_gradient} 5 | \title{Gradient of generalized exponential MIDAS coefficient generating function} 6 | \usage{ 7 | genexp_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{a vector of parameters} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency, currently ignored} 15 | } 16 | \value{ 17 | a vector of coefficients 18 | } 19 | \description{ 20 | Calculates the gradient of generalized exponential MIDAS lag specification 21 | } 22 | \details{ 23 | Generalized exponential MIDAS lag specification is a generalization of exponential 24 | Almon lag. It is defined as a product of first order polynomial with exponent 25 | of the second order polynomial. This spefication was used by V. Kvedaras and 26 | V. Zemlys (2012). 27 | } 28 | \references{ 29 | Kvedaras V., Zemlys, V. \emph{Testing the functional constraints on parameters in 30 | regressions with variables of different frequency} Economics Letters 116 (2012) 250-254 31 | } 32 | \author{ 33 | Virmantas Kvedaras, Vaidotas Zemlys 34 | } 35 | -------------------------------------------------------------------------------- /man/get_estimation_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{get_estimation_sample} 4 | \alias{get_estimation_sample} 5 | \title{Get the data which was used to etimate MIDAS regression} 6 | \usage{ 7 | get_estimation_sample(object) 8 | } 9 | \arguments{ 10 | \item{object}{\code{midas_r} object} 11 | } 12 | \value{ 13 | a named list with mixed frequency data 14 | } 15 | \description{ 16 | Gets the data which was used to estimate MIDAS regression 17 | } 18 | \details{ 19 | A helper function. 20 | } 21 | \author{ 22 | Vaidotas Zemlys 23 | } 24 | -------------------------------------------------------------------------------- /man/gompertzp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{gompertzp} 4 | \alias{gompertzp} 5 | \title{Normalized Gompertz probability density function MIDAS weights specification} 6 | \usage{ 7 | gompertzp(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized Gompertz probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate MIDAS weights according to normalized Gompertz probability density function specification 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/gompertzp_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{gompertzp_gradient} 4 | \alias{gompertzp_gradient} 5 | \title{Gradient function for normalized Gompertz probability density function MIDAS weights specification} 6 | \usage{ 7 | gompertzp_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized Gompertz probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate gradient function for normalized Gompertz probability density function specification of MIDAS weights. 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/hAh_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tests.R 3 | \name{hAh_test} 4 | \alias{hAh_test} 5 | \title{Test restrictions on coefficients of MIDAS regression} 6 | \usage{ 7 | hAh_test(x) 8 | } 9 | \arguments{ 10 | \item{x}{MIDAS regression model with restricted coefficients, estimated with \code{\link{midas_r}}} 11 | } 12 | \value{ 13 | a \code{htest} object 14 | } 15 | \description{ 16 | Perform a test whether the restriction on MIDAS regression coefficients holds. 17 | } 18 | \details{ 19 | Given MIDAS regression: 20 | 21 | \deqn{y_t=\sum_{j=0}^k\sum_{i=0}^{m-1}\theta_{jm+i} x_{(t-j)m-i}+u_t} 22 | 23 | test the null hypothesis that the following restriction holds: 24 | 25 | \deqn{\theta_h=g(h,\lambda),} 26 | where \eqn{h=0,...,(k+1)m}. 27 | } 28 | \examples{ 29 | ##The parameter function 30 | theta_h0 <- function(p, dk, ...) { 31 | i <- (1:dk-1) 32 | (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) 33 | } 34 | 35 | ##Generate coefficients 36 | theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) 37 | 38 | ##Plot the coefficients 39 | plot(theta0) 40 | 41 | ##Generate the predictor variable 42 | set.seed(13) 43 | 44 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 45 | 46 | ##Simulate the response variable 47 | y <- midas_sim(500, xx, theta0) 48 | 49 | x <- window(xx, start=start(y)) 50 | ##Fit restricted model 51 | mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), 52 | start=list(x=c(-0.1,0.1,-0.1,-0.001))) 53 | 54 | ##Perform test (the expected result should be the acceptance of null) 55 | 56 | hAh_test(mr) 57 | 58 | ##Fit using gradient function 59 | 60 | ##The gradient function 61 | theta_h0_gradient<-function(p, dk,...) { 62 | i <- (1:dk-1) 63 | a <- exp(p[3]*i + p[4]*i^2) 64 | cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) 65 | } 66 | 67 | mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), 68 | start=list(x=c(-0.1,0.1,-0.1,-0.001)), 69 | weight_gradients=list()) 70 | 71 | ##The test will use an user supplied gradient of weight function. See the 72 | ##help of midas_r on how to supply the gradient. 73 | 74 | hAh_test(mr) 75 | 76 | 77 | } 78 | \references{ 79 | Kvedaras V., Zemlys, V. \emph{Testing the functional constraints on parameters in regressions with variables of different frequency} Economics Letters 116 (2012) 250-254 80 | } 81 | \seealso{ 82 | hAhr_test 83 | } 84 | \author{ 85 | Virmantas Kvedaras, Vaidotas Zemlys 86 | } 87 | -------------------------------------------------------------------------------- /man/hAhr_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tests.R 3 | \name{hAhr_test} 4 | \alias{hAhr_test} 5 | \title{Test restrictions on coefficients of MIDAS regression using robust version of the test} 6 | \usage{ 7 | hAhr_test(x, PHI = vcovHAC(x$unrestricted, sandwich = FALSE)) 8 | } 9 | \arguments{ 10 | \item{x}{MIDAS regression model with restricted coefficients, estimated with \code{\link{midas_r}}} 11 | 12 | \item{PHI}{the "meat" covariance matrix, defaults to \code{vcovHAC(x$unrestricted, sandwich=FALSE)}} 13 | } 14 | \value{ 15 | a \code{htest} object 16 | } 17 | \description{ 18 | Perform a test whether the restriction on MIDAS regression coefficients holds. 19 | } 20 | \details{ 21 | Given MIDAS regression: 22 | 23 | \deqn{y_t=\sum_{j=0}^k\sum_{i=0}^{m-1}\theta_{jm+i} x_{(t-j)m-i}+u_t} 24 | 25 | test the null hypothesis that the following restriction holds: 26 | 27 | \deqn{\theta_h=g(h,\lambda),} 28 | where \eqn{h=0,...,(k+1)m}. 29 | } 30 | \examples{ 31 | ##The parameter function 32 | theta_h0 <- function(p, dk, ...) { 33 | i <- (1:dk-1) 34 | (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) 35 | } 36 | 37 | ##Generate coefficients 38 | theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) 39 | 40 | ##Plot the coefficients 41 | plot(theta0) 42 | 43 | ##Generate the predictor variable 44 | set.seed(13) 45 | 46 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 47 | 48 | ##Simulate the response variable 49 | y <- midas_sim(500, xx, theta0) 50 | 51 | x <- window(xx, start=start(y)) 52 | ##Fit restricted model 53 | mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, 54 | list(y=y,x=x), 55 | start=list(x=c(-0.1,0.1,-0.1,-0.001))) 56 | 57 | ##The gradient function 58 | theta_h0_gradient <-function(p, dk,...) { 59 | i <- (1:dk-1) 60 | a <- exp(p[3]*i + p[4]*i^2) 61 | cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) 62 | } 63 | 64 | ##Perform test (the expected result should be the acceptance of null) 65 | 66 | hAhr_test(mr) 67 | 68 | mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, 69 | list(y=y,x=x), 70 | start=list(x=c(-0.1,0.1,-0.1,-0.001)), 71 | weight_gradients=list()) 72 | 73 | ##Use exact gradient. Note the 74 | hAhr_test(mr) 75 | 76 | } 77 | \references{ 78 | Kvedaras V., Zemlys, V. \emph{The statistical content and empirical testing of the MIDAS restrictions} 79 | } 80 | \seealso{ 81 | hAh_test 82 | } 83 | \author{ 84 | Virmantas Kvedaras, Vaidotas Zemlys 85 | } 86 | -------------------------------------------------------------------------------- /man/harstep.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{harstep} 4 | \alias{harstep} 5 | \title{HAR(3)-RV model MIDAS weights specification} 6 | \usage{ 7 | harstep(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for Almon lag} 11 | 12 | \item{d}{number of the coefficients} 13 | 14 | \item{m}{the frequency, currently ignored.} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | HAR(3)-RV model MIDAS weights specification 21 | } 22 | \details{ 23 | MIDAS weights for Heterogeneous Autoregressive model of Realized Volatilty (HAR-RV). 24 | It is assumed that month has 20 days. 25 | } 26 | \references{ 27 | Corsi, F., \emph{A Simple Approximate Long-Memory Model of Realized Volatility}, 28 | Journal of Financial Econometrics Vol. 7 No. 2 (2009) 174-196 29 | } 30 | \author{ 31 | Virmantas Kvedaras, Vaidotas Zemlys 32 | } 33 | -------------------------------------------------------------------------------- /man/harstep_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{harstep_gradient} 4 | \alias{harstep_gradient} 5 | \title{Gradient function for HAR(3)-RV model MIDAS weights specification} 6 | \usage{ 7 | harstep_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for Almon lag} 11 | 12 | \item{d}{number of the coefficients} 13 | 14 | \item{m}{the frequency, currently ignored.} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Gradient function for HAR(3)-RV model MIDAS weights specification 21 | } 22 | \details{ 23 | MIDAS weights for Heterogeneous Autoregressive model of Realized Volatilty (HAR-RV). 24 | It is assumed that month has 20 days. 25 | } 26 | \references{ 27 | Corsi, F., \emph{A Simple Approximate Long-Memory Model of Realized Volatility}, 28 | Journal of Financial Econometrics Vol. 7 No. 2 (2009) 174-196 29 | } 30 | \author{ 31 | Virmantas Kvedaras, Vaidotas Zemlys 32 | } 33 | -------------------------------------------------------------------------------- /man/hf_lags_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{hf_lags_table} 4 | \alias{hf_lags_table} 5 | \title{Create a high frequency lag selection table for MIDAS regression model} 6 | \usage{ 7 | hf_lags_table( 8 | formula, 9 | data, 10 | start, 11 | from, 12 | to, 13 | IC = c("AIC", "BIC"), 14 | test = c("hAh_test"), 15 | Ofunction = "optim", 16 | weight_gradients = NULL, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{formula}{the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula} 22 | 23 | \item{data}{a list containing data with mixed frequencies} 24 | 25 | \item{start}{the starting values for optimisation} 26 | 27 | \item{from}{a named list, or named vector with lag numbers which are the beginings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero} 28 | 29 | \item{to}{a named list where each element is a vector with two elements. The first element is the lag number from which the lag selection starts, the second is the lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible.} 30 | 31 | \item{IC}{the information criteria which to compute} 32 | 33 | \item{test}{the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table} 34 | 35 | \item{Ofunction}{see \link{midasr}} 36 | 37 | \item{weight_gradients}{see \link{midas_r}} 38 | 39 | \item{...}{additional parameters to optimisation function, see \link{midas_r}} 40 | } 41 | \value{ 42 | a \code{midas_r_iclagtab} object which is the list with the following elements: 43 | 44 | \item{table}{the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure} 45 | \item{candlist}{the list containing fitted models} 46 | \item{IC}{the argument IC} 47 | } 48 | \description{ 49 | Creates a high frequency lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags. 50 | } 51 | \details{ 52 | This function estimates models sequentially increasing the midas lag from \code{kmin} to \code{kmax} of the last term of the given formula 53 | } 54 | \examples{ 55 | 56 | data("USunempr") 57 | data("USrealgdp") 58 | y <- diff(log(USrealgdp)) 59 | x <- window(diff(USunempr),start=1949) 60 | trend <- 1:length(y) 61 | 62 | mlr <- hf_lags_table(y ~ trend + fmls(x, 12, 12,nealmon), 63 | start = list(x=rep(0,3)), 64 | data = list(y = y, x = x, trend = trend), 65 | from=c(x=0),to=list(x=c(4,4))) 66 | mlr 67 | 68 | } 69 | \author{ 70 | Virmantas Kvedaras, Vaidotas Zemlys 71 | } 72 | -------------------------------------------------------------------------------- /man/imidas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imidasreg.R 3 | \name{imidas_r} 4 | \alias{imidas_r} 5 | \title{Restricted MIDAS regression with I(1) regressors} 6 | \usage{ 7 | imidas_r( 8 | formula, 9 | data, 10 | start, 11 | Ofunction = "optim", 12 | weight_gradients = NULL, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{formula}{formula for restricted MIDAS regression. Formula must include \code{\link{fmls}} function} 18 | 19 | \item{data}{a named list containing data with mixed frequencies} 20 | 21 | \item{start}{the starting values for optimisation. Must be a list with named elements} 22 | 23 | \item{Ofunction}{the list with information which R function to use for optimisation 24 | The list must have element named \code{Ofunction} which contains character string of chosen R 25 | function. Other elements of the list are the arguments passed to this function. 26 | The default optimisation function is \code{\link{optim}} with argument \code{method="BFGS"}. 27 | Other supported functions are \code{\link{nls}}} 28 | 29 | \item{weight_gradients}{a named list containing gradient functions of weights. The weight gradient 30 | function must return the matrix with dimensions \eqn{d_k \times q}, where \eqn{d_k} and \eqn{q} 31 | are the number of coefficients in unrestricted and restricted regressions correspondingly. 32 | The names of the list should coincide with the names of weights used in formula. 33 | The default value is NULL, which means that the numeric approximation of weight 34 | function gradient is calculated. If the argument is not NULL, but the weight 35 | used in formula is not present, it is assumed that there exists an R 36 | function which has the name of the weight function appended with \code{.gradient}.} 37 | 38 | \item{...}{additional arguments supplied to optimisation function} 39 | } 40 | \value{ 41 | a \code{midas_r} object which is the list with the following elements: 42 | 43 | \item{coefficients}{the estimates of parameters of restrictions} 44 | \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 45 | \item{model}{model data} 46 | \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 47 | \item{term_info}{the named list. Each element is a list with the information about the term, 48 | such as its frequency, function for weights, gradient function of weights, etc.} 49 | \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 50 | \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 51 | \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 52 | \item{opt}{the output of optimisation procedure} 53 | \item{argmap_opt}{the list containing the name of optimisation function together with arguments 54 | for optimisation function} 55 | \item{start_opt}{the starting values used in optimisation} 56 | \item{start_list}{the starting values as a list} 57 | \item{call}{the call to the function} 58 | \item{terms}{terms object} 59 | \item{gradient}{gradient of NLS objective function} 60 | \item{hessian}{hessian of NLS objective function} 61 | \item{gradD}{gradient function of MIDAS weight functions} 62 | \item{z_env}{the environment in which data is placed} 63 | \item{use_gradient}{TRUE if user supplied gradient is used, FALSE otherwise} 64 | \item{nobs}{the number of effective observations} 65 | \item{convergence}{the convergence message} 66 | \item{fitted.values}{the fitted values of MIDAS regression} 67 | \item{residuals}{the residuals of MIDAS regression} 68 | } 69 | \description{ 70 | Estimate restricted MIDAS regression using non-linear least squares, when the regressor is I(1) 71 | } 72 | \details{ 73 | Given MIDAS regression: 74 | 75 | \deqn{y_t=\sum_{j=0}^k\sum_{i=0}^{m-1}\theta_{jm+i} x_{(t-j)m-i}+\mathbf{z_t}\beta+u_t} 76 | 77 | estimate the parameters of the restriction 78 | 79 | \deqn{\theta_h=g(h,\lambda),} 80 | where \eqn{h=0,...,(k+1)m}, together with coefficients \eqn{\beta} corresponding to additional 81 | low frequency regressors. 82 | 83 | It is assumed that \eqn{x} is a I(1) process, hence the special transformation is made. 84 | After the transformation \link{midas_r} is used for estimation. 85 | 86 | MIDAS regression involves times series with different frequencies. 87 | 88 | The restriction function must return the restricted coefficients of 89 | the MIDAS regression. 90 | } 91 | \examples{ 92 | theta.h0 <- function(p, dk) { 93 | i <- (1:dk-1)/100 94 | pol <- p[3]*i + p[4]*i^2 95 | (p[1] + p[2]*i)*exp(pol) 96 | } 97 | 98 | theta0 <- theta.h0(c(-0.1,10,-10,-10),4*12) 99 | 100 | xx <- ts(cumsum(rnorm(600*12)), frequency = 12) 101 | 102 | ##Simulate the response variable 103 | y <- midas_sim(500, xx, theta0) 104 | 105 | x <- window(xx, start=start(y)) 106 | 107 | imr <- imidas_r(y~fmls(x,4*12-1,12,theta.h0)-1,start=list(x=c(-0.1,10,-10,-10))) 108 | 109 | } 110 | \seealso{ 111 | midas_r.midas_r 112 | } 113 | \author{ 114 | Virmantas Kvedaras, Vaidotas Zemlys 115 | } 116 | -------------------------------------------------------------------------------- /man/lcauchyp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{lcauchyp} 4 | \alias{lcauchyp} 5 | \title{Normalized log-Cauchy probability density function MIDAS weights specification} 6 | \usage{ 7 | lcauchyp(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized log-Cauchy probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate MIDAS weights according to normalized log-Cauchy probability density function specification 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/lcauchyp_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{lcauchyp_gradient} 4 | \alias{lcauchyp_gradient} 5 | \title{Gradient function for normalized log-Cauchy probability density function MIDAS weights specification} 6 | \usage{ 7 | lcauchyp_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized log-Cauchy probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate gradient function for normalized log-Cauchy probability density function specification of MIDAS weights. 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/lf_lags_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{lf_lags_table} 4 | \alias{lf_lags_table} 5 | \title{Create a low frequency lag selection table for MIDAS regression model} 6 | \usage{ 7 | lf_lags_table( 8 | formula, 9 | data, 10 | start, 11 | from, 12 | to, 13 | IC = c("AIC", "BIC"), 14 | test = c("hAh_test"), 15 | Ofunction = "optim", 16 | weight_gradients = NULL, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{formula}{the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula} 22 | 23 | \item{data}{a list containing data with mixed frequencies} 24 | 25 | \item{start}{the starting values for optimisation} 26 | 27 | \item{from}{a named list, or named vector with high frequency (NB!) lag numbers which are the beginnings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero} 28 | 29 | \item{to}{a named list where each element is a vector with two elements. The first element is the low frequency lag number from which the lag selection starts, the second is the low frequency lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible.} 30 | 31 | \item{IC}{the information criteria which to compute} 32 | 33 | \item{test}{the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table} 34 | 35 | \item{Ofunction}{see \link{midasr}} 36 | 37 | \item{weight_gradients}{see \link{midas_r}} 38 | 39 | \item{...}{additional parameters to optimisation function, see \link{midas_r}} 40 | } 41 | \value{ 42 | a \code{midas_r_ic_table} object which is the list with the following elements: 43 | 44 | \item{table}{the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure} 45 | \item{candlist}{the list containing fitted models} 46 | \item{IC}{the argument IC} 47 | } 48 | \description{ 49 | Creates a low frequency lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags. 50 | } 51 | \details{ 52 | This function estimates models sequentially increasing the midas lag from \code{kmin} to \code{kmax} of the last term of the given formula 53 | } 54 | \examples{ 55 | 56 | data("USunempr") 57 | data("USrealgdp") 58 | y <- diff(log(USrealgdp)) 59 | x <- window(diff(USunempr),start=1949) 60 | trend <- 1:length(y) 61 | 62 | mlr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), 63 | start=list(x=rep(0,3)), 64 | from=c(x=0),to=list(x=c(3,4))) 65 | mlr 66 | 67 | } 68 | \author{ 69 | Virmantas Kvedaras, Vaidotas Zemlys 70 | } 71 | -------------------------------------------------------------------------------- /man/lstr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{lstr} 4 | \alias{lstr} 5 | \title{Compute LSTR term for high frequency variable} 6 | \usage{ 7 | lstr(X, theta, beta, sd_x = sd(c(X), na.rm = TRUE)) 8 | } 9 | \arguments{ 10 | \item{X}{matrix, high frequency variable embedded in low frequency, output of mls} 11 | 12 | \item{theta}{vector, restriction coefficients for high frequency variable} 13 | 14 | \item{beta}{vector of length 4, parameters for LSTR term, slope and 3 LSTR parameters} 15 | 16 | \item{sd_x}{vector of length 1, defaults to standard deviation of X.} 17 | } 18 | \value{ 19 | a vector 20 | } 21 | \description{ 22 | Compute LSTR term for high frequency variable 23 | } 24 | -------------------------------------------------------------------------------- /man/lws_table-add.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{+.lws_table} 4 | \alias{+.lws_table} 5 | \title{Combine \code{lws_table} objects} 6 | \usage{ 7 | \method{+}{lws_table}(..., check = TRUE) 8 | } 9 | \arguments{ 10 | \item{...}{\code{lws_table} object} 11 | 12 | \item{check}{logical, if TRUE checks that the each \code{lws_table} object is named a list with names \code{c("weights","lags","starts")}} 13 | } 14 | \value{ 15 | \code{lws_table} object 16 | } 17 | \description{ 18 | Combines \code{lws_table} objects 19 | } 20 | \details{ 21 | The \code{lws_table} objects have similar structure to table, i.e. it is a list with 3 elements which are the lists with the same number of elements. The base function \code{c} would \code{cbind} such tables. This function \code{rbind}s them. 22 | } 23 | \examples{ 24 | nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) 25 | nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) 26 | 27 | nlmn+nbt 28 | } 29 | \author{ 30 | Virmantas Kvedaras, Vaidotas Zemlys 31 | } 32 | -------------------------------------------------------------------------------- /man/midas_auto_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_auto_sim} 4 | \alias{midas_auto_sim} 5 | \title{Simulate simple autoregressive MIDAS model} 6 | \usage{ 7 | midas_auto_sim( 8 | n, 9 | alpha, 10 | x, 11 | theta, 12 | rand_gen = rnorm, 13 | innov = rand_gen(n, ...), 14 | n_start = NA, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{n}{sample size.} 20 | 21 | \item{alpha}{autoregressive coefficients.} 22 | 23 | \item{x}{a high frequency predictor variable.} 24 | 25 | \item{theta}{a vector with MIDAS weights for predictor variable.} 26 | 27 | \item{rand_gen}{a function to generate the innovations, default is the normal distribution.} 28 | 29 | \item{innov}{an optional time series of innovations.} 30 | 31 | \item{n_start}{number of observations to omit for the burn.in.} 32 | 33 | \item{...}{additional arguments to function \code{rand_gen}.} 34 | } 35 | \value{ 36 | a \code{ts} object 37 | } 38 | \description{ 39 | Given the predictor variable, the weights and autoregressive coefficients, simulate MIDAS regression response variable. 40 | } 41 | \examples{ 42 | theta_h0 <- function(p, dk) { 43 | i <- (1:dk-1)/100 44 | pol <- p[3]*i + p[4]*i^2 45 | (p[1] + p[2]*i)*exp(pol) 46 | } 47 | 48 | ##Generate coefficients 49 | theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) 50 | 51 | ##Generate the predictor variable 52 | xx <- ts(arima.sim(model = list(ar = 0.6), 1000 * 12), frequency = 12) 53 | 54 | y <- midas_auto_sim(500, 0.5, xx, theta0, n_start = 200) 55 | x <- window(xx, start=start(y)) 56 | midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10))) 57 | } 58 | \author{ 59 | Virmantas Kvedaras, Vaidotas Zemlys 60 | } 61 | -------------------------------------------------------------------------------- /man/midas_lstr_plain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{midas_lstr_plain} 4 | \alias{midas_lstr_plain} 5 | \title{LSTR (Logistic Smooth TRansition) MIDAS regression} 6 | \usage{ 7 | midas_lstr_plain( 8 | y, 9 | X, 10 | z = NULL, 11 | weight, 12 | start_lstr, 13 | start_x, 14 | start_z = NULL, 15 | method = c("Nelder-Mead"), 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{y}{model response} 21 | 22 | \item{X}{prepared matrix of high frequency variable lags for LSTR term} 23 | 24 | \item{z}{additional low frequency variables} 25 | 26 | \item{weight}{the weight function} 27 | 28 | \item{start_lstr}{the starting values for lstr term} 29 | 30 | \item{start_x}{the starting values for weight function} 31 | 32 | \item{start_z}{the starting values for additional low frequency variables} 33 | 34 | \item{method}{a method passed to \link[optimx]{optimx}} 35 | 36 | \item{...}{additional parameters to \link[optimx]{optimx}} 37 | } 38 | \value{ 39 | an object similar to \code{midas_r} object 40 | } 41 | \description{ 42 | Function for fitting LSTR MIDAS regression without the formula interface 43 | } 44 | \author{ 45 | Virmantas Kvedaras, Vaidotas Zemlys 46 | } 47 | -------------------------------------------------------------------------------- /man/midas_lstr_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_lstr_sim} 4 | \alias{midas_lstr_sim} 5 | \title{Simulate LSTR MIDAS regression model} 6 | \usage{ 7 | midas_lstr_sim( 8 | n, 9 | m, 10 | theta, 11 | intercept, 12 | plstr, 13 | ar.x, 14 | ar.y, 15 | rand.gen = rnorm, 16 | n.start = NA, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{n}{number of observations to simulate.} 22 | 23 | \item{m}{integer, frequency ratio} 24 | 25 | \item{theta}{vector, restriction coefficients for high frequency variable} 26 | 27 | \item{intercept}{vector of length 1, intercept for the model.} 28 | 29 | \item{plstr}{vector of length 4, slope for the LSTR term and LSTR parameters} 30 | 31 | \item{ar.x}{vector, AR parameters for simulating high frequency variable} 32 | 33 | \item{ar.y}{vector, AR parameters for AR part of the model} 34 | 35 | \item{rand.gen}{function, a function for generating the regression innovations, default is \code{rnorm}} 36 | 37 | \item{n.start}{integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed.} 38 | 39 | \item{...}{additional parameters to rand.gen} 40 | } 41 | \value{ 42 | a list 43 | } 44 | \description{ 45 | Simulate LSTR MIDAS regression model 46 | } 47 | \examples{ 48 | 49 | nnbeta <- function(p, k) nbeta(c(1, p), k) 50 | 51 | dgp <- midas_lstr_sim(250, 52 | m = 12, theta = nnbeta(c(2, 4), 24), 53 | intercept = c(1), plstr = c(1.5, 1, log(1), 1), 54 | ar.x = 0.9, ar.y = 0.5, n.start = 100 55 | ) 56 | 57 | z <- cbind(1, mls(dgp$y, 1:2, 1)) 58 | colnames(z) <- c("Intercept", "y1", "y2") 59 | X <- mls(dgp$x, 0:23, 12) 60 | 61 | lstr_mod <- midas_lstr_plain(dgp$y, X, z, nnbeta, 62 | start_lstr = c(1.5, 1, 1, 1), 63 | start_x = c(2, 4), start_z = c(1, 0.5, 0) 64 | ) 65 | 66 | coef(lstr_mod) 67 | } 68 | -------------------------------------------------------------------------------- /man/midas_mmm_plain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{midas_mmm_plain} 4 | \alias{midas_mmm_plain} 5 | \title{MMM (Mean-Min-Max) MIDAS regression} 6 | \usage{ 7 | midas_mmm_plain( 8 | y, 9 | X, 10 | z = NULL, 11 | weight, 12 | start_mmm, 13 | start_x, 14 | start_z = NULL, 15 | method = c("Nelder-Mead"), 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{y}{model response} 21 | 22 | \item{X}{prepared matrix of high frequency variable lags for MMM term} 23 | 24 | \item{z}{additional low frequency variables} 25 | 26 | \item{weight}{the weight function} 27 | 28 | \item{start_mmm}{the starting values for MMM term} 29 | 30 | \item{start_x}{the starting values for weight function} 31 | 32 | \item{start_z}{the starting values for additional low frequency variables} 33 | 34 | \item{method}{a method passed to \link[optimx]{optimx}} 35 | 36 | \item{...}{additional parameters to \link[optimx]{optimx}} 37 | } 38 | \value{ 39 | an object similar to \code{midas_r} object 40 | } 41 | \description{ 42 | Function for fitting MMM MIDAS regression without the formula interface 43 | } 44 | \author{ 45 | Virmantas Kvedaras, Vaidotas Zemlys 46 | } 47 | -------------------------------------------------------------------------------- /man/midas_mmm_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_mmm_sim} 4 | \alias{midas_mmm_sim} 5 | \title{Simulate MMM MIDAS regression model} 6 | \usage{ 7 | midas_mmm_sim( 8 | n, 9 | m, 10 | theta, 11 | intercept, 12 | pmmm, 13 | ar.x, 14 | ar.y, 15 | rand.gen = rnorm, 16 | n.start = NA, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{n}{number of observations to simulate.} 22 | 23 | \item{m}{integer, frequency ratio} 24 | 25 | \item{theta}{vector, restriction coefficients for high frequency variable} 26 | 27 | \item{intercept}{vector of length 1, intercept for the model.} 28 | 29 | \item{pmmm}{vector of length 2, slope for the MMM term and MMM parameter} 30 | 31 | \item{ar.x}{vector, AR parameters for simulating high frequency variable} 32 | 33 | \item{ar.y}{vector, AR parameters for AR part of the model} 34 | 35 | \item{rand.gen}{function, a function for generating the regression innovations, default is \code{rnorm}} 36 | 37 | \item{n.start}{integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed.} 38 | 39 | \item{...}{additional parameters to rand.gen} 40 | } 41 | \value{ 42 | a list 43 | } 44 | \description{ 45 | Simulate MMM MIDAS regression model 46 | } 47 | \examples{ 48 | 49 | nnbeta <- function(p, k) nbeta(c(1, p), k) 50 | 51 | dgp <- midas_mmm_sim(250, 52 | m = 12, theta = nnbeta(c(2, 4), 24), 53 | intercept = c(1), pmmm = c(1.5, 1), 54 | ar.x = 0.9, ar.y = 0.5, n.start = 100 55 | ) 56 | 57 | z <- cbind(1, mls(dgp$y, 1:2, 1)) 58 | colnames(z) <- c("Intercept", "y1", "y2") 59 | X <- mls(dgp$x, 0:23, 12) 60 | 61 | mmm_mod <- midas_mmm_plain(dgp$y, X, z, nnbeta, 62 | start_mmm = c(1.5, 1), 63 | start_x = c(2, 4), start_z = c(1, 0.5, 0) 64 | ) 65 | 66 | coef(mmm_mod) 67 | } 68 | -------------------------------------------------------------------------------- /man/midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{midas_nlpr} 4 | \alias{midas_nlpr} 5 | \title{Non-linear parametric MIDAS regression} 6 | \usage{ 7 | midas_nlpr(formula, data, start, Ofunction = "optim", ...) 8 | } 9 | \arguments{ 10 | \item{formula}{formula for restricted MIDAS regression or \code{midas_r} object. Formula must include \code{\link{fmls}} function} 11 | 12 | \item{data}{a named list containing data with mixed frequencies} 13 | 14 | \item{start}{the starting values for optimisation. Must be a list with named elements.} 15 | 16 | \item{Ofunction}{the list with information which R function to use for optimisation. The list must have element named \code{Ofunction} which contains character string of chosen 17 | R function. Other elements of the list are the arguments passed to this function. The default optimisation function is \code{\link{optim}} with arguments 18 | \code{method="Nelder-Mead"} and \code{control=list(maxit=5000)}. Other supported functions are \code{\link{nls}}, \code{\link[optimx]{optimx}}.} 19 | 20 | \item{...}{additional arguments supplied to optimisation function} 21 | } 22 | \value{ 23 | a \code{midas_r} object which is the list with the following elements: 24 | 25 | \item{coefficients}{the estimates of parameters of restrictions} 26 | \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 27 | \item{model}{model data} 28 | \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 29 | \item{term_info}{the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc.} 30 | \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 31 | \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 32 | \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 33 | \item{opt}{the output of optimisation procedure} 34 | \item{argmap_opt}{the list containing the name of optimisation function together with arguments for optimisation function} 35 | \item{start_opt}{the starting values used in optimisation} 36 | \item{start_list}{the starting values as a list} 37 | \item{call}{the call to the function} 38 | \item{terms}{terms object} 39 | \item{gradient}{gradient of NLS objective function} 40 | \item{hessian}{hessian of NLS objective function} 41 | \item{gradD}{gradient function of MIDAS weight functions} 42 | \item{Zenv}{the environment in which data is placed} 43 | \item{nobs}{the number of effective observations} 44 | \item{convergence}{the convergence message} 45 | \item{fitted.values}{the fitted values of MIDAS regression} 46 | \item{residuals}{the residuals of MIDAS regression} 47 | } 48 | \description{ 49 | Estimate restricted MIDAS regression using non-linear least squares. 50 | } 51 | \details{ 52 | Given MIDAS regression: 53 | 54 | \deqn{y_t = \sum_{j=1}^p\alpha_jy_{t-j} +\sum_{i=0}^{k}\sum_{j=0}^{l_i}\beta_{j}^{(i)}x_{tm_i-j}^{(i)} + u_t,} 55 | 56 | estimate the parameters of the restriction 57 | 58 | \deqn{\beta_j^{(i)}=g^{(i)}(j,\lambda).} 59 | 60 | Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function \eqn{g^{(i)}} 61 | might be an identity function. Model with no restrictions is called U-MIDAS model. The regressors \eqn{x_\tau^{(i)}} must be of higher 62 | (or of the same) frequency as the dependent variable \eqn{y_t}. 63 | } 64 | \author{ 65 | Virmantas Kvedaras, Vaidotas Zemlys 66 | } 67 | -------------------------------------------------------------------------------- /man/midas_nlpr.fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{midas_nlpr.fit} 4 | \alias{midas_nlpr.fit} 5 | \title{Fit restricted MIDAS regression} 6 | \usage{ 7 | midas_nlpr.fit(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{midas_r} object} 11 | } 12 | \value{ 13 | \code{\link{midas_r}} object 14 | } 15 | \description{ 16 | Workhorse function for fitting restricted MIDAS regression 17 | } 18 | \author{ 19 | Vaidotas Zemlys 20 | } 21 | -------------------------------------------------------------------------------- /man/midas_pl_plain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp.R 3 | \name{midas_pl_plain} 4 | \alias{midas_pl_plain} 5 | \title{MIDAS Partialy linear non-parametric regression} 6 | \usage{ 7 | midas_pl_plain( 8 | y, 9 | X, 10 | z, 11 | p.ar = NULL, 12 | weight, 13 | degree = 1, 14 | start_bws, 15 | start_x, 16 | start_ar = NULL, 17 | method = c("Nelder-Mead"), 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{y}{model response} 23 | 24 | \item{X}{prepared matrix of high frequency variable lags for MMM term} 25 | 26 | \item{z}{a vector, data for the non-parametric part} 27 | 28 | \item{p.ar}{length of AR part} 29 | 30 | \item{weight}{the weight function} 31 | 32 | \item{degree}{the degree of local polynomial} 33 | 34 | \item{start_bws}{the starting values bandwith} 35 | 36 | \item{start_x}{the starting values for weight function} 37 | 38 | \item{start_ar}{the starting values for AR part. Should be the same length as \code{p}} 39 | 40 | \item{method}{a method passed to \link{optim}} 41 | 42 | \item{...}{additional parameters to \link{optim}} 43 | } 44 | \value{ 45 | an object similar to \code{midas_r} object 46 | } 47 | \description{ 48 | Function for fitting PL MIDAS regression without the formula interface 49 | } 50 | \author{ 51 | Virmantas Kvedaras, Vaidotas Zemlys 52 | } 53 | -------------------------------------------------------------------------------- /man/midas_pl_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_pl_sim} 4 | \alias{midas_pl_sim} 5 | \title{Simulate PL MIDAS regression model} 6 | \usage{ 7 | midas_pl_sim( 8 | n, 9 | m, 10 | theta, 11 | gfun, 12 | ar.x, 13 | ar.y, 14 | rand.gen = rnorm, 15 | n.start = NA, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{n}{number of observations to simulate.} 21 | 22 | \item{m}{integer, frequency ratio} 23 | 24 | \item{theta}{vector, restriction coefficients for high frequency variable} 25 | 26 | \item{gfun}{function, a function which takes a single index} 27 | 28 | \item{ar.x}{vector, AR parameters for simulating high frequency variable} 29 | 30 | \item{ar.y}{vector, AR parameters for AR part of the model} 31 | 32 | \item{rand.gen}{function, a function for generating the regression innovations, default is \code{rnorm}} 33 | 34 | \item{n.start}{integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed.} 35 | 36 | \item{...}{additional parameters to rand.gen} 37 | } 38 | \value{ 39 | a list 40 | } 41 | \description{ 42 | Simulate PL MIDAS regression model 43 | } 44 | \examples{ 45 | 46 | nnbeta <- function(p, k) nbeta(c(1, p), k) 47 | 48 | dgp <- midas_pl_sim(250, 49 | m = 12, theta = nnbeta(c(2, 4), 24), 50 | gfun = function(x) 0.25 * x^3, 51 | ar.x = 0.9, ar.y = 0.5, n.start = 100 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /man/midas_qr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasqr.R 3 | \name{midas_qr} 4 | \alias{midas_qr} 5 | \title{Restricted MIDAS quantile regression} 6 | \usage{ 7 | midas_qr( 8 | formula, 9 | data, 10 | tau = 0.5, 11 | start, 12 | Ofunction = "nlrq", 13 | weight_gradients = NULL, 14 | guess_start = TRUE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{formula}{formula for restricted MIDAS regression or \code{midas_qr} object. Formula must include \code{\link{mls}} function} 20 | 21 | \item{data}{a named list containing data with mixed frequencies} 22 | 23 | \item{tau}{quantile} 24 | 25 | \item{start}{the starting values for optimisation. Must be a list with named elements.} 26 | 27 | \item{Ofunction}{the list with information which R function to use for optimisation. The list must have element named \code{Ofunction} which contains character string of chosen R function. Other elements of the list are the arguments passed to this function. The default optimisation function is \code{\link{optim}} with argument \code{method="BFGS"}. Other supported functions are \code{\link{nls}}} 28 | 29 | \item{weight_gradients}{a named list containing gradient functions of weights. The weight gradient function must return the matrix with dimensions 30 | \eqn{d_k \times q}, where \eqn{d_k} and \eqn{q} are the number of coefficients in unrestricted and restricted regressions correspondingly. 31 | The names of the list should coincide with the names of weights used in formula. 32 | The default value is NULL, which means that the numeric approximation of weight function gradient is calculated. If the argument is not NULL, but the 33 | name of the weight used in formula is not present, it is assumed that there exists an R function which has 34 | the name of the weight function appended with \code{_gradient}.} 35 | 36 | \item{guess_start, }{logical, if TRUE tries certain strategy to improve starting values} 37 | 38 | \item{...}{additional arguments supplied to optimisation function} 39 | } 40 | \value{ 41 | a \code{midas_r} object which is the list with the following elements: 42 | 43 | \item{coefficients}{the estimates of parameters of restrictions} 44 | \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 45 | \item{model}{model data} 46 | \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 47 | \item{term_info}{the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc.} 48 | \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 49 | \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 50 | \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 51 | \item{opt}{the output of optimisation procedure} 52 | \item{argmap_opt}{the list containing the name of optimisation function together with arguments for optimisation function} 53 | \item{start_opt}{the starting values used in optimisation} 54 | \item{start_list}{the starting values as a list} 55 | \item{call}{the call to the function} 56 | \item{terms}{terms object} 57 | \item{gradient}{gradient of NLS objective function} 58 | \item{hessian}{hessian of NLS objective function} 59 | \item{gradD}{gradient function of MIDAS weight functions} 60 | \item{Zenv}{the environment in which data is placed} 61 | \item{use_gradient}{TRUE if user supplied gradient is used, FALSE otherwise} 62 | \item{nobs}{the number of effective observations} 63 | \item{convergence}{the convergence message} 64 | \item{fitted.values}{the fitted values of MIDAS regression} 65 | \item{residuals}{the residuals of MIDAS regression} 66 | } 67 | \description{ 68 | Estimate restricted MIDAS quantile regression using nonlinear quantile regression 69 | } 70 | \examples{ 71 | ##Take the same example as in midas_r 72 | 73 | theta_h0 <- function(p, dk, ...) { 74 | i <- (1:dk-1)/100 75 | pol <- p[3]*i + p[4]*i^2 76 | (p[1] + p[2]*i)*exp(pol) 77 | } 78 | 79 | ##Generate coefficients 80 | theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) 81 | 82 | ##Plot the coefficients 83 | plot(theta0) 84 | 85 | ##Generate the predictor variable 86 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 87 | 88 | ##Simulate the response variable 89 | y <- midas_sim(500, xx, theta0) 90 | 91 | x <- window(xx, start=start(y)) 92 | 93 | ##Fit quantile regression. All the coefficients except intercept should be constant. 94 | ##Intercept coefficient should correspond to quantile function of regression errors. 95 | mr <- midas_qr(y~fmls(x,4*12-1,12,theta_h0), tau = c(0.1, 0.5, 0.9), 96 | list(y=y,x=x), 97 | start=list(x=c(-0.1,10,-10,-10))) 98 | 99 | mr 100 | } 101 | \author{ 102 | Vaidotas Zemlys-Balevicius 103 | } 104 | -------------------------------------------------------------------------------- /man/midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasreg.R 3 | \name{midas_r} 4 | \alias{midas_r} 5 | \title{Restricted MIDAS regression} 6 | \usage{ 7 | midas_r( 8 | formula, 9 | data, 10 | start, 11 | Ofunction = "optim", 12 | weight_gradients = NULL, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{formula}{formula for restricted MIDAS regression or \code{midas_r} object. Formula must include \code{\link{fmls}} function} 18 | 19 | \item{data}{a named list containing data with mixed frequencies} 20 | 21 | \item{start}{the starting values for optimisation. Must be a list with named elements.} 22 | 23 | \item{Ofunction}{the list with information which R function to use for optimisation. The list must have element named \code{Ofunction} which contains character string of chosen R function. Other elements of the list are the arguments passed to this function. The default optimisation function is \code{\link{optim}} with argument \code{method="BFGS"}. Other supported functions are \code{\link{nls}}} 24 | 25 | \item{weight_gradients}{a named list containing gradient functions of weights. The weight gradient function must return the matrix with dimensions 26 | \eqn{d_k \times q}, where \eqn{d_k} and \eqn{q} are the number of coefficients in unrestricted and restricted regressions correspondingly. 27 | The names of the list should coincide with the names of weights used in formula. 28 | The default value is NULL, which means that the numeric approximation of weight function gradient is calculated. If the argument is not NULL, but the 29 | name of the weight used in formula is not present, it is assumed that there exists an R function which has 30 | the name of the weight function appended with \code{_gradient}.} 31 | 32 | \item{...}{additional arguments supplied to optimisation function} 33 | } 34 | \value{ 35 | a \code{midas_r} object which is the list with the following elements: 36 | 37 | \item{coefficients}{the estimates of parameters of restrictions} 38 | \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 39 | \item{model}{model data} 40 | \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 41 | \item{term_info}{the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc.} 42 | \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 43 | \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 44 | \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 45 | \item{opt}{the output of optimisation procedure} 46 | \item{argmap_opt}{the list containing the name of optimisation function together with arguments for optimisation function} 47 | \item{start_opt}{the starting values used in optimisation} 48 | \item{start_list}{the starting values as a list} 49 | \item{call}{the call to the function} 50 | \item{terms}{terms object} 51 | \item{gradient}{gradient of NLS objective function} 52 | \item{hessian}{hessian of NLS objective function} 53 | \item{gradD}{gradient function of MIDAS weight functions} 54 | \item{Zenv}{the environment in which data is placed} 55 | \item{use_gradient}{TRUE if user supplied gradient is used, FALSE otherwise} 56 | \item{nobs}{the number of effective observations} 57 | \item{convergence}{the convergence message} 58 | \item{fitted.values}{the fitted values of MIDAS regression} 59 | \item{residuals}{the residuals of MIDAS regression} 60 | } 61 | \description{ 62 | Estimate restricted MIDAS regression using non-linear least squares. 63 | } 64 | \details{ 65 | Given MIDAS regression: 66 | 67 | \deqn{y_t = \sum_{j=1}^p\alpha_jy_{t-j} +\sum_{i=0}^{k}\sum_{j=0}^{l_i}\beta_{j}^{(i)}x_{tm_i-j}^{(i)} + u_t,} 68 | 69 | estimate the parameters of the restriction 70 | 71 | \deqn{\beta_j^{(i)}=g^{(i)}(j,\lambda).} 72 | 73 | Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function \eqn{g^{(i)}} 74 | might be an identity function. Model with no restrictions is called U-MIDAS model. The regressors \eqn{x_\tau^{(i)}} must be of higher 75 | (or of the same) frequency as the dependent variable \eqn{y_t}. 76 | 77 | MIDAS-AR* (a model with a common factor, see (Clements and Galvao, 2008)) can be estimated by specifying additional argument, see an example. 78 | 79 | The restriction function must return the restricted coefficients of 80 | the MIDAS regression. 81 | } 82 | \examples{ 83 | ##The parameter function 84 | theta_h0 <- function(p, dk, ...) { 85 | i <- (1:dk-1)/100 86 | pol <- p[3]*i + p[4]*i^2 87 | (p[1] + p[2]*i)*exp(pol) 88 | } 89 | 90 | ##Generate coefficients 91 | theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) 92 | 93 | ##Plot the coefficients 94 | plot(theta0) 95 | 96 | ##Generate the predictor variable 97 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 98 | 99 | ##Simulate the response variable 100 | y <- midas_sim(500, xx, theta0) 101 | 102 | x <- window(xx, start=start(y)) 103 | 104 | ##Fit restricted model 105 | mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, 106 | list(y=y,x=x), 107 | start=list(x=c(-0.1,10,-10,-10))) 108 | 109 | ##Include intercept and trend in regression 110 | mr_it <- midas_r(y~fmls(x,4*12-1,12,theta_h0)+trend, 111 | list(data.frame(y=y,trend=1:500),x=x), 112 | start=list(x=c(-0.1,10,-10,-10))) 113 | 114 | data("USrealgdp") 115 | data("USunempr") 116 | 117 | y.ar <- diff(log(USrealgdp)) 118 | xx <- window(diff(USunempr), start = 1949) 119 | trend <- 1:length(y.ar) 120 | 121 | ##Fit AR(1) model 122 | mr_ar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1) + 123 | fmls(xx, 11, 12, nealmon), 124 | start = list(xx = rep(0, 3))) 125 | 126 | ##First order MIDAS-AR* restricted model 127 | mr_arstar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1, "*") 128 | + fmls(xx, 11, 12, nealmon), 129 | start = list(xx = rep(0, 3))) 130 | 131 | } 132 | \references{ 133 | Clements, M. and Galvao, A., \emph{Macroeconomic Forecasting With Mixed-Frequency Data: Forecasting Output Growth in the United States}, Journal of Business and Economic Statistics, Vol.26 (No.4), (2008) 546-554 134 | } 135 | \author{ 136 | Virmantas Kvedaras, Vaidotas Zemlys 137 | } 138 | -------------------------------------------------------------------------------- /man/midas_r.fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasreg.R 3 | \name{midas_r.fit} 4 | \alias{midas_r.fit} 5 | \title{Fit restricted MIDAS regression} 6 | \usage{ 7 | midas_r.fit(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{midas_r} object} 11 | } 12 | \value{ 13 | \code{\link{midas_r}} object 14 | } 15 | \description{ 16 | Workhorse function for fitting restricted MIDAS regression 17 | } 18 | \author{ 19 | Vaidotas Zemlys 20 | } 21 | -------------------------------------------------------------------------------- /man/midas_r_ic_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{midas_r_ic_table} 4 | \alias{midas_r_ic_table} 5 | \title{Create a weight and lag selection table for MIDAS regression model} 6 | \usage{ 7 | midas_r_ic_table( 8 | formula, 9 | data = NULL, 10 | start = NULL, 11 | table, 12 | IC = c("AIC", "BIC"), 13 | test = c("hAh_test"), 14 | Ofunction = "optim", 15 | weight_gradients = NULL, 16 | show_progress = TRUE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{formula}{the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula} 22 | 23 | \item{data}{a list containing data with mixed frequencies} 24 | 25 | \item{start}{the starting values for optimisation excluding the starting values for the last term} 26 | 27 | \item{table}{an wls_table object, see \link{expand_weights_lags}} 28 | 29 | \item{IC}{the names of information criteria which to compute} 30 | 31 | \item{test}{the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table} 32 | 33 | \item{Ofunction}{see \link{midasr}} 34 | 35 | \item{weight_gradients}{see \link{midas_r}} 36 | 37 | \item{show_progress}{logical, TRUE to show progress bar, FALSE for silent evaluation} 38 | 39 | \item{...}{additional parameters to optimisation function, see \link{midas_r}} 40 | } 41 | \value{ 42 | a \code{midas_r_ic_table} object which is the list with the following elements: 43 | 44 | \item{table}{the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure} 45 | \item{candlist}{the list containing fitted models} 46 | \item{IC}{the argument IC} 47 | } 48 | \description{ 49 | Creates a weight and lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags. 50 | } 51 | \details{ 52 | This function estimates models sequentially increasing the midas lag from \code{kmin} to \code{kmax} and varying the weights of the last term of the given formula 53 | } 54 | \examples{ 55 | 56 | data("USunempr") 57 | data("USrealgdp") 58 | y <- diff(log(USrealgdp)) 59 | x <- window(diff(USunempr),start=1949) 60 | trend <- 1:length(y) 61 | 62 | 63 | mwlr <- midas_r_ic_table(y~trend+fmls(x,12,12,nealmon), 64 | table=list(x=list(weights= 65 | as.list(c("nealmon","nealmon","nbeta")), 66 | lags=list(0:4,0:5,0:6), 67 | starts=list(rep(0,3),rep(0,3,),c(1,1,1,0))))) 68 | 69 | mwlr 70 | 71 | } 72 | \author{ 73 | Virmantas Kvedaras, Vaidotas Zemlys 74 | } 75 | -------------------------------------------------------------------------------- /man/midas_r_np.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nonparametric.R 3 | \name{midas_r_np} 4 | \alias{midas_r_np} 5 | \title{Estimate non-parametric MIDAS regression} 6 | \usage{ 7 | midas_r_np(formula, data, lambda = NULL) 8 | } 9 | \arguments{ 10 | \item{formula}{formula specifying MIDAS regression} 11 | 12 | \item{data}{a named list containing data with mixed frequencies} 13 | 14 | \item{lambda}{smoothing parameter, defaults to \code{NULL}, which means that it is chosen by minimising AIC.} 15 | } 16 | \value{ 17 | a \code{midas_r_np} object 18 | } 19 | \description{ 20 | Estimates non-parametric MIDAS regression 21 | } 22 | \details{ 23 | Estimates non-parametric MIDAS regression accodring Breitung et al. 24 | } 25 | \examples{ 26 | data("USunempr") 27 | data("USrealgdp") 28 | y <- diff(log(USrealgdp)) 29 | x <- window(diff(USunempr),start=1949) 30 | trend <- 1:length(y) 31 | midas_r_np(y~trend+fmls(x,12,12)) 32 | } 33 | \references{ 34 | Breitung J, Roling C, Elengikal S (2013). \emph{Forecasting inflation rates using daily data: A nonparametric MIDAS approach} Working paper, URL http://www.ect.uni-bonn.de/mitarbeiter/joerg-breitung/npmidas. 35 | } 36 | \author{ 37 | Vaidotas Zemlys 38 | } 39 | -------------------------------------------------------------------------------- /man/midas_r_plain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasreg.R 3 | \name{midas_r_plain} 4 | \alias{midas_r_plain} 5 | \title{Restricted MIDAS regression} 6 | \usage{ 7 | midas_r_plain( 8 | y, 9 | X, 10 | z = NULL, 11 | weight, 12 | grw = NULL, 13 | startx, 14 | startz = NULL, 15 | method = c("Nelder-Mead", "BFGS"), 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{y}{model response} 21 | 22 | \item{X}{prepared matrix of high frequency variable lags} 23 | 24 | \item{z}{additional low frequency variables} 25 | 26 | \item{weight}{the weight function} 27 | 28 | \item{grw}{the gradient of weight function} 29 | 30 | \item{startx}{the starting values for weight function} 31 | 32 | \item{startz}{the starting values for additional low frequency variables} 33 | 34 | \item{method}{a method passed to \link[optimx]{optimx}} 35 | 36 | \item{...}{additional parameters to \link[optimx]{optimx}} 37 | } 38 | \value{ 39 | an object similar to \code{midas_r} object 40 | } 41 | \description{ 42 | Function for fitting MIDAS regression without the formula interface 43 | } 44 | \examples{ 45 | 46 | data("USunempr") 47 | data("USrealgdp") 48 | y <- diff(log(USrealgdp)) 49 | x <- window(diff(USunempr),start=1949) 50 | trend <- 1:length(y) 51 | 52 | X<-fmls(x,11,12) 53 | 54 | midas_r_plain(y,X,trend,weight=nealmon,startx=c(0,0,0)) 55 | } 56 | \author{ 57 | Virmantas Kvedaras, Vaidotas Zemlys 58 | } 59 | -------------------------------------------------------------------------------- /man/midas_si_plain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp.R 3 | \name{midas_si_plain} 4 | \alias{midas_si_plain} 5 | \title{MIDAS Single index regression} 6 | \usage{ 7 | midas_si_plain( 8 | y, 9 | X, 10 | p.ar = NULL, 11 | weight, 12 | degree = 1, 13 | start_bws, 14 | start_x, 15 | start_ar = NULL, 16 | method = "Nelder-Mead", 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{y}{model response} 22 | 23 | \item{X}{prepared matrix of high frequency variable lags for MMM term} 24 | 25 | \item{p.ar}{length of AR part} 26 | 27 | \item{weight}{the weight function} 28 | 29 | \item{degree}{the degree of local polynomial} 30 | 31 | \item{start_bws}{the starting values bandwith} 32 | 33 | \item{start_x}{the starting values for weight function} 34 | 35 | \item{start_ar}{the starting values for AR part. Should be the same length as \code{p}} 36 | 37 | \item{method}{a method passed to \link{optim}, defaults to Nelder-Mead} 38 | 39 | \item{...}{additional parameters to \link{optim}} 40 | } 41 | \value{ 42 | an object similar to \code{midas_r} object 43 | } 44 | \description{ 45 | Function for fitting SI MIDAS regression without the formula interface 46 | } 47 | \author{ 48 | Virmantas Kvedaras, Vaidotas Zemlys 49 | } 50 | -------------------------------------------------------------------------------- /man/midas_si_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_si_sim} 4 | \alias{midas_si_sim} 5 | \title{Simulate SI MIDAS regression model} 6 | \usage{ 7 | midas_si_sim( 8 | n, 9 | m, 10 | theta, 11 | gfun, 12 | ar.x, 13 | ar.y, 14 | rand.gen = rnorm, 15 | n.start = NA, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{n}{number of observations to simulate.} 21 | 22 | \item{m}{integer, frequency ratio} 23 | 24 | \item{theta}{vector, restriction coefficients for high frequency variable} 25 | 26 | \item{gfun}{function, a function which takes a single index} 27 | 28 | \item{ar.x}{vector, AR parameters for simulating high frequency variable} 29 | 30 | \item{ar.y}{vector, AR parameters for AR part of the model} 31 | 32 | \item{rand.gen}{function, a function for generating the regression innovations, default is \code{rnorm}} 33 | 34 | \item{n.start}{integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed.} 35 | 36 | \item{...}{additional parameters to rand.gen} 37 | } 38 | \value{ 39 | a list 40 | } 41 | \description{ 42 | Simulate SI MIDAS regression model 43 | } 44 | \examples{ 45 | 46 | nnbeta <- function(p, k) nbeta(c(1, p), k) 47 | 48 | dgp <- midas_si_sim(250, 49 | m = 12, theta = nnbeta(c(2, 4), 24), 50 | gfun = function(x) 0.03 * x^3, 51 | ar.x = 0.9, ar.y = 0.5, n.start = 100 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /man/midas_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{midas_sim} 4 | \alias{midas_sim} 5 | \title{Simulate simple MIDAS regression response variable} 6 | \usage{ 7 | midas_sim(n, x, theta, rand_gen = rnorm, innov = rand_gen(n, ...), ...) 8 | } 9 | \arguments{ 10 | \item{n}{The sample size} 11 | 12 | \item{x}{a \code{ts} object with MIDAS regression predictor variable} 13 | 14 | \item{theta}{a vector with MIDAS regression coefficients} 15 | 16 | \item{rand_gen}{the function which generates the sample of innovations, the default is \code{\link{rnorm}}} 17 | 18 | \item{innov}{the vector with innovations, the default is NULL, i.e. innovations are generated using argument \code{rand_gen}} 19 | 20 | \item{...}{additional arguments to \code{rand_gen}.} 21 | } 22 | \value{ 23 | a \code{ts} object 24 | } 25 | \description{ 26 | Given the predictor variable and the coefficients simulate MIDAS regression response variable. 27 | } 28 | \details{ 29 | MIDAS regression with one predictor variable has the following form: 30 | 31 | \deqn{y_t=\sum_{j=0}^{h}\theta_jx_{tm-j}+u_t,} 32 | where \eqn{m} is the frequency ratio and 33 | \eqn{h} is the number of high frequency lags included in the regression. 34 | 35 | MIDAS regression involves times series with different frequencies. In R 36 | the frequency property is set when creating time series objects 37 | \code{\link{ts}}. Hence the frequency ratio \eqn{m} which figures in MIDAS regression is calculated from frequency property of time series objects supplied. 38 | } 39 | \examples{ 40 | ##The parameter function 41 | theta_h0 <- function(p, dk) { 42 | i <- (1:dk-1)/100 43 | pol <- p[3]*i + p[4]*i^2 44 | (p[1] + p[2]*i)*exp(pol) 45 | } 46 | 47 | ##Generate coefficients 48 | theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) 49 | 50 | ##Plot the coefficients 51 | plot(theta0) 52 | 53 | ##Generate the predictor variable, leave 4 low frequency lags of data for burn-in. 54 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 55 | 56 | ##Simulate the response variable 57 | y <- midas_sim(500, xx, theta0) 58 | 59 | x <- window(xx, start=start(y)) 60 | midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10))) 61 | 62 | } 63 | \author{ 64 | Virmantas Kvedaras, Vaidotas Zemlys 65 | } 66 | -------------------------------------------------------------------------------- /man/midas_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp.R 3 | \name{midas_sp} 4 | \alias{midas_sp} 5 | \title{Semi-parametric MIDAS regression} 6 | \usage{ 7 | midas_sp(formula, data, bws, start, degree = 1, Ofunction = "optim", ...) 8 | } 9 | \arguments{ 10 | \item{formula}{formula for restricted MIDAS regression or \code{midas_r} object. Formula must include \code{\link{fmls}} function} 11 | 12 | \item{data}{a named list containing data with mixed frequencies} 13 | 14 | \item{bws}{a bandwith specification. Note you need to supply logarithm value of the bandwith.} 15 | 16 | \item{start}{the starting values for optimisation. Must be a list with named elements.} 17 | 18 | \item{degree}{the degree of local polynomial. 0 corresponds to local-constant, 1 local-linear. For univariate models higher values can be provided.} 19 | 20 | \item{Ofunction}{the list with information which R function to use for optimisation. The list must have element named \code{Ofunction} which contains character string of chosen 21 | R function. Other elements of the list are the arguments passed to this function. The default optimisation function is \code{\link[optimx]{optimx}} with arguments 22 | \code{method="Nelder-Mead"} and \code{control=list(maxit=5000)}. Other supported functions are \code{\link{nls}}, \code{\link[optimx]{optimx}}.} 23 | 24 | \item{...}{additional arguments supplied to optimisation function} 25 | } 26 | \value{ 27 | a \code{midas_sp} object which is the list with the following elements: 28 | 29 | \item{coefficients}{the estimates of parameters of restrictions} 30 | \item{midas_coefficients}{the estimates of MIDAS coefficients of MIDAS regression} 31 | \item{model}{model data} 32 | \item{unrestricted}{unrestricted regression estimated using \code{\link{midas_u}}} 33 | \item{term_info}{the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc.} 34 | \item{fn0}{optimisation function for non-linear least squares problem solved in restricted MIDAS regression} 35 | \item{rhs}{the function which evaluates the right-hand side of the MIDAS regression} 36 | \item{gen_midas_coef}{the function which generates the MIDAS coefficients of MIDAS regression} 37 | \item{opt}{the output of optimisation procedure} 38 | \item{argmap_opt}{the list containing the name of optimisation function together with arguments for optimisation function} 39 | \item{start_opt}{the starting values used in optimisation} 40 | \item{start_list}{the starting values as a list} 41 | \item{call}{the call to the function} 42 | \item{terms}{terms object} 43 | \item{gradient}{gradient of NLS objective function} 44 | \item{hessian}{hessian of NLS objective function} 45 | \item{gradD}{gradient function of MIDAS weight functions} 46 | \item{Zenv}{the environment in which data is placed} 47 | \item{nobs}{the number of effective observations} 48 | \item{convergence}{the convergence message} 49 | \item{fitted.values}{the fitted values of MIDAS regression} 50 | \item{residuals}{the residuals of MIDAS regression} 51 | } 52 | \description{ 53 | Estimate semi-parametric MIDAS regression using non-linear least squares. 54 | } 55 | \details{ 56 | Given MIDAS regression: 57 | 58 | \deqn{y_t = \sum_{j=1}^p\alpha_jy_{t-j} +\sum_{i=0}^{k}\sum_{j=0}^{l_i}\beta_{j}^{(i)}x_{tm_i-j}^{(i)} + u_t,} 59 | 60 | estimate the parameters of the restriction 61 | 62 | \deqn{\beta_j^{(i)}=g^{(i)}(j,\lambda).} 63 | 64 | Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function \eqn{g^{(i)}} 65 | might be an identity function. The regressors \eqn{x_\tau^{(i)}} must be of higher 66 | (or of the same) frequency as the dependent variable \eqn{y_t}. 67 | } 68 | \author{ 69 | Virmantas Kvedaras, Vaidotas Zemlys-Balevičius 70 | } 71 | -------------------------------------------------------------------------------- /man/midas_u.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasreg.R 3 | \name{midas_u} 4 | \alias{midas_u} 5 | \title{Estimate unrestricted MIDAS regression} 6 | \usage{ 7 | midas_u(formula, data, ...) 8 | } 9 | \arguments{ 10 | \item{formula}{MIDAS regression model formula} 11 | 12 | \item{data}{a named list containing data with mixed frequencies} 13 | 14 | \item{...}{further arguments, which could be passed to \code{\link{lm}} function.} 15 | } 16 | \value{ 17 | \code{\link{lm}} object. 18 | } 19 | \description{ 20 | Estimate unrestricted MIDAS regression using OLS. This function is a wrapper for \code{lm}. 21 | } 22 | \details{ 23 | MIDAS regression has the following form: 24 | 25 | \deqn{y_t = \sum_{j=1}^p\alpha_jy_{t-j} +\sum_{i=0}^{k}\sum_{j=0}^{l_i}\beta_{j}^{(i)}x_{tm_i-j}^{(i)} + u_t,} 26 | 27 | where \eqn{x_\tau^{(i)}}, \eqn{i=0,...k} are regressors of higher (or similar) frequency than \eqn{y_t}. 28 | Given certain assumptions the coefficients can be estimated using usual OLS and they have the familiar properties associated with simple linear regression. 29 | } 30 | \examples{ 31 | ##The parameter function 32 | theta_h0 <- function(p, dk, ...) { 33 | i <- (1:dk-1)/100 34 | pol <- p[3]*i + p[4]*i^2 35 | (p[1] + p[2]*i)*exp(pol) 36 | } 37 | 38 | ##Generate coefficients 39 | theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) 40 | 41 | ##Plot the coefficients 42 | ##Do not run 43 | #plot(theta0) 44 | 45 | ##' ##Generate the predictor variable 46 | xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) 47 | 48 | ##Simulate the response variable 49 | y <- midas_sim(500, xx, theta0) 50 | 51 | x <- window(xx, start=start(y)) 52 | 53 | ##Create low frequency data.frame 54 | ldt <- data.frame(y=y,trend=1:length(y)) 55 | 56 | ##Create high frequency data.frame 57 | 58 | hdt <- data.frame(x=window(x, start=start(y))) 59 | 60 | ##Fit unrestricted model 61 | mu <- midas_u(y~fmls(x,2,12)-1, list(ldt, hdt)) 62 | 63 | ##Include intercept and trend in regression 64 | 65 | mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, hdt)) 66 | 67 | ##Pass data as partialy named list 68 | 69 | mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, x=hdt$x)) 70 | 71 | } 72 | \references{ 73 | Kvedaras V., Zemlys, V. \emph{Testing the functional constraints on parameters in regressions with variables of different frequency} Economics Letters 116 (2012) 250-254 74 | } 75 | \author{ 76 | Virmantas Kvedaras, Vaidotas Zemlys 77 | } 78 | -------------------------------------------------------------------------------- /man/midasr-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{package} 4 | \name{midasr-package} 5 | \alias{midasr-package} 6 | \alias{midasr} 7 | \title{Mixed Data Sampling Regression} 8 | \description{ 9 | Package for estimating, testing and forecasting MIDAS regression. 10 | } 11 | \details{ 12 | Methods and tools for mixed frequency time series data analysis. Allows estimation, model selection and forecasting for MIDAS regressions. 13 | } 14 | \seealso{ 15 | Useful links: 16 | \itemize{ 17 | \item \url{http://mpiktas.github.io/midasr/} 18 | \item Report bugs at \url{https://github.com/mpiktas/midasr/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | Virmantas Kvedaras \email{virmantas.kvedaras@mif.vu.lt}, Vaidotas Zemlys (maintainer) \email{zemlys@gmail.com} 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/mls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midaslag.R 3 | \name{mls} 4 | \alias{mls} 5 | \title{MIDAS lag structure} 6 | \usage{ 7 | mls(x, k, m, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | 12 | \item{k}{a vector of lag orders, zero denotes contemporaneous lag.} 13 | 14 | \item{m}{frequency ratio} 15 | 16 | \item{...}{further arguments used in fitting MIDAS regression} 17 | } 18 | \value{ 19 | a matrix containing the lags 20 | } 21 | \description{ 22 | Create a matrix of selected MIDAS lags 23 | } 24 | \details{ 25 | The function checks whether high frequency data is complete, i.e. \code{m} must divide \code{length(x)}. 26 | } 27 | \examples{ 28 | ## Quarterly frequency data 29 | x <- 1:16 30 | ## Create MIDAS lag for use with yearly data 31 | mls(x,0:3,4) 32 | 33 | ## Do not use contemporaneous lag 34 | mls(x,1:3,4) 35 | 36 | ## Compares with embed when m=1 37 | embed(x,2) 38 | mls(x,0:1,1) 39 | } 40 | \author{ 41 | Virmantas Kvedaras, Vaidotas Zemlys 42 | } 43 | -------------------------------------------------------------------------------- /man/mlsd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midaslag.R 3 | \name{mlsd} 4 | \alias{mlsd} 5 | \title{MIDAS lag structure with dates} 6 | \usage{ 7 | mlsd(x, k, y, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a vector, of high frequency time series. Must be zoo or ts object} 11 | 12 | \item{k}{lags, a vector} 13 | 14 | \item{y}{a vector of low frequency time series. Must be zoo or ts object} 15 | 16 | \item{...}{further arguments used in fitting MIDAS regression} 17 | } 18 | \value{ 19 | a matrix containing the lags 20 | } 21 | \description{ 22 | MIDAS lag structure with dates 23 | } 24 | \details{ 25 | High frequency time series is aligned with low frequency time series using date information. 26 | Then the high frequency lags are calculated. 27 | 28 | To align the time series the low frequency series index 29 | needs to be extended by one low frequency period into the past and into the future. If supplied time series 30 | object does not support extending time index, a simple heuristic is used. 31 | 32 | It is expected that time index for zoo objects can be converted to POSIXct format. 33 | } 34 | \examples{ 35 | 36 | # Example with ts objects 37 | x <- ts(c(1:144), start = c(1980, 1), frequency = 12) 38 | y <- ts(c(1:12), start = 1980, frequency = 1) 39 | 40 | 41 | # msld and mls should give the same results 42 | 43 | m1 <- mlsd(x, 0:5, y) 44 | 45 | m2 <- mls(x, 0:5, 12) 46 | 47 | sum(abs(m1 - m2)) 48 | 49 | # Example with zooreg 50 | 51 | # Convert x to zooreg object using yearmon time index 52 | \dontrun{ 53 | xz <- zoo::as.zooreg(x) 54 | 55 | yz <- zoo::zoo(as.numeric(y), order.by = as.Date(paste0(1980 + 0:11, "-01-01"))) 56 | 57 | # Heuristic works here 58 | m3 <- mlsd(xz, 0:5, yz) 59 | 60 | sum(abs(m3 - m1)) 61 | } 62 | } 63 | \author{ 64 | Virmantas Kvedaras, Vaidotas Zemlys-Balevičius 65 | } 66 | -------------------------------------------------------------------------------- /man/mmm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr.R 3 | \name{mmm} 4 | \alias{mmm} 5 | \title{Compute MMM term for high frequency variable} 6 | \usage{ 7 | mmm(X, theta, beta, ...) 8 | } 9 | \arguments{ 10 | \item{X}{matrix, high frequency variable embedded in low frequency, output of mls} 11 | 12 | \item{theta}{vector, restriction coefficients for high frequency variable} 13 | 14 | \item{beta}{vector of length 2, parameters for MMM term, slope and MMM parameter.} 15 | 16 | \item{..., }{currently not used} 17 | } 18 | \value{ 19 | a vector 20 | } 21 | \description{ 22 | Compute MMM term for high frequency variable 23 | } 24 | -------------------------------------------------------------------------------- /man/modsel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{modsel} 4 | \alias{modsel} 5 | \title{Select the model based on given information criteria} 6 | \usage{ 7 | modsel( 8 | x, 9 | IC = x$IC[1], 10 | test = x$test[1], 11 | type = c("restricted", "unrestricted"), 12 | print = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{a \link{midas_r_ic_table} object} 17 | 18 | \item{IC}{the name of information criteria to base the choosing of the model} 19 | 20 | \item{test}{the name of the test for which to print out the p-value} 21 | 22 | \item{type}{the type of MIDAS model, either restricted or unrestricted} 23 | 24 | \item{print}{logical, if TRUE, prints the summary of the best model.} 25 | } 26 | \value{ 27 | (invisibly) the best model based on information criteria, \link{midas_r} object 28 | } 29 | \description{ 30 | Selects the model with minimum of given information criteria and model type 31 | } 32 | \details{ 33 | This function selects the model from the model selection table for which the chosen information criteria achieves the smallest value. The function works with model tables produced by functions \link{lf_lags_table}, \link{hf_lags_table}, \link{amidas_table} and \link{midas_r_ic_table}. 34 | } 35 | \examples{ 36 | 37 | data("USunempr") 38 | data("USrealgdp") 39 | y <- diff(log(USrealgdp)) 40 | x <- window(diff(USunempr),start=1949) 41 | trend <- 1:length(y) 42 | 43 | mhfr <- hf_lags_table(y~trend+fmls(x,12,12,nealmon), 44 | start=list(x=rep(0,3)), 45 | from=list(x=0),to=list(x=c(4,6))) 46 | 47 | mlfr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), 48 | start=list(x=rep(0,3)), 49 | from=list(x=0),to=list(x=c(2,3))) 50 | 51 | modsel(mhfr,"BIC","unrestricted") 52 | 53 | modsel(mlfr,"BIC","unrestricted") 54 | 55 | } 56 | \author{ 57 | Virmantas Kvedaras, Vaidotas Zemlys 58 | } 59 | -------------------------------------------------------------------------------- /man/nakagamip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nakagamip} 4 | \alias{nakagamip} 5 | \title{Normalized Nakagami probability density function MIDAS weights specification} 6 | \usage{ 7 | nakagamip(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized Nakagami probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate MIDAS weights according to normalized Nakagami probability density function specification 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/nakagamip_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nakagamip_gradient} 4 | \alias{nakagamip_gradient} 5 | \title{Gradient function for normalized Nakagami probability density function MIDAS weights specification} 6 | \usage{ 7 | nakagamip_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized Nakagami probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate gradient function for normalized Nakagami probability density function specification of MIDAS weights. 21 | } 22 | \author{ 23 | Julius Vainora 24 | } 25 | -------------------------------------------------------------------------------- /man/nbeta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nbeta} 4 | \alias{nbeta} 5 | \title{Normalized beta probability density function MIDAS weights specification} 6 | \usage{ 7 | nbeta(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized beta probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate MIDAS weights according to normalized beta probability density function specification 21 | } 22 | \author{ 23 | Virmantas Kvedaras, Vaidotas Zemlys 24 | } 25 | -------------------------------------------------------------------------------- /man/nbetaMT.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nbetaMT} 4 | \alias{nbetaMT} 5 | \title{Normalized beta probability density function MIDAS weights specification (MATLAB toolbox compatible)} 6 | \usage{ 7 | nbetaMT(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized beta probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate MIDAS weights according to normalized beta probability density function specification. 21 | Compatible with the specification in MATLAB toolbox. 22 | } 23 | \author{ 24 | Virmantas Kvedaras, Vaidotas Zemlys 25 | } 26 | -------------------------------------------------------------------------------- /man/nbetaMT_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nbetaMT_gradient} 4 | \alias{nbetaMT_gradient} 5 | \title{Gradient function for normalized beta probability density function MIDAS weights specification 6 | (MATLAB toolbox compatible)} 7 | \usage{ 8 | nbetaMT_gradient(p, d, m) 9 | } 10 | \arguments{ 11 | \item{p}{parameters for normalized beta probability density function} 12 | 13 | \item{d}{number of coefficients} 14 | 15 | \item{m}{the frequency ratio, currently ignored} 16 | } 17 | \value{ 18 | vector of coefficients 19 | } 20 | \description{ 21 | Calculate gradient function for normalized beta probability density function specification of MIDAS weights. 22 | } 23 | \author{ 24 | Virmantas Kvedaras, Vaidotas Zemlys 25 | } 26 | -------------------------------------------------------------------------------- /man/nbeta_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nbeta_gradient} 4 | \alias{nbeta_gradient} 5 | \title{Gradient function for normalized beta probability density function MIDAS weights specification} 6 | \usage{ 7 | nbeta_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for normalized beta probability density function} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate gradient function for normalized beta probability density function specification of MIDAS weights. 21 | } 22 | \author{ 23 | Virmantas Kvedaras, Vaidotas Zemlys 24 | } 25 | -------------------------------------------------------------------------------- /man/nealmon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nealmon} 4 | \alias{nealmon} 5 | \title{Normalized Exponential Almon lag MIDAS coefficients} 6 | \usage{ 7 | nealmon(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{parameters for Almon lag} 11 | 12 | \item{d}{number of the coefficients} 13 | 14 | \item{m}{the frequency, currently ignored.} 15 | } 16 | \value{ 17 | vector of coefficients 18 | } 19 | \description{ 20 | Calculate normalized exponential Almon lag coefficients given the parameters and required number of coefficients. 21 | } 22 | \details{ 23 | Given unrestricted MIDAS regression 24 | 25 | \deqn{y_t=\sum_{h=0}^d\theta_{h}x_{tm-h}+\mathbf{z_t}\beta+u_t} 26 | 27 | normalized exponential Almon lag restricts the coefficients \eqn{theta_h} in the following way: 28 | 29 | \deqn{\theta_{h}=\delta\frac{\exp(\lambda_1(h+1)+\dots+ 30 | \lambda_r(h+1)^r)}{\sum_{s=0}^d\exp(\lambda_1(s+1)+\dots+\lambda_r(h+1)^r)}} 31 | 32 | The parameter \eqn{\delta} should be the first element in vector \code{p}. The degree of 33 | the polynomial is then decided by the number of the remaining parameters. 34 | } 35 | \examples{ 36 | 37 | ##Load data 38 | data("USunempr") 39 | data("USrealgdp") 40 | 41 | y <- diff(log(USrealgdp)) 42 | x <- window(diff(USunempr),start=1949) 43 | t <- 1:length(y) 44 | 45 | midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0))) 46 | 47 | } 48 | \author{ 49 | Virmantas Kvedaras, Vaidotas Zemlys 50 | } 51 | -------------------------------------------------------------------------------- /man/nealmon_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{nealmon_gradient} 4 | \alias{nealmon_gradient} 5 | \title{Gradient function for normalized exponential Almon lag weights} 6 | \usage{ 7 | nealmon_gradient(p, d, m) 8 | } 9 | \arguments{ 10 | \item{p}{hyperparameters for Almon lag} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | } 16 | \value{ 17 | the gradient matrix 18 | } 19 | \description{ 20 | Gradient function for normalized exponential Almon lag weights 21 | } 22 | \author{ 23 | Vaidotas Zemlys 24 | } 25 | -------------------------------------------------------------------------------- /man/oos_prec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{oos_prec} 5 | \alias{oos_prec} 6 | \title{Out-of-sample prediction precision data on simulation example} 7 | \format{ 8 | A \code{data.frame} object with four columns. The first column indicates the sample size, the second the type of constraint, the third the value of the precision measure and the fourth the type of precision measure. 9 | } 10 | \description{ 11 | The code in the example generates the out-of-sample prediction precision data for correctly and incorrectly constrained MIDAS regression model compared to unconstrained MIDAS regression model. 12 | } 13 | \examples{ 14 | ## Do not run: 15 | ## set.seed(1001) 16 | 17 | ## gendata<-function(n) { 18 | ## trend<-c(1:n) 19 | ## z<-rnorm(12*n) 20 | ## fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) 21 | ## y<-2+0.1*trend+mls(z,0:16,12)\%*\%fn.z+rnorm(n) 22 | ## list(y=as.numeric(y),z=z,trend=trend) 23 | ## } 24 | 25 | ## nn <- c(50,100,200,300,500,750,1000) 26 | 27 | ## data_sets <- lapply(n,gendata) 28 | 29 | ## mse <- function(x) { 30 | ## mean(residuals(x)^2) 31 | ## } 32 | 33 | ## bnorm <- function(x) { 34 | ## sqrt(sum((coef(x, midas = TRUE)-c(2,0.1,nealmon(p=c(2,0.5,-0.1),d=17)))^2)) 35 | ## } 36 | 37 | ## rep1 <- function(n) { 38 | ## dt <- gendata(round(1.25*n)) 39 | ## ni <- n 40 | ## ind <- 1:ni 41 | ## mind <- 1:(ni*12) 42 | ## indt<-list(y=dt$y[ind],z=dt$z[mind],trend=dt$trend[ind]) 43 | ## outdt <- list(y=dt$y[-ind],z=dt$z[-mind],trend=dt$trend[-ind]) 44 | ## um <- midas_r(y~trend+mls(z,0:16,12),data=indt,start=NULL) 45 | ## nm <- midas_r(y~trend+mls(z,0:16,12,nealmon),data=indt,start=list(z=c(1,-1,0))) 46 | ## am <- midas_r(y~trend+mls(z,0:16,12,almonp),data=indt,start=list(z=c(1,0,0,0))) 47 | ## modl <- list(um,nm,am) 48 | ## names(modl) <- c("um","nm","am") 49 | ## list(norms=sapply(modl,bnorm), 50 | ## mse=sapply(modl,function(mod)mean((forecast(mod,newdata=outdt)-outdt$y)^2))) 51 | ## } 52 | 53 | ## repr <- function(n,R) { 54 | ## cc <- lapply(1:R,function(i)rep1(n)) 55 | ## list(norms=t(sapply(cc,"[[","norms")),mse=t(sapply(cc,"[[","mse"))) 56 | ## } 57 | 58 | ## res <- lapply(nn,repr,R=1000) 59 | 60 | ## norms <- data.frame(nn,t(sapply(lapply(res,"[[","norms"),function(l)apply(l,2,mean)))) 61 | ## mses <- data.frame(nn,t(sapply(lapply(res,"[[","mse"),function(l)apply(l,2,mean)))) 62 | 63 | 64 | ## msd <- melt(mses[-1,],id=1) 65 | ## colnames(msd)[2] <- "Constraint" 66 | ## nmd <- melt(norms[-1,],id=1) 67 | ## colnames(nmd)[2] <- "Constraint" 68 | 69 | ## msd$Type <- "Mean squared error" 70 | ## nmd$Type <- "Distance from true values" 71 | ## oos_prec <- rbind(msd,nmd) 72 | ## oos_prec$Type <- factor(oos_prec$Type,levels=c("Mean squared error","Distance from true values")) 73 | } 74 | \keyword{datasets} 75 | -------------------------------------------------------------------------------- /man/plot_lstr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{plot_lstr} 4 | \alias{plot_lstr} 5 | \title{Plot MIDAS coefficients} 6 | \usage{ 7 | plot_lstr(x, term_name, title = NULL, compare = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\code{midas_r} object} 11 | 12 | \item{term_name}{the term name for which the coefficients are plotted. Default is \code{NULL}, which selects the first MIDAS term} 13 | 14 | \item{title}{the title string of the graph. The default is \code{NULL} for the default title.} 15 | 16 | \item{compare}{the parameters for weight function to compare with the model, default is NULL} 17 | 18 | \item{...}{not used} 19 | } 20 | \value{ 21 | a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data 22 | frame is returned invisibly. 23 | } 24 | \description{ 25 | Plots logistic function for LSTR MIDAS regression 26 | } 27 | \details{ 28 | Plots logistic function for LSTR MIDSAS regression 29 | of unrestricted MIDAS regression 30 | } 31 | \author{ 32 | Virmantas Kvedaras, Vaidotas Zemlys 33 | } 34 | -------------------------------------------------------------------------------- /man/plot_midas_coef.midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{plot_midas_coef.midas_nlpr} 4 | \alias{plot_midas_coef.midas_nlpr} 5 | \title{Plot MIDAS coefficients} 6 | \usage{ 7 | \method{plot_midas_coef}{midas_nlpr}( 8 | x, 9 | term_name = NULL, 10 | title = NULL, 11 | compare = NULL, 12 | normalize = FALSE, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{\code{midas_r} object} 18 | 19 | \item{term_name}{the term name for which the coefficients are plotted. Default is \code{NULL}, which selects the first MIDAS term} 20 | 21 | \item{title}{the title string of the graph. The default is \code{NULL} for the default title.} 22 | 23 | \item{compare}{the parameters for weight function to compare with the model, default is NULL} 24 | 25 | \item{normalize}{logical, if FALSE use the weight from the model, if TRUE, set the normalization coefficient of the weight function to 1.} 26 | 27 | \item{...}{not used} 28 | } 29 | \value{ 30 | a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data 31 | frame is returned invisibly. 32 | } 33 | \description{ 34 | Plots MIDAS coefficients of a MIDAS regression for a selected term. 35 | } 36 | \details{ 37 | Plots MIDAS coefficients of a selected MIDAS regression term together with corresponding MIDAS coefficients and their confidence intervals 38 | of unrestricted MIDAS regression 39 | } 40 | \author{ 41 | Virmantas Kvedaras, Vaidotas Zemlys 42 | } 43 | -------------------------------------------------------------------------------- /man/plot_midas_coef.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{plot_midas_coef} 4 | \alias{plot_midas_coef} 5 | \alias{plot_midas_coef.midas_r} 6 | \title{Plot MIDAS coefficients} 7 | \usage{ 8 | plot_midas_coef(x, term_name, title, ...) 9 | 10 | \method{plot_midas_coef}{midas_r}( 11 | x, 12 | term_name = NULL, 13 | title = NULL, 14 | vcov. = sandwich, 15 | unrestricted = x$unrestricted, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{x}{\code{midas_r} object} 21 | 22 | \item{term_name}{the term name for which the coefficients are plotted. Default is \code{NULL}, which selects the first MIDAS term} 23 | 24 | \item{title}{the title string of the graph. The default is \code{NULL} for the default title.} 25 | 26 | \item{...}{additional arguments passed to \code{vcov.}} 27 | 28 | \item{vcov.}{the covariance matrix to calculate the standard deviation of the cofficients} 29 | 30 | \item{unrestricted}{the unrestricted model, the default is unrestricted model from the \code{x} object. Set NULL to plot only the weights.} 31 | } 32 | \value{ 33 | a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data 34 | frame is returned invisibly. 35 | } 36 | \description{ 37 | Plots MIDAS coefficients of a MIDAS regression for a selected term. 38 | } 39 | \details{ 40 | Plots MIDAS coefficients of a selected MIDAS regression term together with corresponding MIDAS coefficients and their confidence intervals 41 | of unrestricted MIDAS regression 42 | } 43 | \examples{ 44 | data("USrealgdp") 45 | data("USunempr") 46 | 47 | y <- diff(log(USrealgdp)) 48 | x <- window(diff(USunempr), start = 1949) 49 | trend <- 1:length(y) 50 | 51 | ##24 high frequency lags of x included 52 | mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) 53 | 54 | plot_midas_coef(mr) 55 | } 56 | \author{ 57 | Virmantas Kvedaras, Vaidotas Zemlys 58 | } 59 | -------------------------------------------------------------------------------- /man/plot_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp_methods.R 3 | \name{plot_sp} 4 | \alias{plot_sp} 5 | \title{Plot non-parametric part of the single index MIDAS regression} 6 | \usage{ 7 | plot_sp(x, term_name, title = NULL, compare = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\code{midas_r} object} 11 | 12 | \item{term_name}{the term name for which the coefficients are plotted. Default is \code{NULL}, which selects the first MIDAS term} 13 | 14 | \item{title}{the title string of the graph. The default is \code{NULL} for the default title.} 15 | 16 | \item{compare}{the parameters for weight function to compare with the model, default is NULL} 17 | 18 | \item{...}{not used} 19 | } 20 | \value{ 21 | a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data 22 | frame is returned invisibly. 23 | } 24 | \description{ 25 | Plot non-parametric part of the single index MIDAS regression 26 | of unrestricted MIDAS regression 27 | } 28 | \author{ 29 | Virmantas Kvedaras, Vaidotas Zemlys 30 | } 31 | -------------------------------------------------------------------------------- /man/polystep.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{polystep} 4 | \alias{polystep} 5 | \title{Step function specification for MIDAS weights} 6 | \usage{ 7 | polystep(p, d, m, a) 8 | } 9 | \arguments{ 10 | \item{p}{vector of parameters} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | 16 | \item{a}{vector of increasing positive integers indicating the steps} 17 | } 18 | \value{ 19 | vector of coefficients 20 | } 21 | \description{ 22 | Step function specification for MIDAS weights 23 | } 24 | \author{ 25 | Vaidotas Zemlys 26 | } 27 | -------------------------------------------------------------------------------- /man/polystep_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lagspec.R 3 | \name{polystep_gradient} 4 | \alias{polystep_gradient} 5 | \title{Gradient of step function specification for MIDAS weights} 6 | \usage{ 7 | polystep_gradient(p, d, m, a) 8 | } 9 | \arguments{ 10 | \item{p}{vector of parameters} 11 | 12 | \item{d}{number of coefficients} 13 | 14 | \item{m}{the frequency ratio, currently ignored} 15 | 16 | \item{a}{vector of increasing positive integers indicating the steps} 17 | } 18 | \value{ 19 | vector of coefficients 20 | } 21 | \description{ 22 | Gradient of step function specification for MIDAS weights 23 | } 24 | \author{ 25 | Vaidotas Zemlys 26 | } 27 | -------------------------------------------------------------------------------- /man/predict.midas_nlpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_nlpr_methods.R 3 | \name{predict.midas_nlpr} 4 | \alias{predict.midas_nlpr} 5 | \title{Predict method for non-linear parametric MIDAS regression fit} 6 | \usage{ 7 | \method{predict}{midas_nlpr}(object, newdata, na.action = na.omit, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{\link{midas_nlpr}} object} 11 | 12 | \item{newdata}{a named list containing data for mixed frequencies. If omitted, the in-sample values are used.} 13 | 14 | \item{na.action}{function determining what should be done with missing values in \code{newdata}. The most likely cause of missing values is the insufficient data for the lagged variables. The default is to omit such missing values.} 15 | 16 | \item{...}{additional arguments, not used} 17 | } 18 | \value{ 19 | a vector of predicted values 20 | } 21 | \description{ 22 | Predicted values based on \code{midas_nlpr} object. 23 | } 24 | \details{ 25 | \code{predict.midas_nlpr} produces predicted values, obtained by evaluating regression function in the frame \code{newdata}. This means that the appropriate model matrix is constructed using only the data in \code{newdata}. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function \link{forecast.midas_r}. Also this function produces only static predictions, if you want dynamic forecasts use the \link{forecast.midas_r}. 26 | } 27 | \author{ 28 | Virmantas Kvedaras, Vaidotas Zemlys 29 | } 30 | -------------------------------------------------------------------------------- /man/predict.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_r_methods.R 3 | \name{predict.midas_r} 4 | \alias{predict.midas_r} 5 | \title{Predict method for MIDAS regression fit} 6 | \usage{ 7 | \method{predict}{midas_r}(object, newdata, na.action = na.omit, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{\link{midas_r}} object} 11 | 12 | \item{newdata}{a named list containing data for mixed frequencies. If omitted, the in-sample values are used.} 13 | 14 | \item{na.action}{function determining what should be done with missing values in \code{newdata}. The most likely cause of missing values is the insufficient data for the lagged variables. The default is to omit such missing values.} 15 | 16 | \item{...}{additional arguments, not used} 17 | } 18 | \value{ 19 | a vector of predicted values 20 | } 21 | \description{ 22 | Predicted values based on \code{midas_r} object. 23 | } 24 | \details{ 25 | \code{predict.midas_r} produces predicted values, obtained by evaluating regression function in the frame \code{newdata}. This means that the appropriate model matrix is constructed using only the data in \code{newdata}. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function \link{forecast.midas_r}. Also this function produces only static predictions, if you want dynamic forecasts use the \link{forecast.midas_r}. 26 | } 27 | \examples{ 28 | data("USrealgdp") 29 | data("USunempr") 30 | 31 | y <- diff(log(USrealgdp)) 32 | x <- window(diff(USunempr), start = 1949) 33 | 34 | ##24 high frequency lags of x included 35 | mr <- midas_r(y ~ fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) 36 | 37 | ##Declining unemployment 38 | xn <- rnorm(2 * 12, -0.1, 0.1) 39 | 40 | ##Only one predicted value, historical values discarded 41 | predict(mr, list(x = xn)) 42 | 43 | ##Historical values taken into account 44 | forecast(mr, list(x = xn)) 45 | } 46 | \author{ 47 | Virmantas Kvedaras, Vaidotas Zemlys 48 | } 49 | -------------------------------------------------------------------------------- /man/predict.midas_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midas_sp_methods.R 3 | \name{predict.midas_sp} 4 | \alias{predict.midas_sp} 5 | \title{Predict method for semi-parametric MIDAS regression fit} 6 | \usage{ 7 | \method{predict}{midas_sp}(object, newdata, na.action = na.omit, ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{\link{midas_nlpr}} object} 11 | 12 | \item{newdata}{a named list containing data for mixed frequencies. If omitted, the in-sample values are used.} 13 | 14 | \item{na.action}{function determining what should be done with missing values in \code{newdata}. The most likely cause of missing values is the insufficient data for the lagged variables. The default is to omit such missing values.} 15 | 16 | \item{...}{additional arguments, not used} 17 | } 18 | \value{ 19 | a vector of predicted values 20 | } 21 | \description{ 22 | Predicted values based on \code{midas_sp} object. 23 | } 24 | \details{ 25 | \code{predict.midas_sp} produces predicted values, obtained by evaluating regression function in the frame \code{newdata}. This means that the appropriate model matrix is constructed using only the data in \code{newdata}. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function \link{forecast.midas_r}. Also this function produces only static predictions, if you want dynamic forecasts use the \link{forecast.midas_r}. 26 | } 27 | \author{ 28 | Virmantas Kvedaras, Vaidotas Zemlys-Balevičius 29 | } 30 | -------------------------------------------------------------------------------- /man/prep_hAh.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tests.R 3 | \name{prep_hAh} 4 | \alias{prep_hAh} 5 | \title{Calculate data for \link{hAh_test} and \link{hAhr_test}} 6 | \usage{ 7 | prep_hAh(x) 8 | } 9 | \arguments{ 10 | \item{x}{\code{midas_r} object} 11 | } 12 | \value{ 13 | a list with necessary matrices 14 | } 15 | \description{ 16 | Workhorse function for calculating necessary matrices for \link{hAh_test} and \link{hAhr_test}. Takes the same parameters as \link{hAh_test} 17 | } 18 | \seealso{ 19 | hAh_test, hAhr_test 20 | } 21 | \author{ 22 | Virmantas Kvedaras, Vaidotas Zemlys 23 | } 24 | -------------------------------------------------------------------------------- /man/rvsp500.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasr-package.R 3 | \docType{data} 4 | \name{rvsp500} 5 | \alias{rvsp500} 6 | \title{Realized volatility of S&P500 index} 7 | \format{ 8 | A \code{data.frame} object with two columns. First column contains date id, and the second the realized volatility for S&P500 index. 9 | } 10 | \source{ 11 | No longer available. Read the statement here: \href{https://oxford-man.ox.ac.uk/research/realized-library/}{https://oxford-man.ox.ac.uk/research/realized-library/} 12 | } 13 | \description{ 14 | Realized volatility of S&P500(Live) index of the period 2000 01 03 - 2013 11 22 15 | } 16 | \examples{ 17 | ## Do not run: 18 | ## The original data contained the file OxfordManRealizedVolatilityIndices.csv. 19 | ## The code below reproduces the dataset. 20 | 21 | ## rvi <- read.csv("OxfordManRealizedVolatilityIndices.csv",check.names=FALSE,skip=2) 22 | ## ii <- which(rvi$DateID=="20131112") 23 | ## rvsp500 <- na.omit(rvi[1:ii,c("DataID","SPX2.rv")] 24 | } 25 | \references{ 26 | Heber, Gerd and Lunde, Asger, and Shephard, Neil and Sheppard, Kevin \emph{Oxford-Man Institute's realized library}, Oxford-Man Institute, University of Oxford (2009) 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/select_and_forecast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{select_and_forecast} 4 | \alias{select_and_forecast} 5 | \title{Create table for different forecast horizons} 6 | \usage{ 7 | select_and_forecast( 8 | formula, 9 | data, 10 | from, 11 | to, 12 | insample, 13 | outsample, 14 | weights, 15 | wstart, 16 | start = NULL, 17 | IC = "AIC", 18 | seltype = c("restricted", "unrestricted"), 19 | test = "hAh_test", 20 | ftype = c("fixed", "recursive", "rolling"), 21 | measures = c("MSE", "MAPE", "MASE"), 22 | fweights = c("EW", "BICW", "MSFE", "DMSFE"), 23 | ... 24 | ) 25 | } 26 | \arguments{ 27 | \item{formula}{initial formula for the} 28 | 29 | \item{data}{list of data} 30 | 31 | \item{from}{a named list of starts of lags from where to fit. Denotes the horizon} 32 | 33 | \item{to}{a named list for lag selections} 34 | 35 | \item{insample}{the low frequency indexes for in-sample data} 36 | 37 | \item{outsample}{the low frequency indexes for out-of-sample data} 38 | 39 | \item{weights}{names of weight function candidates} 40 | 41 | \item{wstart}{starting values for weight functions} 42 | 43 | \item{start}{other starting values} 44 | 45 | \item{IC}{name of information criteria to choose model from} 46 | 47 | \item{seltype}{argument to modsel, \code{"restricted"} for model selection based on information criteria of restricted MIDAS model, \code{"unrestricted"} for model selection based on unrestricted (U-MIDAS) model.} 48 | 49 | \item{test}{argument to modsel} 50 | 51 | \item{ftype}{which type of forecast to use.} 52 | 53 | \item{measures}{the names of goodness of fit measures} 54 | 55 | \item{fweights}{names of weighting schemes} 56 | 57 | \item{...}{additional arguments for optimisation method, see \link{midas_r}} 58 | } 59 | \value{ 60 | a list containing forecasts, tables of accuracy measures and the list with selected models 61 | } 62 | \description{ 63 | Creates tables for different forecast horizons and table for combined forecasts 64 | } 65 | \details{ 66 | Divide data into in-sample and out-of-sample. Fit different forecasting horizons for in-sample data. Calculate accuracy measures for individual and average forecasts. 67 | } 68 | \examples{ 69 | ### Sets a seed for RNG ### 70 | set.seed(1001) 71 | ## Number of low-frequency observations 72 | n<-250 73 | ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) 74 | trend<-c(1:n) 75 | x<-rnorm(4*n) 76 | z<-rnorm(12*n) 77 | ## Exponential Almon polynomial constraint-consistent coefficients 78 | fn.x <- nealmon(p=c(1,-0.5),d=8) 79 | fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) 80 | ## Simulated low-frequency series (e.g. yearly) 81 | y<-2+0.1*trend+mls(x,0:7,4)\%*\%fn.x+mls(z,0:16,12)\%*\%fn.z+rnorm(n) 82 | ##Do not run 83 | ## cbfc<-select_and_forecast(y~trend+mls(x,0,4)+mls(z,0,12), 84 | ## from=list(x=c(4,8,12),z=c(12,24,36)), 85 | ## to=list(x=rbind(c(14,19),c(18,23),c(22,27)),z=rbind(c(22,27),c(34,39),c(46,51))), 86 | ## insample=1:200,outsample=201:250, 87 | ## weights=list(x=c("nealmon","almonp"),z=c("nealmon","almonp")), 88 | ## wstart=list(nealmon=rep(1,3),almonp=rep(1,3)), 89 | ## IC="AIC", 90 | ## seltype="restricted", 91 | ## ftype="fixed", 92 | ## measures=c("MSE","MAPE","MASE"), 93 | ## fweights=c("EW","BICW","MSFE","DMSFE") 94 | ## ) 95 | 96 | } 97 | \author{ 98 | Virmantas Kvedaras, Vaidotas Zemlys 99 | } 100 | -------------------------------------------------------------------------------- /man/simulate.midas_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulate.R 3 | \name{simulate.midas_r} 4 | \alias{simulate.midas_r} 5 | \alias{simulate} 6 | \title{Simulate MIDAS regression response} 7 | \usage{ 8 | \method{simulate}{midas_r}( 9 | object, 10 | nsim = 999, 11 | seed = NULL, 12 | future = TRUE, 13 | newdata = NULL, 14 | insample = NULL, 15 | method = c("static", "dynamic"), 16 | innov = NULL, 17 | show_progress = TRUE, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{object}{\code{\link{midas_r}} object} 23 | 24 | \item{nsim}{number of simulations} 25 | 26 | \item{seed}{either NULL or an integer that will be used in a call to set.seed before simulating the time series. The default, NULL will not change the random generator state.} 27 | 28 | \item{future}{logical, if \code{TRUE} forecasts are simulated, if \code{FALSE} in-sample simulation is performed.} 29 | 30 | \item{newdata}{a named list containing future values of mixed frequency regressors. The default is \code{NULL}, meaning that only in-sample data is used.} 31 | 32 | \item{insample}{a list containing the historic mixed frequency data} 33 | 34 | \item{method}{the simulation method, if \code{"static"} in-sample values for dependent variable are used in autoregressive MIDAS model, if \code{"dynamic"} 35 | the dependent variable values are calculated step-by-step from the initial in-sample values.} 36 | 37 | \item{innov}{a matrix containing the simulated innovations. The default is \code{NULL}, meaning, that innovations are simulated from model residuals.} 38 | 39 | \item{show_progress}{logical, TRUE to show progress bar, FALSE for silent evaluation} 40 | 41 | \item{...}{not used currently} 42 | } 43 | \value{ 44 | a matrix of simulated responses. Each row contains a simulated response. 45 | } 46 | \description{ 47 | Simulates one or more responses from the distribution corresponding to a fitted MIDAS regression object. 48 | } 49 | \details{ 50 | Only the regression innovations are simulated, it is assumed that the predictor variables and coefficients are fixed. The 51 | innovation distribution is simulated via bootstrap. 52 | } 53 | \examples{ 54 | data("USrealgdp") 55 | data("USunempr") 56 | 57 | y <- diff(log(USrealgdp)) 58 | x <- window(diff(USunempr), start = 1949) 59 | trend <- 1:length(y) 60 | 61 | ##24 high frequency lags of x included 62 | mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) 63 | 64 | simulate(mr, nsim=10, future=FALSE) 65 | 66 | ##Forecast horizon 67 | h <- 3 68 | ##Declining unemployment 69 | xn <- rep(-0.1, 12*3) 70 | ##New trend values 71 | trendn <- length(y) + 1:h 72 | 73 | simulate(mr, nsim = 10, future = TRUE, newdata = list(trend = trendn, x = xn)) 74 | } 75 | \author{ 76 | Virmantas Kvedaras, Vaidotas Zemlys 77 | } 78 | -------------------------------------------------------------------------------- /man/split_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{split_data} 4 | \alias{split_data} 5 | \title{Split mixed frequency data into in-sample and out-of-sample} 6 | \usage{ 7 | split_data(data, insample, outsample) 8 | } 9 | \arguments{ 10 | \item{data}{a list containing mixed frequency data} 11 | 12 | \item{insample}{the low frequency indexes for in-sample data} 13 | 14 | \item{outsample}{the low frequency indexes for out-of-sample data} 15 | } 16 | \value{ 17 | a list with elements \code{indata} and \code{outdata} containing respectively in-sample and out-of-sample data sets 18 | } 19 | \description{ 20 | Splits mixed frequency data into in-sample and out-of-sample datasets given the indexes of the low frequency data 21 | } 22 | \details{ 23 | It is assumed that data is a list containing mixed frequency data. Then given the indexes of the low frequency data the function splits the data into two subsets. 24 | } 25 | \examples{ 26 | 27 | #Monthly data 28 | x <- 1:24 29 | #Quartely data 30 | z <- 1:8 31 | #Yearly data 32 | y <- 1:2 33 | split_data(list(y=y,x=x,z=z),insample=1,outsample=2) 34 | } 35 | \author{ 36 | Virmantas Kvedaras, Vaidotas Zemlys 37 | } 38 | -------------------------------------------------------------------------------- /man/update_weights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/midasreg.R 3 | \name{update_weights} 4 | \alias{update_weights} 5 | \title{Updates weights in MIDAS regression formula} 6 | \usage{ 7 | update_weights(expr, tb) 8 | } 9 | \arguments{ 10 | \item{expr}{expression with MIDAS term} 11 | 12 | \item{tb}{a named list with redefined weights} 13 | } 14 | \value{ 15 | an expression with changed weights 16 | } 17 | \description{ 18 | Updates weights in a expression with MIDAS term 19 | } 20 | \details{ 21 | For a MIDAS term \code{fmls(x, 6, 1, nealmon)} change weight \code{nealmon} to another weight. 22 | } 23 | \examples{ 24 | 25 | update_weights(y~trend+mls(x,0:7,4,nealmon)+mls(z,0:16,12,nealmon),list(x = "nbeta", z = "")) 26 | 27 | } 28 | \author{ 29 | Vaidotas Zemlys 30 | } 31 | -------------------------------------------------------------------------------- /man/weights_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modsel.R 3 | \name{weights_table} 4 | \alias{weights_table} 5 | \title{Create a weight function selection table for MIDAS regression model} 6 | \usage{ 7 | weights_table( 8 | formula, 9 | data, 10 | start = NULL, 11 | IC = c("AIC", "BIC"), 12 | test = c("hAh_test"), 13 | Ofunction = "optim", 14 | weight_gradients = NULL, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{formula}{the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula} 20 | 21 | \item{data}{a list containing data with mixed frequencies} 22 | 23 | \item{start}{the starting values for optimisation} 24 | 25 | \item{IC}{the information criteria which to compute} 26 | 27 | \item{test}{the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table} 28 | 29 | \item{Ofunction}{see \link{midasr}} 30 | 31 | \item{weight_gradients}{see \link{midas_r}} 32 | 33 | \item{...}{additional parameters to optimisation function, see \link{midas_r}} 34 | } 35 | \value{ 36 | a \code{midas_r_ic_table} object which is the list with the following elements: 37 | 38 | \item{table}{the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure} 39 | \item{candlist}{the list containing fitted models} 40 | \item{IC}{the argument IC} 41 | } 42 | \description{ 43 | Creates a weight function selection table for MIDAS regression model with given information criteria and weight functions. 44 | } 45 | \details{ 46 | This function estimates models sequentially increasing the midas lag from \code{kmin} to \code{kmax} of the last term of the given formula 47 | } 48 | \examples{ 49 | 50 | data("USunempr") 51 | data("USrealgdp") 52 | y <- diff(log(USrealgdp)) 53 | x <- window(diff(USunempr),start=1949) 54 | trend <- 1:length(y) 55 | mwr <- weights_table(y~trend+fmls(x,12,12,nealmon), 56 | start=list(x=list(nealmon=rep(0,3), 57 | nbeta=c(1,1,1,0)))) 58 | 59 | mwr 60 | 61 | } 62 | \author{ 63 | Virmantas Kvedaras, Vaidotas Zemlys 64 | } 65 | -------------------------------------------------------------------------------- /midasr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: a139e048-ad25-4c89-bc05-b0a86b510daa 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 4 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(midasr) 3 | 4 | test_check("midasr") 5 | -------------------------------------------------------------------------------- /tests/testthat/test_methods.R: -------------------------------------------------------------------------------- 1 | context("Testing midas_r methods") 2 | set.seed(1001) 3 | n <- 250 4 | trend <- c(1:n) 5 | x <- rnorm(4 * n) 6 | z <- rnorm(12 * n) 7 | fn_x <- nealmon(p = c(1, -0.5), d = 8) 8 | fn_z <- nealmon(p = c(2, 0.5, -0.1), d = 17) 9 | y <- 2 + 0.1 * trend + mls(x, 0:7, 4) %*% fn_x + mls(z, 0:16, 12) %*% fn_z + rnorm(n) 10 | 11 | 12 | spd <- split_data(list(y = y, x = x, trend = trend, z = z), 1:200, 201:250) 13 | 14 | accuracy <- sqrt(.Machine$double.eps) 15 | 16 | ## Add test for preserving zoo and other attributes. 17 | ## Add test for printing out the estimation sample start and end. 18 | 19 | 20 | test_that("midas_r preserves ts attribute", { 21 | spd$indata$y <- ts(spd$indata$y, start = 1, frequency = 1) 22 | a <- midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1)), data = spd$indata) 23 | fa <- forecast(a, newdata = spd$outdata) 24 | expect_true(inherits(fa$mean, "ts")) 25 | expect_true(identical(time(fa$mean), time(ts(201:250, start = 201)))) 26 | 27 | spd$indata$y <- ts(spd$indata$y, start = 1950, frequency = 4) 28 | a <- midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1)), data = spd$indata) 29 | fa <- forecast(a, newdata = spd$outdata) 30 | expect_true(inherits(fa$mean, "ts")) 31 | expect_true(identical(time(fa$mean), time(ts(201:250, start = c(2000, 1), frequency = 4)))) 32 | 33 | spd$indata$y <- ts(spd$indata$y, start = 1990, frequency = 12) 34 | a <- midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1)), data = spd$indata) 35 | fa <- forecast(a, newdata = spd$outdata) 36 | expect_true(inherits(fa$mean, "ts")) 37 | expect_lt(sum(abs(time(fa$mean) - time(ts(201:250, start = c(2006, 9), frequency = 12)))), accuracy) 38 | }) 39 | 40 | test_that("midas_u preserves ts attribute", { 41 | spd$indata$y <- ts(spd$indata$y, start = 1, frequency = 1) 42 | a <- midas_u(y ~ trend + mls(x, 0:7, 4) + mls(z, 0:16, 12), data = spd$indata) 43 | fa <- forecast(a, newdata = spd$outdata) 44 | expect_true(inherits(fa$mean, "ts")) 45 | expect_true(identical(time(fa$mean), time(ts(201:250, start = 201)))) 46 | 47 | spd$indata$y <- ts(spd$indata$y, start = 1950, frequency = 4) 48 | a <- midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1)), data = spd$indata) 49 | fa <- forecast(a, newdata = spd$outdata) 50 | expect_true(inherits(fa$mean, "ts")) 51 | expect_true(identical(time(fa$mean), time(ts(201:250, start = c(2000, 1), frequency = 4)))) 52 | 53 | spd$indata$y <- ts(spd$indata$y, start = 1990, frequency = 12) 54 | a <- midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1)), data = spd$indata) 55 | fa <- forecast(a, newdata = spd$outdata) 56 | expect_true(inherits(fa$mean, "ts")) 57 | expect_lt(sum(abs(time(fa$mean) - time(ts(201:250, start = c(2006, 9), frequency = 12)))), accuracy) 58 | }) 59 | 60 | 61 | test_that("forecast for midas_r and midas_u is the same", { 62 | a <- midas_r(y ~ trend + mls(x, 0:7, 4) + mls(z, 0:16, 12), start = NULL, data = spd$indata) 63 | b <- midas_u(y ~ trend + mls(x, 0:7, 4) + mls(z, 0:16, 12), start = NULL, data = spd$indata) 64 | fa <- forecast(a, newdata = spd$outdata) 65 | fb <- forecast(b, newdata = spd$outdata) 66 | expect_lt(sum(abs(fa$mean - fb$mean)), accuracy) 67 | }) 68 | -------------------------------------------------------------------------------- /tests/testthat/test_midas_sp.R: -------------------------------------------------------------------------------- 1 | set.seed(131313) 2 | 3 | # Generate the data sets for use in tests 4 | # 5 | n <- 250 6 | nnbeta <- function(p, k) nbeta(c(1, p), k) 7 | dgp_pl <- midas_pl_sim(n, m = 12, theta = nbeta(c(1.5, 2, 4), 24), gfun = function(x) 0.25 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100) 8 | dgp_si <- midas_si_sim(n, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.03 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100) 9 | 10 | a100 <- midas_sp(y ~ mlsd(x, 0:23, y, nbeta) + mlsd(y, 1:2, y) | z, 11 | bws = 1, degree = 1, data = dgp_pl, 12 | start = list(x = c(1.5, 2, 4), y = c(0.5, 0)), 13 | method = "Nelder-Mead", control = list(maxit = 100) 14 | ) 15 | 16 | b100 <- midas_sp(y ~ mlsd(y, 1:2, y) | mlsd(x, 0:23, y, nnbeta), 17 | bws = 1, degree = 1, data = dgp_si, 18 | start = list(x = c(2, 4), y = c(0.5, 0)), 19 | method = "Nelder-Mead", control = list(maxit = 100) 20 | ) 21 | accuracy <- sqrt(.Machine$double.eps) 22 | 23 | test_that("Plain and formula interface give the same results for PL", { 24 | skip_on_cran() 25 | X <- mls(dgp_pl$x, 0:23, 12) 26 | 27 | mpl <- midas_pl_plain(dgp_pl$y, X, dgp_pl$z, 28 | p.ar = 2L, nbeta, degree = 1, 29 | start_bws = 1, start_x = c(1.5, 2, 4), start_ar = c(0.5, 0), 30 | method = "Nelder-Mead", control = list(maxit = 100) 31 | ) 32 | 33 | mfr <- a100 34 | 35 | fmpl <- fitted(mpl) 36 | fmfr <- fitted(mfr) 37 | 38 | expect_true((sum(abs(mfr$coefficients - mpl$coefficients)) < accuracy) & (sum(abs(fmpl - fmfr)) < accuracy)) 39 | }) 40 | 41 | test_that("Plain and formula interface give the same results for SI", { 42 | skip_on_cran() 43 | X <- mls(dgp_si$x, 0:23, 12) 44 | 45 | mpl <- midas_si_plain(dgp_si$y, X, 46 | p.ar = 2L, nnbeta, degree = 1, start_bws = 1, start_x = c(2, 4), start_ar = c(0.5, 0), 47 | method = "Nelder-Mead", control = list(maxit = 100) 48 | ) 49 | 50 | mfr <- midas_sp(y ~ mlsd(y, 1:2, y) | mlsd(x, 0:23, y, nnbeta), 51 | bws = 1, degree = 1, data = dgp_si, 52 | start = list(x = c(2, 4), y = c(0.5, 0)), 53 | method = "Nelder-Mead", control = list(maxit = 100) 54 | ) 55 | 56 | cmap <- c(1, 4:5, 2:3) 57 | 58 | fmpl <- fitted(mpl) 59 | fmfr <- fitted(mfr) 60 | 61 | expect_true((sum(abs(mfr$coefficients[cmap] - mpl$coefficients)) < accuracy) & (sum(abs(fmpl - fmfr)) < accuracy)) 62 | }) 63 | 64 | 65 | test_that("Rearanging terms works", { 66 | skip_on_cran() 67 | mfr1 <- a100 68 | mfr2 <- midas_sp(y ~ mlsd(y, 1:2, y) + mlsd(x, 0:23, y, nbeta) | z, 69 | bws = 1, degree = 1, data = dgp_pl, 70 | start = list(x = c(1.5, 2, 4), y = c(0.5, 0)), 71 | method = "Nelder-Mead", control = list(maxit = 100) 72 | ) 73 | 74 | cmap <- c(1, 5:6, 2:4) 75 | 76 | 77 | expect_true(sum(abs(mfr1$coefficients[cmap] - mfr2$coefficients)) < accuracy) 78 | }) 79 | 80 | test_that("Updating Ofunction works for sp", { 81 | skip_on_cran() 82 | a <- a100 83 | b <- update(a, Ofunction = "nls") 84 | c <- suppressWarnings(update(b, Ofunction = "optimx", method = c("BFGS", "spg"), itnmax = 10)) 85 | 86 | expect_true(a$argmap_opt$Ofunction == "optim") 87 | expect_true(b$argmap_opt$Ofunction == "nls") 88 | expect_true(c$argmap_opt$Ofunction == "optimx") 89 | 90 | expect_true(inherits(b$opt, "nls")) 91 | expect_true(inherits(c$opt, "optimx")) 92 | 93 | expect_true(sum(abs(coef(a) - b$start_opt)) == 0) 94 | expect_true(sum(abs(coef(b) - c$start_opt)) == 0) 95 | }) 96 | 97 | test_that("Updating Ofunction arguments works", { 98 | skip_on_cran() 99 | a <- a100 100 | b <- update(a, method = "CG", control = list(maxit = 5)) 101 | 102 | expect_true(b$argmap_opt$method == "CG") 103 | }) 104 | 105 | test_that("Updating data and starting values works", { 106 | skip_on_cran() 107 | spd <- dgp_si[c("y", "x")] 108 | spd$y <- window(spd$y, start = 1, end = 200) 109 | spd$x <- window(spd$x, start = c(1, 1), end = c(200, 12)) 110 | 111 | a <- b100 112 | 113 | b <- update(a, data = spd, start = list(x = c(2, 4), y = c(0.5, 0)), control = list(maxit = 1), method = "Nelder-Mead") 114 | 115 | m <- na.omit(cbind(spd$y, mlsd(spd$y, 1:2, spd$y), mlsd(spd$x, 0:23, spd$y))) 116 | 117 | expect_lt(sum(abs(m - b$model)), accuracy) 118 | }) 119 | 120 | test_that("Predicting works for PL", { 121 | skip_on_cran() 122 | r <- predict(a100, newdata = dgp_pl) - fitted(a100) 123 | expect_equivalent(sum(abs(r)), 0) 124 | }) 125 | 126 | 127 | 128 | test_that("Predicting works for SI", { 129 | skip_on_cran() 130 | r <- predict(b100, newdata = dgp_si) - fitted(b100) 131 | expect_that(sum(abs(r)), equals(0)) 132 | }) 133 | 134 | 135 | test_that("Predicting works for pure SI model", { 136 | skip_on_cran() 137 | bb <- midas_sp(y ~ mlsd(x, 0:23, y, nnbeta), 138 | bws = 1, degree = 1, data = dgp_si, 139 | start = list(x = c(2, 4)), 140 | method = "Nelder-Mead", control = list(maxit = 100) 141 | ) 142 | r <- predict(bb, newdata = dgp_si) - fitted(bb) 143 | expect_that(sum(abs(r)), equals(0)) 144 | }) 145 | 146 | 147 | test_that("g_np and g_np_mv works the same for numeric and for matrices in case of a vector", { 148 | skip_on_cran() 149 | oo <- midasr:::midas_sp_fit(a100) 150 | 151 | rn <- g_np(as.numeric(oo$y - oo$xi), as.numeric(oo$z), as.numeric(oo$z), coef(a100)[1], a100$degree) 152 | rm <- g_np_mv(oo$y - oo$xi, oo$z, oo$z, coef(a100)[1], a100$degree) 153 | expect_that(sum(abs(rn - rm)), equals(0)) 154 | }) 155 | 156 | 157 | test_that("cv_np works the same for numeric and for matrices in case of a vector", { 158 | oo <- midasr:::midas_sp_fit(a100) 159 | 160 | rn <- cv_np(as.numeric(oo$y - oo$xi), as.numeric(oo$z), coef(a100)[1], a100$degree) 161 | rm <- cv_np(oo$y - oo$xi, oo$z, coef(a100)[1], a100$degree) 162 | expect_that(sum(abs(rn - rm)), equals(0)) 163 | }) 164 | -------------------------------------------------------------------------------- /tests/testthat/test_midaslag.R: -------------------------------------------------------------------------------- 1 | context("Testing mls") 2 | accuracy <- sqrt(.Machine$double.eps) 3 | 4 | test_that("Embedding to low frequency works as expected", { 5 | x <- 1:24 6 | x1 <- matrix(2 * (1:12), ncol = 1) 7 | x2 <- cbind(2 * (1:12), 2 * (1:12) - 1) 8 | x3 <- rbind(c(NA, NA, NA), cbind(2 * (2:12), 2 * (2:12) - 1, 2 * (2:12) - 2)) 9 | x4 <- rbind(c(NA, NA), embed(x, 2)) 10 | expect_equivalent(fmls(x, 0, 2), x1) 11 | expect_equivalent(fmls(x, 1, 2), x2) 12 | expect_equivalent(fmls(x, 2, 2), x3) 13 | expect_equivalent(fmls(x, 1, 1), x4) 14 | }) 15 | 16 | test_that("mls and fmls give the same results", { 17 | set.seed(123) 18 | e <- rnorm(100) 19 | a <- mls(e, 0:10, 10) 20 | b <- fmls(e, 10, 10) 21 | expect_lt(sum(abs(a - b), na.rm = TRUE), accuracy) 22 | }) 23 | 24 | test_that("fmls and dmls give the same results", { 25 | set.seed(123) 26 | e <- rnorm(100) 27 | a <- fmls(c(NA, diff(e)), 10, 10) 28 | b <- dmls(e, 10, 10) 29 | expect_lt(sum(abs(a - b), na.rm = TRUE), accuracy) 30 | }) 31 | 32 | test_that("mlsd works for the ts objects", { 33 | x <- ts(c(1:144), frequency = 12) 34 | y <- ts(c(1:48), frequency = 4) 35 | 36 | m1 <- mlsd(x, 0:7, y) 37 | m2 <- mls(x, 0:7, 3) 38 | 39 | expect_true(sum(abs(m1 - m2), na.rm = TRUE) < accuracy) 40 | }) 41 | 42 | data(USunempr) 43 | data(USrealgdp) 44 | yy <- diff(log(USrealgdp)) 45 | xx <- diff(USunempr) 46 | 47 | test_that("mlsd returns the matrix of apropriate dimensions", { 48 | zz <- mlsd(xx, 0:24, yy) 49 | expect_true(nrow(zz) == length(yy)) 50 | }) 51 | 52 | test_that("Windowing works with mlsd from the right", { 53 | yy1 <- window(yy, end = 1980) 54 | zz <- mlsd(xx, 0:24, yy1) 55 | xx1 <- window(xx, end = c(1980, 12)) 56 | expect_true(zz[nrow(zz), 1] == xx1[length(xx1)]) 57 | }) 58 | 59 | test_that("Windowing works with mlsd from the left", { 60 | yy1 <- window(yy, start = 1955, end = 1980) 61 | zz <- mlsd(xx, 0:24, yy1) 62 | xx1 <- window(xx, end = c(1980, 12)) 63 | expect_true(zz[nrow(zz), 1] == xx1[length(xx1)]) 64 | }) 65 | --------------------------------------------------------------------------------