zcc.tab: Lenh co ban lam nen cho lenh zcc

Usage Arguments Examples

View source: R/zcc.tab.R

Usage

1
cc.tab(tab, rev = c("neither", "rows", "columns", "both"), pctdig = 0, digits = 0)

Arguments

tab
rev
pctdig
digits

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(tab,rev = c("neither", "rows", "columns", "both"),pctdig=0,digits=0){
    if ((ncol(tab)>= 2) & (nrow(tab)>=2)) {
        N<-nrow(tab)
            reverse <- match.arg(rev)
            if (reverse == "columns")  tab <- x[N:1, ]
            if (reverse == "rows")     tab <- tab[, 2:1]
            if (reverse == "neither")  tab <- tab[N:1, 2:1]
            if (reverse == "both")     tab <- tab
        min1<-min(outer(margin.table(tab,1), margin.table(tab,2), "*")/margin.table(tab))
        if (min1<5) {
            st<-fisher.test(tab,simulate.p.value=TRUE)
            stat1<-paste("Fisher's Exact =",formatC(st$p.value,format="f",digits=4))
        } else
        {
          st<-chisq.test(tab, correct=FALSE)
         stat1<-paste("Pearson's Chi2","(",st$parameter,") = ",
              formatC(st$statistic,format="f",digits=2)," Pr = ",
              ifelse(st$p.value<0.0001,"<0.0001",formatC(st$p.value,format="f",digits=4)),sep="")
        }
          or1<-tab[,1]*tab[N,2]/tab[,2]/tab[N,1]
          ef1<-exp(1.96*sqrt(1/tab[,1]+1/tab[,2]+1/tab[N,1]+1/tab[N,2]))
        tabpct<-round(prop.table(tab,1)*100,pctdig)
        tab<-rbind(c("N","N"),tab)
        tabpct<-rbind(c("",""),tabpct)
        c1<-paste(tab[,1]," (",tabpct[,1],"%)",sep="")
        c2<-paste(tab[,2]," (",tabpct[,2],"%)",sep="")
          ci.or<-paste(formatC(or1,format="f",digits=2)," (",formatC(or1/ef1,format="f",digits=2),
              "-",formatC(or1*ef1,format="f",digits=2),")",sep="")
        ci.or=c(stat1,ci.or)
        t0<-cbind(c1,c2,ci.or)
        return(t0)
    }
  }

gvdovandzung/thongke documentation built on May 23, 2020, 12:35 a.m.