Thursday, March 15, 2018

Chisquared test và Fisher exact test trong bảng tần suất 2x2


Chạy với dữ liệu mới đã sửa lại Performance của một số thương vụ (file mdat1)
> mdat<-read.csv("D:thR/mdat1.csv", sep=";", header=TRUE)
> head(mdat)
Number        Acquirer FirmsizeA      Target FirmsizeT Year  Stake  Categories Performance Stake1  X
1    M01          KinhDo    listed      Wall's   foreign 2003    50% acquisition    positive  above 15
2    M02          KinhDo    listed     Tribeco    listed 2005 35.40% acquisition    negative  above 13
3    M03             ANZ   foreign   Sacombank    listed 2005    10% acquisition    negative  under 13
4    M04 StandardCharter   foreign         ACB    listed 2005    10% acquisition    positive  under 13
5    M05            OCBC   foreign      VPBank     other 2006    10% acquisition    negative  under 12
6    M06            HSBC   foreign Techcombank     other 2007    15% acquisition    negative  under 11
> hieuqua1 <- xtabs(~Performance+FirmsizeA, data=mdat)
> hieuqua1
           FirmsizeA
Performance foreign listed other SOE
   mix            8      6     1   1
   negative      19     10     0   0
   positive      16     13     2   3
> hieuqua1 <- read.table("D:thR/hieuqua1.txt", header=TRUE)
> hieuqua1
         pos neg
foreign   16  27
domestic  18  18
> chisq.test(hieuqua1)
 
        Pearson's Chi-squared test with Yates' continuity correction
 
data:  hieuqua1
X-squared = 0.83796, df = 1, p-value = 0.36
 
> fisher.test(hieuqua1)
 
        Fisher's Exact Test for Count Data
 
data:  hieuqua1
p-value = 0.2657
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.2190024 1.5993961
sample estimates:
odds ratio 
 0.5965731 
 
> hieuqua3 <- read.table("D:thR/hieuqua3.txt", header=TRUE)
> hieuqua3
            neg pos
acquisition  40  30
merger        5   4
> fisher.test(hieuqua3)
 
        Fisher's Exact Test for Count Data
 
data:  hieuqua3
p-value = 1
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.1940964 5.4276861
sample estimates:
odds ratio 
  1.065783 
 
> hieuqua4 <- read.table("D:thR/hieuqua4.txt", header=TRUE)
> hieuqua4
        pos neg
under35  28  14
above35   6  31
> fisher.test(hieuqua4)
 
        Fisher's Exact Test for Count Data
 
data:  hieuqua4
p-value = 9.702e-06
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
  3.160346 36.481411
sample estimates:
odds ratio 
   9.97676 
 
> chisq.test(hieuqua4)
 
        Pearson's Chi-squared test with Yates' continuity correction
 
data:  hieuqua4
X-squared = 18.417, df = 1, p-value = 1.775e-05
 
> hieuqua2 <- read.table("D:thR/hieuqua2.txt", header=TRUE)
> hieuqua2
         pos neg
foreign    5   1
domestic  29  44
> chisq.test(hieuqua2)
 
        Pearson's Chi-squared test with Yates' continuity correction
 
data:  hieuqua2
X-squared = 2.7057, df = 1, p-value = 0.09999
 
Warning message:
In chisq.test(hieuqua2) : Chi-squared approximation may be incorrect
> hqmodel1 <- read.table("D:thR/hqmodel1.txt", header=T)
> hqmodel1
  FirmsizeA  Categories Neg Pos
1   foreign acquisition  26  16
2   foreign      merger   1   0
3  domestic acquisition  14  14
4  domestic      merger   4   4
> contrasts(hqmodel1$FirmsizeA)=contr.treatment(levels(hqmodel1$FirmsizeA), base=2)
> contrasts(hqmodel1$Categories)=contr.treatment(levels(hqmodel1$Categories), base=2)
> library(VGAM)
Loading required package: stats4
Loading required package: splines
> fit.hqmodel1=vglm(cbind(Pos,Neg)~FirmsizeA+Categories, data=hqmodel1,family=multinomial)
> summary(fit.hqmodel1)
 
Call:
vglm(formula = cbind(Pos, Neg) ~ FirmsizeA + Categories, family = multinomial, 
    data = hqmodel1)
 
 
Pearson residuals:
        [,1]
[1,]  0.1039
[2,] -0.6948
[3,] -0.1231
[4,]  0.2310
 
Coefficients: 
                      Estimate Std. Error z value Pr(>|z|)
(Intercept)            -0.7282     0.8016  -0.908    0.364
FirmsizeAdomestic       0.5650     0.4831   1.170    0.242
Categoriesacquisition   0.2097     0.7533   0.278    0.781
 
Number of linear predictors:  1 
 
Name of linear predictor: log(mu[,1]/mu[,2]) 
 
Residual deviance: 0.8669 on 1 degrees of freedom
 
Log-likelihood: -5.7028 on 1 degrees of freedom
 
Number of iterations: 3 
 
Reference group is level  2  of the response
> hqmodel2 <- xtabs(~Stake1+Categories+Performance, data=mdat)
> hqmodel2
, , Performance = mix
 
       Categories
Stake1  acquisition merger
  above          12      2
  under           2      0
 
, , Performance = negative
 
       Categories
Stake1  acquisition merger
  above          15      2
  under          11      1
 
, , Performance = positive
 
       Categories
Stake1  acquisition merger
  above          24      4
  under           6      0
 
> hqmodel2 <- read.table("D:thR/hqmodel2.txt", header=T)
> hqmodel2
  Stake1  Categories Neg Pos
1  above acquisition  27  24
2  under acquisition  13   6
3  above      merger   4   4
4  under      merger   1   0
> contrasts(hqmodel2$Stake1)=contr.treatment(levels(hqmodel2$Stake1), base=2)
> contrasts(hqmodel2$Categories)=contr.treatment(levels(hqmodel2$Categories), base=2)
> fit.hqmodel2=vglm(cbind(Pos,Neg)~Stake1+Categories, data=hqmodel2,family=multinomial)
> summary(fit.hqmodel2)
 
Call:
vglm(formula = cbind(Pos, Neg) ~ Stake1 + Categories, family = multinomial, 
    data = hqmodel2)
 
 
Pearson residuals:
         [,1]
[1,] -0.08132
[2,]  0.14514
[3,]  0.20564
[4,] -0.63918
 
Coefficients: 
                      Estimate Std. Error z value Pr(>|z|)
(Intercept)           -0.89512    0.84263  -1.062    0.288
Stake1above            0.74984    0.55674   1.347    0.178
Categoriesacquisition  0.05031    0.72239   0.070    0.944
 
Number of linear predictors:  1 
 
Name of linear predictor: log(mu[,1]/mu[,2]) 
 
Residual deviance: 0.7548 on 1 degrees of freedom
 
Log-likelihood: -5.5099 on 1 degrees of freedom
 
Number of iterations: 3 
 
Reference group is level  2  of the response


No comments:

Post a Comment