我正在尝试验证我的数据在具有逻辑copula的双变量GEV和bilogistic copula之间的更好估计分布。
我通过可能性定量测试进行操作,并且当无效的假设被拒绝时,它仅显示出良好的p值。我认为这是由于代码错误造成的。
请帮助
数据:
max
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1958 163.0 182.3 178.0 254.1 165.5 230.6 164.0 172.0
[2,] 1959 105.0 119.6 91.5 72.0 71.2 85.0 138.0 64.8
[3,] 1960 125.0 159.4 200.0 105.0 118.5 106.4 109.0 84.8
[4,] 1961 130.5 127.8 106.8 106.3 109.5 141.6 97.0 90.5
[5,] 1962 149.2 154.3 93.0 57.4 66.5 100.4 177.0 54.0
[6,] 1963 194.8 199.2 113.0 136.0 129.7 232.0 170.0 140.0
[7,] 1964 176.2 138.2 125.8 113.5 129.0 166.4 138.0 114.0
[8,] 1965 250.2 272.0 102.2 74.5 87.0 117.4 211.1 69.5
[9,] 1966 84.7 188.4 76.5 52.0 73.7 116.1 90.5 57.0
[10,] 1967 65.2 98.0 82.4 63.0 67.5 79.7 86.0 54.8
[11,] 1968 115.2 217.0 120.8 58.0 63.8 123.1 71.2 56.0
[12,] 1969 87.8 128.0 110.0 126.0 104.8 125.2 95.0 107.0
[13,] 1970 96.0 145.0 240.0 170.0 154.8 187.9 95.0 108.0
[14,] 1971 117.3 148.0 170.0 67.7 81.6 107.2 135.0 70.7
[15,] 1972 114.0 115.4 118.0 106.4 118.0 139.1 108.0 108.0
[16,] 1973 126.0 165.2 170.0 99.3 80.0 98.6 164.3 75.0
[17,] 1974 103.4 134.6 98.0 64.6 76.0 237.4 127.3 63.8
[18,] 1975 92.7 93.6 88.0 54.0 55.8 79.2 69.0 45.0
[19,] 1976 132.8 235.4 170.0 176.0 150.0 177.6 212.0 145.0
[20,] 1977 112.1 148.6 187.7 98.6 120.0 278.0 126.0 89.0
[21,] 1978 85.5 117.2 137.5 103.1 120.5 133.8 110.5 107.0
[22,] 1979 124.7 138.5 124.0 105.0 104.0 124.0 107.5 102.0
[23,] 1980 219.5 184.0 75.5 65.7 80.5 90.0 148.2 63.0
[24,] 1981 78.0 127.0 119.5 69.0 89.0 90.0 100.0 74.0
[25,] 1982 210.0 279.0 230.0 51.0 90.0 134.5 141.0 62.0
[26,] 1983 93.8 96.2 162.0 90.0 92.0 63.0 101.8 110.0
[27,] 1984 119.9 180.6 236.0 66.0 126.0 140.0 119.0 78.0
[28,] 1985 61.1 86.0 97.0 38.5 48.0 73.0 66.4 39.0
[29,] 1986 83.0 168.8 114.5 74.0 91.5 120.0 97.3 71.4
[30,] 1987 117.5 147.5 108.1 88.5 105.0 130.0 130.0 125.2
[31,] 1988 84.6 126.5 117.0 87.5 88.8 99.0 89.3 97.0
[32,] 1989 81.0 143.2 120.0 48.5 51.6 85.0 85.0 54.0
[33,] 1990 75.5 93.0 65.0 51.5 56.5 70.0 63.7 44.0
[34,] 1991 85.0 112.3 90.0 61.5 65.5 42.0 82.3 72.0
[35,] 1992 150.0 222.0 160.0 215.0 192.0 211.0 202.8 199.0
[36,] 1993 128.5 152.0 120.0 141.0 71.0 83.1 227.2 143.9
[37,] 1994 249.1 244.0 190.0 132.0 124.5 221.0 165.0 106.0
[38,] 1995 96.1 127.0 200.0 164.0 219.0 256.4 139.5 125.0
[39,] 1996 108.3 181.0 133.0 70.5 86.5 144.0 135.0 83.4
[40,] 1997 89.0 120.6 150.0 155.0 145.3 136.0 150.0 230.0
[41,] 1998 112.1 176.5 190.0 139.0 159.2 130.0 129.2 105.4
[42,] 1999 142.5 199.5 200.0 78.0 95.7 108.7 172.5 60.8
[43,] 2000 103.0 163.3 140.0 135.5 126.4 126.6 104.0 81.0
代码:
library(evd)
c=combn(1:8,2)
bgev_log=list(length=28)
for(i in 1:28){
bgev_log[[i]]=fbvevd(cbind(max[,c[1,i]+1],max[,c[2,i]+1]),model="log")
}
bgev_bilog=list(length=28)
for(i in 1:28){
bgev_bilog[[i]]=fbvevd(cbind(max[,c[1,i]+1],max[,c[2,i]+1]),model="bilog",std.err=FALSE)
}
trvs=function(log,bilog){
D=2*(abs(logLik(log)-logLik(bilog)))
return(D)
}
trvsr=vector(length=28)
for(i in 1:28){
trvsr[i]=trvs(bgev_log[[i]],bgev_bilog[[i]])
}
p.val=vector(length=28)
for(i in 1:28){
p.val[i]=pchisq(trvsr[i], 1, lower.tail=FALSE)
}
modele=vector(length=28)
modele[which(trvsr<qchisq(.95, df=1))]='log'
modele[which(trvsr>=qchisq(.95, df=1))]='bilog'
sig=vector(length=28)
sig[which(p.val<=0.03)]='***'
sig[which(p.val<=0.05 & p.val>0.03) ]='**'
sig[which(p.val<=0.06 & p.val>0.05) ]='*'
sig[which(p.val>0.06) ]=' '
输出:
输出:
trvsr
[1] 0.093562490 1.592100173 4.433786405 0.285696128 0.017787392
[6] 0.025239761 1.200461025 0.232100874 4.899640061 0.502523168
[11] 0.494979289 0.590806114 0.576494213 7.873337183 6.239519942
[16] 1.001118715 0.969221050 3.148315326 0.001530167 2.025349835
[21] 1.431512991 0.170563364 2.369423446 2.918107515 0.496675317
[26] 1.870034511 0.251993649 3.849875976
p.val
[1] 0.759696119 0.207026334 0.035234261 0.592991846 0.893901259
[6] 0.873771088 0.273229554 0.629970419 0.026862294 0.478393557
[11] 0.481714526 0.442107569 0.447689768 0.005016898 0.012493033
[16] 0.317039963 0.324874524 0.076005396 0.968796832 0.154693296
[21] 0.231517676 0.679611613 0.123732742 0.087590537 0.480964613
[26] 0.171471127 0.615674773 0.049749669
sig
[1] " " " " "**" " " " " " " " " " " "***" " "
[11] " " " " " " "***" "***" " " " " " " " " " "
[21] " " " " " " " " " " " " " " "**"