# NOT RUN {
#Poisson Example (Spinelli 1994) p36
counts <- c(9, 22, 6, 2, 1, 0, 0, 0, 0)
vals <- 0:8
data <- rep(vals, counts)
groupFit(data = data, distr = "pois")
# When the parameters are unknown
#(Spinelli 1994) p56
counts <- c(57, 203, 383, 525, 532, 408, 273, 139, 45, 27, 10, 4, 0, 1, 1)
vals <- 0:14
data <- rep(vals, counts)
(pois_fit <- groupFit(data = data, distr = "pois"))
#Binomial example when the parameter is unknown
#Spinelli (1994) P92.
N=12
counts= c(185, 1149, 3265, 5475, 6114, 5194,
3067, 1331, 403, 105, 14, 4, 0)
vals <- 0:12
data <- rep(vals, counts)
(binom_fit <- groupFit(data = data, N = N, distr = "binom"))
#When the parameter is assumed known and is equal to 1/3
(binom_fit <- groupFit(data = data, N = N, distr = "binom", params = 1/3, known = TRUE))
#uniform example (Choulakian, Lockhart and Stephens(1994) Example 2, p8)
counts <- c(10, 19, 18, 15, 11, 13, 7, 10, 13, 23, 15, 22)
(uni_fit <- groupFit(0:12, counts, distr = "unif"))
#uniform example (Choulakian, Lockhart and Stephens(1994) Example 3, p8)
counts <- c(1, 4, 11, 4, 0)
probability <- c(0.05, 0.3, 0.3, 0.3, 0.05)
breaks <- c(0, cumsum(probability))
#with bootstrapping
(uni_fit1 <- groupFit(breaks, counts, distr = "unif", bootstrap = TRUE, numLoops = 500))
#without bootstrapping
(uni_fit2 <- groupFit(breaks, counts, distr = "unif", bootstrap = FALSE))
#exponential example (Spinelli 2001)
breaks <- c(0, 2, 6, 10, 14, 18, 22, 26)
counts <- c(21, 9, 5, 2, 1, 1, 0)
(exp_fit <- groupFit(breaks, counts, distr = "exp", pave = TRUE))
#Example Sun, Stephens & Spinelli (2012) set 2.
breaks <- c(0, 2, 6, 10, 14, 18, 22, 26)
counts <- c(21, 9, 5, 2, 1, 1, 0)
breaks[1] <- 1e-6
breaks[8] <- Inf
(weibull_fit <- groupFit(breaks, counts, distr = "Weibull"))
#Example Sun, Stephens & Spinelli (2012) set 3.
breaks <- c(0, seq(0.5, 6.5, 1) )
counts <- c(32, 12, 3, 6, 0, 0, 1)
breaks[1] <- 1e-6
breaks[8] <- Inf
(weibull_fit <- groupFit(breaks, counts, distr = "Weibull"))
#Example Sun, Stephens & Spinelli (2012) set 3.
breaks <- c(0, 2, 6, 10, 14, 18, 22, 26)
counts <- c(21, 9, 5, 2, 1, 1, 0)
breaks[1] <- 1e-6
breaks[8] <- Inf
(gamma_fit <- groupFit(breaks, counts, distr = "exp"))
#Example Sun, Stephens & Spinelli (2012) set 3.
breaks <- c(0, seq(0.5, 6.5, 1) )
counts <- c(32, 12, 3, 6, 0, 0, 1)
breaks[1] <- 1e-6
breaks[8] <- Inf
(gamma_fit <- groupFit(breaks, counts, distr = "gamma"))
#More examples
breaks <- c(0, seq(0.5, 6.5, 1) )
counts <- table(cut(rgamma(100, 3, 1/3), breaks))
breaks[8] <- Inf
#setting pave to true
(exp_fit <- groupFit(breaks, counts, distr = "exp", initials = 0.2, pave = TRUE))
#Setting known to true, with params
(gamma_fit <- groupFit(breaks, counts, distr = "gamma",
params = c(3, 1/3), known = TRUE))
#with bootstrapping, specifying the number of loops.
(lnorm_fit <- groupFit(breaks, counts, distr = "lnorm",
bootstrap = TRUE, numLoops = 1000))
#fitting with both pave and imhof set to false
#by setting imhof to false, we use a+bX^2_p to approximate
#the distribution of the goodness-of-fit Statistics
(weibull_fit <- groupFit(breaks, counts, distr = "weibull",
pave = TRUE, imhof = FALSE))
#Using the user defined distribution to test for Benford's law
#genomic data, Lesperance et al (2016)
genomic <- c(48, 14, 12, 6, 18, 5, 7, 8, 9)
phat <- log10(1+1/1:9)
(fit <- groupFit(counts = genomic, distr = "user", pfixed = phat, imhof = FALSE, pave = TRUE))
# }
Run the code above in your browser using DataLab