zoukankan      html  css  js  c++  java
  • R语言 ur.df函数(2)

      1 ############################################################################################
      2 # This R function helps to interpret the output of the urca::ur.df function.
      3 # The rules are based on https://stats.stackexchange.com/questions/24072/interpreting-rs-ur-df-dickey-fuller-unit-root-test-results
      4 #
      5 # urdf is the output of the urca::ur.df function
      6 # level is one of c("1pct", "5pct", "10pct")
      7 #
      8 # Author: Hank Roark
      9 # Date: October 2019
     10 ############################################################################################
     11 interp_urdf <- function(urdf, level="5pct") {
     12   if(class(urdf) != "ur.df") stop('parameter is not of class ur.df from urca package')
     13   if(!(level %in% c("1pct", "5pct", "10pct") ) ) stop('parameter level is not one of 1pct, 5pct, or 10pct')
     14 
     15   cat("========================================================================
    ")
     16   cat( paste("At the", level, "level:
    ") )
     17   if(urdf@model == "none") {
     18     cat("The model is of type none
    ")
     19     tau1_crit = urdf@cval["tau1",level]
     20     tau1_teststat = urdf@teststat["statistic","tau1"]
     21     tau1_teststat_wi_crit = tau1_teststat > tau1_crit
     22     if(tau1_teststat_wi_crit) {
     23       cat("tau1: The null hypothesis is not rejected, unit root is present
    ")
     24     } else {
     25       cat("tau1: The null hypothesis is rejected, unit root is not present
    ")
     26     }
     27   } else if(urdf@model == "drift") {
     28     cat("The model is of type drift
    ")
     29     tau2_crit = urdf@cval["tau2",level]
     30     tau2_teststat = urdf@teststat["statistic","tau2"]
     31     tau2_teststat_wi_crit = tau2_teststat > tau2_crit
     32     phi1_crit = urdf@cval["phi1",level]
     33     phi1_teststat = urdf@teststat["statistic","phi1"]
     34     phi1_teststat_wi_crit = phi1_teststat < phi1_crit
     35     if(tau2_teststat_wi_crit) {
     36       # Unit root present branch
     37       cat("tau2: The first null hypothesis is not rejected, unit root is present
    ")
     38       if(phi1_teststat_wi_crit) {
     39         cat("phi1: The second null hypothesis is not rejected, unit root is present
    ")
     40         cat("      and there is no drift.
    ")
     41       } else {
     42         cat("phi1: The second null hypothesis is rejected, unit root is present
    ")
     43         cat("      and there is drift.
    ")
     44       }
     45     } else {
     46       # Unit root not present branch
     47       cat("tau2: The first null hypothesis is rejected, unit root is not present
    ")
     48       if(phi1_teststat_wi_crit) {
     49         cat("phi1: The second null hypothesis is not rejected, unit root is present
    ")
     50         cat("      and there is no drift.
    ")
     51         warning("This is inconsistent with the first null hypothesis.")
     52       } else {
     53         cat("phi1: The second null hypothesis is rejected, unit root is not present
    ")
     54         cat("      and there is drift.
    ")
     55       }
     56     }
     57   } else if(urdf@model == "trend") {
     58     cat("The model is of type trend
    ")
     59     tau3_crit = urdf@cval["tau3",level]
     60     tau3_teststat = urdf@teststat["statistic","tau3"]
     61     tau3_teststat_wi_crit = tau3_teststat > tau3_crit
     62     phi2_crit = urdf@cval["phi2",level]
     63     phi2_teststat = urdf@teststat["statistic","phi2"]
     64     phi2_teststat_wi_crit = phi2_teststat < phi2_crit
     65     phi3_crit = urdf@cval["phi3",level]
     66     phi3_teststat = urdf@teststat["statistic","phi3"]
     67     phi3_teststat_wi_crit = phi3_teststat < phi3_crit
     68     if(tau3_teststat_wi_crit) {
     69       # First null hypothesis is not rejected, Unit root present branch
     70       cat("tau3: The first null hypothesis is not rejected, unit root is present
    ")
     71       if(phi3_teststat_wi_crit) {
     72         # Second null hypothesis is not rejected
     73         cat("phi3: The second null hypothesis is not rejected, unit root is present
    ")
     74         cat("      and there is no trend
    ")
     75         if(phi2_teststat_wi_crit) {
     76           # Third null hypothesis is not rejected
     77           # a0-drift = gamma = a2-trend = 0
     78           cat("phi2: The third null hypothesis is not rejected, unit root is present
    ")
     79           cat("      there is no trend, and there is no drift
    ")
     80         } else {
     81           # Third null hypothesis is rejected
     82           cat("phi2: The third null hypothesis is rejected, unit root is present
    ")
     83           cat("      there is no trend, and there is drift
    ")
     84         }
     85       }
     86       else {
     87         # Second null hypothesis is rejected
     88         cat("phi3: The second null hypothesis is rejected, unit root is present
    ")
     89         cat("      and there is trend
    ")
     90         if(phi2_teststat_wi_crit) {
     91           # Third null hypothesis is not rejected
     92           # a0-drift = gamma = a2-trend = 0
     93           cat("phi2: The third null hypothesis is not rejected, unit root is present
    ")
     94           cat("      there is no trend, and there is no drift
    ")
     95           warning("This is inconsistent with the second null hypothesis.")
     96         } else {
     97           # Third null hypothesis is rejected
     98           cat("phi2: The third null hypothesis is rejected, unit root is present
    ")
     99           cat("      there is trend, and there may or may not be drift
    ")
    100           warning("Presence of drift is inconclusive.")
    101         }
    102       }
    103     } else {
    104       # First null hypothesis is rejected, Unit root not present branch
    105       cat("tau3: The first null hypothesis is rejected, unit root is not present
    ")
    106       if(phi3_teststat_wi_crit) {
    107         cat("phi3: The second null hypothesis is not rejected, unit root is present
    ")
    108         cat("      and there is no trend
    ")
    109         warning("This is inconsistent with the first null hypothesis.")
    110         if(phi2_teststat_wi_crit) {
    111           # Third null hypothesis is not rejected
    112           # a0-drift = gamma = a2-trend = 0
    113           cat("phi2: The third null hypothesis is not rejected, unit root is present
    ")
    114           cat("      there is no trend, and there is no drift
    ")
    115           warning("This is inconsistent with the first null hypothesis.")
    116         } else {
    117           # Third null hypothesis is rejected
    118           cat("phi2: The third null hypothesis is rejected, unit root is not present
    ")
    119           cat("      there is no trend, and there is drift
    ")
    120         }
    121       } else {
    122         cat("phi3: The second null hypothesis is rejected, unit root is not present
    ")
    123         cat("      and there may or may not be trend
    ")
    124         warning("Presence of trend is inconclusive.")
    125         if(phi2_teststat_wi_crit) {
    126           # Third null hypothesis is not rejected
    127           # a0-drift = gamma = a2-trend = 0
    128           cat("phi2: The third null hypothesis is not rejected, unit root is present
    ")
    129           cat("      there is no trend, and there is no drift
    ")
    130           warning("This is inconsistent with the first and second null hypothesis.")
    131         } else {
    132           # Third null hypothesis is rejected
    133           cat("phi2: The third null hypothesis is rejected, unit root is not present
    ")
    134           cat("      there may or may not be trend, and there may or may not be drift
    ")
    135           warning("Presence of trend and drift is inconclusive.")
    136         }
    137       }
    138     }
    139   } else warning('urdf model type is not one of none, drift, or trend')
    140   cat("========================================================================
    ")
    141 }
    人前一杯酒,各自饮完;人后一片海,独自上岸
  • 相关阅读:
    SQL语法:查询此表有另外一个表没有的数据
    .NET平台开源项目速览-最快的对象映射组件Tiny Mapper之项目实践
    win7 64 安装Oracle 11G 、使用PLSQL进行连接 标准实践
    json 筛选数据 $.grep过滤数据
    bootstrap table 行号 显示行号 添加行号 bootstrap-table 行号
    ajax 请求二进制流 图片 文件 XMLHttpRequest 请求并处理二进制流数据 之最佳实践
    JS中判断JSON数据是否存在某字段的方法 JavaScript中判断json中是否有某个字段
    json 数字key json 数字作为主键
    ajax 跨域 headers JavaScript ajax 跨域请求 +设置headers 实践
    扩展:gridview 空数据时显示表头
  • 原文地址:https://www.cnblogs.com/kisen/p/12632390.html
Copyright © 2011-2022 走看看