I am trying to create a function where if the length of my data is longer than 6, I would like it to tabulate it into 6 bins, and if the length of it is 6 or less, I do not want it to change. I want to use that info to create a test statistic for a chi squared goodness of fit test. The function below has worked when my length exceeds 6, but does not work when it has a length of 6 or less
ExpectedCount <- 52/6
TestStatistic <- function(data){
if(length(data > 6)){
test <- tabulate(data, nbins = 6)
} else {
test <- data
}
SumTotals <- sum(((test-ExpectedCount)^2)/(test))
return(SumTotals)
}
Aucun commentaire:
Enregistrer un commentaire