You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R语言fable库拟合VARIMA模型仅得到NULL模型,求解决办法

问题

尝试使用R语言的fable库拟合VARIMA模型,但运行后仅生成NULL_Models。使用vignette中的示例代码如下:

library(fable)
library(tsibbledata)

aus_production %>% autoplot(vars(Beer, Cement))
fit <- aus_production %>% model(VARIMA(vars(Beer, Cement) ~ pdq(4, 1, 1), identification = "none"))
fit

运行结果:autoplot输出了预期图表,证明数据已成功加载,但最后一行返回NULL模型:

> fit
# A mable: 1 x 1
  `VARIMA(vars(Beer, Cement) ~ pdq(4, 1, 1), identification = "none")`
                                                               <model>
1                                                         <NULL model>

已知该问题与类似问题(fable::ARIMA produces only NULL model)相关,但安装urca包的解决方案未生效,询问是否还有缺失的依赖包。

R环境信息:

> sessionInfo()
R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=German_Austria.utf8  LC_CTYPE=German_Austria.utf8    LC_MONETARY=German_Austria.utf8
[4] LC_NUMERIC=C                    LC_TIME=German_Austria.utf8    

time zone: Europe/Vienna
tzcode source: internal

attached base packages:
[1] splines   tools     stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] feasts_0.4.1           tsibbledata_0.4.1      fpp3_1.0.1             tsibble_1.1.6          fable_0.4.1           
 [6] fabletools_0.5.0       fredr_2.1.0            vars_1.6-1             lmtest_0.9-40          urca_1.3-4            
[11] strucchange_1.5-4      sandwich_3.1-1         zoo_1.8-14             MASS_7.3-65            ggpp_0.5.8-1          
[16] timeplyr_1.1.0         forecast_8.24.0        ggpubr_0.6.0           plotly_4.11.0          ecb_0.4.3              
[21] directlabels_2025.5.20 patchwork_1.3.0        kableExtra_1.4.0       lubridate_1.9.4        forcats_1.0.0         
[26] purrr_1.0.4            tidyr_1.3.1            tibble_3.3.0           tidyverse_2.0.0        ggrepel_0.9.6         
[31] RColorBrewer_1.1-3     stringr_1.5.1          dplyr_1.1.4            reshape2_1.4.4         ggplot2_3.5.2         
[36] readr_2.1.5           

loaded via a namespace (and not attached):
 [1] polynom_1.4-1        rlang_1.1.6          magrittr_2.0.3       tseries_0.10-58      compiler_4.5.1      
 [6] systemfonts_1.2.3    vctrs_0.6.5          quadprog_1.5-8       crayon_1.5.3         pkgconfig_2.0.3     
[11] fastmap_1.2.0        backports_1.5.0      ellipsis_0.3.2       labeling_0.4.3       utf8_1.2.6          
[16] rmarkdown_2.29       tzdb_0.5.0           anytime_0.3.11       xfun_0.52            jsonlite_2.0.0      
[21] highr_0.11           rsdmx_0.6-5          broom_1.0.8          parallel_4.5.1       R6_2.6.1            
[26] stringi_1.8.7        car_3.1-3            Rcpp_1.0.14          knitr_1.50           nnet_7.3-20         
[31] timechange_0.3.0     tidyselect_1.2.1     yaml_2.3.10          rstudioapi_0.17.1    abind_1.4-8         
[36] timeDate_4041.110    curl_6.3.0           lattice_0.22-7       plyr_1.8.9           quantmod_0.4.28     
[41] withr_3.0.2          evaluate_1.0.4       ggdist_3.3.3         xts_0.14.1           xml2_1.3.8          
[46] pillar_1.10.2        carData_3.0-5        renv_1.1.4           distributional_0.5.0 generics_0.1.4      
[51] TTR_0.24.4           hms_1.1.3            scales_1.4.0         glue_1.8.0           lazyeval_0.2.2      
[56] data.table_1.17.6    ggsignif_0.6.4       XML_3.99-0.18        grid_4.5.1           colorspace_2.1-1    
[61] nlme_3.1-168         fracdiff_1.5-3       Formula_1.2-5        cli_3.6.5            rappdirs_0.3.3      
[66] textshaping_1.0.1    viridisLite_0.4.2    svglite_2.2.1        gtable_0.3.6         rstatix_0.7.2       
[71] digest_0.6.37        progressr_0.15.1     htmlwidgets_1.6.4    farver_2.1.2         htmltools_0.5.8.1   
[76] lifecycle_1.0.4      httr_1.4.7 

可能的解决方案

  • 修正VARIMA语法:fable中多变量VARIMA的正确语法无需vars()包裹响应变量,应使用+连接变量。尝试修改代码:

    fit <- aus_production %>% model(VARIMA(Beer + Cement ~ pdq(4,1,1)))
    

    也可以先使用自动识别模型简化调试:

    fit <- aus_production %>% model(VARIMA(Beer + Cement))
    
  • 更新fpp3生态包:当前使用的fable(0.4.1)、tsibble(1.1.6)版本可能存在兼容性问题,更新相关包:

    install.packages(c("fable", "tsibble", "feasts", "tsibbledata", "fabletools"))
    
  • 查看拟合错误详情:NULL模型通常是拟合过程出错但未抛出显性错误,通过以下方式获取报错信息:

    report(fit)
    # 或手动捕获错误
    tryCatch({
      fit <- aus_production %>% model(VARIMA(vars(Beer, Cement) ~ pdq(4, 1, 1), identification = "none"))
    }, error = function(e) print(e))
    
  • 清理环境避免包冲突:当前环境加载了大量无关包(如vars、forecast),可能引发函数冲突。在干净环境中测试:

    rm(list = ls())
    detachAllPackages <- function() {
      basic.packages <- c("package:stats","package:graphics","package:grDevices","package:utils","package:datasets","package:methods","package:base")
      package.list <- search()[ifelse(unlist(gregexpr("package:",search()))==1,TRUE,FALSE)]
      package.list <- setdiff(package.list,basic.packages)
      if (length(package.list)>0)  for (package in package.list) detach(package, character.only=TRUE)
    }
    detachAllPackages()
    library(fable)
    library(tsibbledata)
    # 重新运行拟合代码
    aus_production %>% autoplot(vars(Beer, Cement))
    fit <- aus_production %>% model(VARIMA(Beer + Cement ~ pdq(4,1,1)))
    fit
    
  • 重新安装依赖包quadprog:VARIMA拟合依赖quadprog进行优化,即便已加载也可重新安装确保正常工作:

    install.packages("quadprog")
    

内容的提问来源于stack exchange,提问作者BerndGit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 21:05:17