Skip to content
Back to formatted view

Raw Message

Message-ID: <59A3F7E4-F693-4044-AF59-C00DB452E33A@comcast.net>
Date: 2012-08-22T22:19:46Z
From: David Winsemius
Subject: Entering a table
In-Reply-To: <8F38A285-E8D4-438D-BA05-5181060E5CE7@nottingham.ac.uk>

On Aug 21, 2012, at 5:48 AM, Thomas wrote:

> I'm trying to enter a frequency table manually so that I can run a  
> goodness of fit test (I only have the frequencies, I don't have the  
> raw data).
>
> So for example, let's say I want to re-create the HorseKicks table:
>
> library(vcd)
>
> data(HorseKicks)
> str(HorseKicks)
>
> 'table' int [1:5(1d)] 109 65 22 3 1
> - attr(*, "dimnames")=List of 1
>  ..$ nDeaths: chr [1:5] "0" "1" "2" "3" ...
>
> I tried this the following but it didn't work:
>
> vex <- matrix(c(0,109,1,65,2,22,3,3,4,1), nrow=2, ncol=5)
> vec <- as.table(vex)
> str(vec)
>
> table [1:2, 1:5] 0 109 1 65 2 22 3 3 4 1
> - attr(*, "dimnames")=List of 2
>  ..$ : chr [1:2] "A" "B"
>  ..$ : chr [1:5] "A" "B" "C" "D" ...
>
> I also tried:
>
> vex <- c(109,65,22,3,1)
> vec <- as.table(vex)
> str(vec)
>
> table [1:5(1d)] 109 65 22 3 1
> - attr(*, "dimnames")=List of 1
>  ..$ : chr [1:5] "A" "B" "C" "D" ...
>
> goodfit(HorseKicks) works fine
> goodfit(vec) does not

You needed a two _column_ matrix with the frequencies in the _first_  
column, rather than a two-row matrix with frequencies in the second row:

 > vcd::goodfit( t(vex)[ , 2:1])  # transpose to column oriented and  
swap columns

Observed and fitted values for poisson distribution
with parameters estimated by `ML'

  count observed      fitted
      0      109 108.6701738
      1       65  66.2888060
      2       22  20.2180858
      3        3   4.1110108
      4        1   0.6269291
>


-- 

David Winsemius, MD
Alameda, CA, USA