fci vs. spx monthlyreturn fisher.test

create data set

> w <- data.frame(fci=(diff(to.monthly(NFCI)[,4]))["2010::2022-11"],spx=(monthlyReturn(GSPC))["2010::2022-11"])
> colnames(w) <- c('fci','spx')
> w
fci spx
1 2010 -0.05203 -3.697425e-02
2 2010 -0.05722 2.851369e-02
3 2010 -0.18112 5.879643e-02
4 2010 0.07212 1.475923e-02
5 2010 0.29466 -8.197584e-02
6 2010 -0.01741 -5.388244e-02

category

> dplyr::filter(w,fci<0 & spx >0) %>% dim()
# fci is minus and spx is positive
[1] 76 2
> dplyr::filter(w,fci<0 & spx <0) %>% dim() 
# fci is minus and spx is negative
[1] 12 2
> dplyr::filter(w,fci>0 & spx >0) %>% dim() 
# fci is plus and spx is positive
[1] 26 2
> dplyr::filter(w,fci>0 & spx <0) %>% dim() 
# fci is minus and spx is negative
[1] 41 2

results

> c(76,12,26,41) %>% matrix(.,nrow=2,dimnames=list(c('positive','negative'),c('fciminus','fciplus')))
fciminus fciplus
positive 76 26
negative 12 41
> c(76,12,26,41) %>% matrix(.,nrow=2,dimnames=list(c('positive','negative'),c('fciminus','fciplus'))) %>% fisher.test()

Fisher's Exact Test for Count Data
data: .
p-value = 6.886e-10
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
4.302013 23.827788
sample estimates:
odds ratio
9.80708


graph

appendix case from 1980

w <- data.frame(fci=(diff(to.monthly(NFCI)[,4]))["1980::2022-11"],spx=(monthlyReturn(GSPC))["1980::2022-11"])
colnames(w) <- c('fci','spx')
dplyr::filter(w,fci<0 & spx >0) %>% dim()
[1] 218 2
dplyr::filter(w,fci<0 & spx <0) %>% dim()
[1] 60 2
dplyr::filter(w,fci>0 & spx >0) %>% dim()
[1] 105 2
dplyr::filter(w,fci>0 & spx <0) %>% dim()
[1] 132 2

c(218,60,105,132) %>% matrix(.,nrow=2,dimnames=list(c('positive','negative'),c('fciminus','fciplus'))) %>% fisher.test()

Fisher's Exact Test for Count Data
data: .p-value = 1.594e-15
alternative hypothesis: true odds ratio is not equal to 195 percent confidence interval:3.058279 6.837407
sample estimates:
odds ratio 4.553196



いいなと思ったら応援しよう!