Skip to content
Prev 258424 / 398502 Next

3-way contingency table

On Apr 29, 2011, at 6:47 AM, Mathias Walter wrote:

            
You have obviously not given us the full data from which your "correct  
answer" was drawn, but see if this is going  the right direction:

require(reshape)
 > dataHm <- melt(dataH)
Using host as id variables
 > xtabs(~host+value+variable, dataHm)
, , variable = ms01

         value
host     3 4 5 6 9 20
   cattle 0 4 0 0 0  0
   goat   0 3 0 0 0  0
   sheep  0 3 0 0 0  0

, , variable = ms31

         value
host     3 4 5 6 9 20
   cattle 3 0 0 0 0  1
   goat   3 0 0 0 0  0
   sheep  3 0 0 0 0  0

, , variable = ms33

         value
host     3 4 5 6 9 20
   cattle 0 3 0 0 1  0
   goat   0 3 0 0 0  0
   sheep  0 1 2 0 0  0

, , variable = ms34

         value
host     3 4 5 6 9 20
   cattle 0 0 3 1 0  0
   goat   0 0 3 0 0  0
   sheep  0 0 3 0 0  0
David Winsemius, MD
West Hartford, CT