File: runit5A.R

package info (click to toggle)
fbasics 240.10067-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,676 kB
  • ctags: 760
  • sloc: fortran: 5,589; sh: 22; makefile: 1
file content (194 lines) | stat: -rw-r--r-- 5,541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

################################################################################
# FUNCTION:             NORMALITY TESTS:
#  fHTEST                Class Representation
#  show.fHTEST           S4 Print Method
# FUNCTION:             DESCRIPTION:
#  jbTable               Finite sample p values for the Jarque Bera test
# FUNCTION:             PVALUE AND STATISTICS TABLES:
#  pPlot                 General finite sample probability plot
#  pTable                Interpolated probabilities from finite sample table
#  .pTable                Utility function called by the function 'pTable'
#  qTable                Interpolated quantiles from finite sample table
#  .qTable                Utility function called by the function 'qTable'
# FUNCTION:             INTERNAL FUNCTIONS:
#  .interpTable.old      'akima' interpolation utility function
#  .interpTable.new      'akima' interpolation utility function
################################################################################


test.helpFile = 
function()
{
    # Help File:
    helpFile = function() { 
        example(HypothesisTesting); return() }
    checkIdentical(
        target = class(try(helpFile())),
        current = "NULL")

    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.jbTable.LM = 
function()
{
    # Plot Parameters:
    par(ask = FALSE)
    par(mfrow = c(1, 1))
    
    # Interpolated plot of Small Jarque Bera Table:
    X = jbTable(type = "LM", size = "small")
    
    # List of finite Sizes:
    colnames(X) 
    
    # List of Probabilities:
    rownames(X)
    
    # 3D-Plot Probability Table:
    pPlot(X, linear = TRUE,  logStat = TRUE, main = "JB LM", cex = 0.5)
    pPlot(X, linear = TRUE,  logStat = TRUE, fill = TRUE,    cex = 0.5)
    pPlot(X, linear = FALSE, logStat = TRUE,                 cex = 0.5)
    pPlot(X, linear = FALSE, logStat = TRUE, fill = TRUE,    cex = 0.5)
    
    # 2D-Plot Probability for Fixed Size:
    p = (1:99)/100
    plot(qTable(X, p, N = 100), p, type = "b")
    grid()
    
    # 2D-Plot Statistics for Fixed Size:
    Stat = seq(0.01, 15, length = 100)
    plot(Stat, pTable(X, Stat, N = 100), type = "b")  
    grid()
    
    # Return Value:
    return()  
}


# ------------------------------------------------------------------------------


test.jbTable.ALM = 
function()
{
    # Plot Parameters:
    par(ask = FALSE)
    par(mfrow = c(1, 1))
    
    # Interpolated plot of Small Jarque Bera Table:
    X = jbTable(type = "ALM", size = "small")
    
    # List of finite Sizes:
    colnames(X) 
    
    # List of Probabilities:
    rownames(X)
    
    # 3D-Plot Probability Table:
    pPlot(X, linear = TRUE,  logStat = TRUE, main = "JB ALM", cex = 0.5)
    pPlot(X, linear = TRUE,  logStat = TRUE, fill = TRUE,     cex = 0.5)
    pPlot(X, linear = FALSE, logStat = TRUE,                  cex = 0.5)
    pPlot(X, linear = FALSE, logStat = TRUE, fill = TRUE,     cex = 0.5)
    
    # 2D-Plot Probability for Fixed Size:
    p = (1:99)/100
    plot(qTable(X, p, N = 100), p, type = "b")
    grid()
    
    # 2D-Plot Statistics for Fixed Size:
    Stat = seq(0.01, 15, length = 100)
    plot(Stat, pTable(X, Stat, N = 100), type = "b")  
    grid()
    
    # Return Value:
    return()  
}


# ------------------------------------------------------------------------------

 
test.adfTable = 
function()
{  
    # Plot Parameters:
    par(ask = FALSE)
    par(mfrow = c(1, 1))
    
    # Dickey-Fuller Tables:
    
    # type = "ns" 
    adfTable = cbind(
        c(-2.66, -2.26, -1.95, -1.60, +0.92, +1.33, +1.70, +2.16),
        c(-2.62, -2.25, -1.95, -1.61, +0.91, +1.31, +1.66, +2.08),
        c(-2.60, -2.24, -1.95, -1.61, +0.90, +1.29, +1.64, +2.03),
        c(-2.58, -2.23, -1.95, -1.62, +0.89, +1.29, +1.63, +2.01),
        c(-2.58, -2.23, -1.95, -1.62, +0.89, +1.28, +1.62, +2.00),
        c(-2.58, -2.23, -1.95, -1.62, +0.89, +1.28, +1.62, +2.00))
    colnames(adfTable) = c(25, 50, 100, 250, 500, 100000)
    rownames(adfTable) = c(0.01, 0.025, 0.05, 0.1, 0.9, 0.95, 0.975, 0.99)
    print(adfTable)
        #          25    50   100   250   500 1e+05
        # 0.01  -2.66 -2.62 -2.60 -2.58 -2.58 -2.58
        # 0.025 -2.26 -2.25 -2.24 -2.23 -2.23 -2.23
        # 0.05  -1.95 -1.95 -1.95 -1.95 -1.95 -1.95
        # 0.1   -1.60 -1.61 -1.61 -1.62 -1.62 -1.62
        # 0.9    0.92  0.91  0.90  0.89  0.89  0.89
        # 0.95   1.33  1.31  1.29  1.29  1.28  1.28
        # 0.975  1.70  1.66  1.64  1.63  1.62  1.62
        # 0.99   2.16  2.08  2.03  2.01  2.00  2.00
    
    # Table:
    X = adfTable
    
    # List of finite Sizes:
    colnames(X) 
    
    # List of Probabilities:
    rownames(X)     
       
    # 3D Probability Plot:
    pPlot(X)
    ans = pPlot(X, 10, 10, fill = TRUE)$z

    # Probabilities:
    Stat = c(-3, -1.5, 0, 1.5, 3)
    N = 400
    p = pTable(X = adfTable, Stat, N) 
    names(p) = paste("q=", Stat, sep = "")
    attr(p, "N")<-N
    p
    
    # Quantiles:
    p = c(0.001, 0.01, 0.02, 0.06, 0.11)
    N = 400
    q = qTable(X = adfTable, p, N)
    names(q) = paste("p=", p, sep = "")
    attr(q, "N")<-N
    q
    
    # Return Value:
    return()
}

   
# ------------------------------------------------------------------------------


if (FALSE) {
    require(RUnit)
    testResult <- runTestFile("C:/Rmetrics/SVN/trunk/fBasics/test/runit5A.R")
    printTextProtocol(testResult)
}


################################################################################