R: Estimate probabilities in contingency table

multinomial {lava} | R Documentation

## Estimate probabilities in contingency table

### Description

Estimate probabilities in contingency table

### Usage

    multinomial(x, data = parent.frame(), marginal = FALSE, transform,
      vcov = TRUE, iid = TRUE, ...)

### Arguments

`x` | Formula (or matrix or data.frame with observations, 1 or 2 columns)
`data` | Optional data.frame
`marginal` | If TRUE the marginals are estimated
`transform` | Optional transformation of parameters (e.g., logit)
`vcov` | Calculate asymptotic variance (default TRUE)
`iid` | Return iid decomposition (default TRUE)
`...` | Additional arguments to lower-level functions

### Author(s)

Klaus K. Holst

### Examples

    set.seed(1)
    breaks <- c(-Inf,-1,0,Inf)
    m <- lvm(); covariance(m,pairwise=TRUE) <- ~y1+y2+y3+y4
    d <- transform(sim(m,5e2),
                  z1=cut(y1,breaks=breaks),
                  z2=cut(y2,breaks=breaks),
                  z3=cut(y3,breaks=breaks),
                  z4=cut(y4,breaks=breaks))

    multinomial(d[,5])
    (a1 <- multinomial(d[,5:6]))
    (K1 <- kappa(a1)) ## Cohen's kappa

    K2 <- kappa(d[,7:8])
    ## Testing difference K1-K2:
    estimate(merge(K1,K2,id=TRUE),diff)

    estimate(merge(K1,K2,id=FALSE),diff) ## Wrong std.err ignoring dependence
    sqrt(vcov(K1)+vcov(K2))

    ## Average of the two kappas:
    estimate(merge(K1,K2,id=TRUE),function(x) mean(x))
    estimate(merge(K1,K2,id=FALSE),function(x) mean(x)) ## Independence
    ##'
    ## Goodman-Kruskal's gamma
    m2 <- lvm(); covariance(m2) <- y1~y2
    breaks1 <- c(-Inf,-1,0,Inf)
    breaks2 <- c(-Inf,0,Inf)
    d2 <- transform(sim(m2,5e2),
                  z1=cut(y1,breaks=breaks1),
                  z2=cut(y2,breaks=breaks2))

    (g1 <- gkgamma(d2[,3:4]))
    ## same as
    ## Not run:
    gkgamma(table(d2[,3:4]))
    gkgamma(multinomial(d2[,3:4]))

    ## End(Not run)

    ##partial gamma
    d2$x <- rbinom(nrow(d2),2,0.5)
    gkgamma(z1~z2|x,data=d2)

[Package lava version 1.6.1 Index]