> ?mantelhaen.test
> raw=c(0,0,6,5,3,0,3,6,6,2,0,4,5,6,1,0,2,5,0,0)
> rabbits=array(raw,dim=c(2,2,5))
> rabbits
, , 1

     [,1] [,2]
     [1,]    0    6
     [2,]    0    5

, , 2

     [,1] [,2]
     [1,]    3    3
     [2,]    0    6

, , 3

     [,1] [,2]
     [1,]    6    0
     [2,]    2    4

, , 4

     [,1] [,2]
     [1,]    5    1
     [2,]    6    0

, , 5

     [,1] [,2]
     [1,]    2    0
     [2,]    5    0

> mantelhaen.test(rabbits)

        Mantel-Haenszel chi-squared test with continuity correction

data:  rabbits
Mantel-Haenszel X-squared = 3.9286, df = 1, p-value = 0.04747
alternative hypothesis: true common odds ratio is not equal to 1
95 percent confidence interval:
  1.026713 47.725133
  sample estimates:
  common odds ratio
                  7

> t69raw=c(11,10,25,27,16,22,4,10,14,7,5,12
+ ,2,1,14,16,6,0,11,12,1,0,10,10,1,1,4,8,4,6,2,1)
> t69=array(t69raw,dim=c(2,2,8))
> t69
, , 1

     [,1] [,2]
     [1,]   11   25
     [2,]   10   27

, , 2

     [,1] [,2]
     [1,]   16    4
     [2,]   22   10

, , 3

     [,1] [,2]
     [1,]   14    5
     [2,]    7   12

, , 4

     [,1] [,2]
     [1,]    2   14
     [2,]    1   16

, , 5

     [,1] [,2]
     [1,]    6   11
     [2,]    0   12

, , 6

     [,1] [,2]
     [1,]    1   10
     [2,]    0   10

, , 7

     [,1] [,2]
     [1,]    1    4
     [2,]    1    8

, , 8

     [,1] [,2]
     [1,]    4    2
     [2,]    6    1

> mantelhaen.test(t69)

        Mantel-Haenszel chi-squared test with continuity correction

data:  t69
Mantel-Haenszel X-squared = 5.6716, df = 1, p-value = 0.01724
alternative hypothesis: true common odds ratio is not equal to 1
95 percent confidence interval:
 1.177590 3.869174
 sample estimates:
 common odds ratio
          2.134549

> sum(t69)
[1] 273
> library(nnet)
> ?multinom
> x1=c(rep(2,4),rep(7,3))
> x1
[1] 2 2 2 2 7 7 7
> x2=c(3,4,5,6,3,5,6)
> x2
[1] 3 4 5 6 3 5 6
> yraw=c(0,10,3,7,10,4,5,10,20,3,4,20,3,1,50,40,3,1,60,3,2)
> y=array(yraw,dim=c(7,3))
> y
     [,1] [,2] [,3]
     [1,]    0   10   50
     [2,]   10   20   40
     [3,]    3    3    3
     [4,]    7    4    1
     [5,]   10   20   60
     [6,]    4    3    3
     [7,]    5    1    2
> fit=multinom(y ~ x1 + x2)
# weights:  12 (6 variable)
initial  value 284.540583
iter  10 value 213.475054
final  value 213.468470
converged
> fit
     # weights:  12 (6 variable)
     initial  value 284.540583
     iter  10 value 213.475054
     final  value 213.468470
     converged
     Call:
     multinom(formula = y ~ x1 + x2)

Coefficients:
  (Intercept)         x1         x2
  2    3.878294 -0.1351903 -0.6961262
  3    7.525092 -0.1955475 -1.3853915

Residual Deviance: 426.9369
AIC: 438.9369
> summary(fit)
Call:
multinom(formula = y ~ x1 + x2)

Coefficients:
  (Intercept)         x1         x2
  2    3.878294 -0.1351903 -0.6961262
  3    7.525092 -0.1955475 -1.3853915

Std. Errors:
  (Intercept)         x1        x2
  2    1.008533 0.08965241 0.2016337
  3    1.050273 0.08589664 0.2202543

Residual Deviance: 426.9369
AIC: 438.9369
> pnorm(-.69/.20)
[1] 0.0002802933
