bs.test: Bootstrap Likelihood Ratio Test for Finite Mixture Models

Description Usage Arguments Details Value See Also Examples

View source: R/bs.test.R

Description

This function performs the likelihood ratio test by parametric bootstrapping for two mixture models with different number of components.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
bs.test(
  x,
  ncomp = c(1, 2),
  family = c("normal", "weibull", "gamma", "lnorm"),
  B = 100,
  ev = FALSE,
  mstep.method = c("bisection", "newton"),
  init.method = c("kmeans", "hclust"),
  tol = 1e-06,
  max_iter = 500
)

Arguments

x

a numeric vector for the raw data or a three-column matrix for the binned data.

ncomp

a vector of two positive integers specifying the number of components of the mixture model under the null and alternative hypothesis. The first integer should be smaller than the second one. The default value is c(1, 2).

family

a character string specifying the family of the mixture model, which can be one of normal, weibull, gamma, or lnorm (default normal).

B

the number of bootstrap iterations (default 100).

ev

a logical value indicating whether the variance of each component should be the same or not (default FALSE). ev is ignored for other family members.

mstep.method

the method used in M-step of EM algorithm for weibull or gamma family. It is ignored for normal or lnorm family, which has closed-form solution in the M-step. The default value is bisection.

init.method

a character string specifying the method used for providing the initial values for the parameters for the EM algorithm. It can be one of kmeans or hclust. The default is kmeans

tol

the tolerance for the stopping rule of EM algorithm. It is the value to stop EM algorithm when the two consecutive iterations produces log-likelihood with difference less than tol. The default value is 1e-6.

max_iter

the maximum number of iterations for the EM algorithm (default 500).

Details

For the given data x and the specified family, the function bs.test conducts a bootstrap likelihood ratio test for two mixture models with the number of components under the null and the alternative hypothesis specified in ncomp.

Value

The function bs.test returns an object of class bootEM which contains the following three items.

pvalue

The p-value of the bootstrap likelihood ratio test

w0

the observed likelihood ratio test statistic

w1

a vector of simulated likelihood ratio test statistics

See Also

plot.bootEM, mixfit, select

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## testing normal mixture models with 2 and 3 components
set.seed(100)
x <- rmixnormal(200, c(0.5, 0.5), c(2, 5), c(1, 0.7))
ret <- bs.test(x, ncomp = c(2, 3), B = 30)
ret

## (not run) testing Weibull mixture models with 2 and 3 components
## set.seed(101)
## x <- rmixweibull(200, c(0.3, 0.4, 0.3), c(2, 5, 8), c(1, 0.6, 0.8))
## ret <- bs.test(x, ncomp = c(2, 3), family = "weibull", B = 30)
## ret

## (not run) testing Gamma mixture models with 1 and 2 components
## set.seed(102)
## x <- rgamma(200, 2, 1)
## ret <- bs.test(x, ncomp = c(1, 2), family = "gamma", B = 30)
## ret

mixR documentation built on June 1, 2021, 5:07 p.m.