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 Thank you, Thomas This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Try this: table(nDeaths = rep(0:4, c(109, 65, 22, 3, 1))) ## or as.table(array(c(109L, 65L, 22L, 3L, 1L), dimnames = list(nDeaths = 0:4))) -- Noia Raindrops noia.raindrops at gmail.com
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 notYou 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
Maybe Matching Threads
- goodfit() in vcd package: computation of chi-squared
- Does goodfit() require frequency count of the numbers or numbers themselves?
- Error while using fitdistr() function or goodfit() function
- How can I save the result for goodness of fit test
- (Fwd) Re: goodfit macro