-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcusum f stat final
58 lines (49 loc) · 1.64 KB
/
cusum f stat final
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
library(strucchange)
# mat2 <- read.csv(file="I:/New Project/Stocks/dcc_stocks_red_v2.csv",head=TRUE,sep=",")
for (i in 1:15)
{
mat2 <- read.csv(file="I:/New Project/Stocks/dcc_stocks_red_v2.csv",head=TRUE,sep=",")
mat = mat2[,i]
## Load dataset "mat" with average yearly temperatures in New Haven
## plot the data
s1 <- "I:/dcc"
s2 <- as.character(i)
# s3 <- ".pdf"
s3 <- ".jpeg"
name <- paste(s1, s2, s3, sep = "")
# pdf(name, bg = "white")
jpeg(name, quality = 100, bg = "white",res = 200, width = 7, height = 7, units = "in")
plot(mat)
dev.off()
## test the model null hypothesis that the average temperature remains constant
## over the years
## compute OLS-CUSUM fluctuation process
temp.cus <- efp(mat ~ 1, type = "OLS-MOSUM")
## plot the process without boundaries
s1 <- "I:/ols_mosum"
s2 <- as.character(i)
# s3 <- ".pdf"
s3 <- ".jpeg"
name <- paste(s1, s2, s3, sep = "")
jpeg(name, quality = 100, bg = "white",res = 200, width = 7, height = 7, units = "in")
plot(temp.cus, alpha = 0.01, boundary = FALSE)
dev.off()
## add the boundaries in another colour
bound <- boundary(temp.cus, alpha = 0.01)
lines(bound, col=4)
lines(-bound, col=4)
fs <- Fstats(mat ~ 1, from = 4, to = length(mat)-4)
k <- fs$nreg
n <- fs$nobs
x <- fs$Fstats
pvals <- 1 - pf(x, k, (n - 2 * k))
s1 <- "I:/ols_mosum_pval"
s2 <- as.character(i)
# s3 <- ".pdf"
s3 <- ".jpeg"
name <- paste(s1, s2, s3, sep = "")
# pdf(name, bg = "white")
jpeg(name, quality = 100, bg = "white",res = 200, width = 7, height = 7, units = "in")
plot(fs,pval=TRUE)
dev.off()
}