This function fits the semi-supervised mixture model multiple times. It is called by mixtura and scrutor.

fit.wrap(y, z, dist, phi, pi, gamma, starts = 1, it.em = 100,
  epsilon = 1e-04)

Arguments

y

observations: numeric vector of length n

z

class labels: integer vector of length n, with entries 0, 1 and NA

dist

distributional assumption: character "norm" (Gaussian), "nbinom" (negative bionomial), or "zinb" (zero-inflated negative binomial)

phi

dispersion parameter: positive numeric, or NULL

pi

zero-inflation parameter: numeric between 0 and 1, or NULL

gamma

offset: numeric vector of length n, or NULL

starts

restarts of the EM algorithm: positive integer (defaults to 1)

it.em

(maximum) number of iterations in the EM algorithm: positive integer (defaults to 100)

epsilon

convergence criterion for the EM algorithm: non-negative numeric (defaults to 1e-04)

Value

This function returns the parameter estimates, the posterior probabilities, and the likelihood.

posterior

probability of belonging to class 1: numeric vector of length n

converge

path of the log-likelihood: numeric vector with maximum length it.em

estim0

parameter estimates under H0: data frame

estim1

parameter estimates under H1: data frame

loglik0

log-likelihood under H0: numeric

loglik1

log-likelihood under H1: numeric

lrts

likelihood-ratio test statistic: positive numeric

Details

The distributions are parametrised as follows:

  • Gaussian
    y ~ N(mean,sd^2)
    E[y]=mean
    Var[y]=sd^2

  • Negative binomial
    y ~ NB(mu,phi)
    E[y]=mu
    Var[y]=mu+phi*mu^2

  • Zero-inflated negative binomial
    y ~ ZINB(mu,phi,pi)
    E[y]=(1-pi)*mu

See also

This is an internal function. The user functions are mixtura and scrutor.

Examples

# data simulation n <- 100 z <- rep(0:1,each=n/2) y <- rnorm(n=n,mean=2*z,sd=1) z[(n/4):n] <- NA # model fitting fit.wrap(y,z,dist="norm")
#> $posterior #> [1] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 #> [6] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 #> [11] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 #> [16] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 #> [21] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.2473295913 #> [26] 0.1379557866 0.8544822127 0.3841875124 0.0041310609 0.0169270544 #> [31] 0.0220697324 0.7944980023 0.2022296583 0.0086261424 0.0327597395 #> [36] 0.0193142680 0.0264029977 0.0230198982 0.2907475421 0.0002407683 #> [41] 0.2558888422 0.0278693384 0.1250404459 0.3277304376 0.5949697991 #> [46] 0.1746455913 0.0530796851 0.0544241558 0.3667698535 0.0015611585 #> [51] 0.9593978916 0.2102229589 0.8329439855 0.8977331551 0.9569705370 #> [56] 0.8350415480 0.9937334873 0.8749699675 0.9929639767 0.8812360262 #> [61] 0.5337950599 0.8541554551 0.1592338070 0.9650017668 0.9434324186 #> [66] 0.5544914154 0.9826455135 0.7223815318 0.9743138889 0.3226003417 #> [71] 0.6503460304 0.9489936592 0.9342318171 0.9985108902 0.6934599906 #> [76] 0.9628867440 0.4563643527 0.6269196112 0.3258857687 0.7523484843 #> [81] 0.3064649277 0.7555833368 0.9872517582 0.9543410854 0.5382732574 #> [86] 0.8515902748 0.7851914704 0.9547257052 0.9318496362 0.7592232555 #> [91] 0.9199989616 0.9465726888 0.9643984557 0.9786604718 0.9569223533 #> [96] 0.9473778735 0.5017967817 0.9796003996 0.9814440849 0.9712655799 #> #> $converge #> [1] -174.9421 -173.4297 -172.1316 -170.9595 -169.9704 -169.2455 -168.7956 #> [8] -168.5575 -168.4457 -168.3952 -168.3710 -168.3576 -168.3489 -168.3427 #> [15] -168.3380 -168.3343 -168.3314 -168.3292 -168.3274 -168.3260 -168.3249 #> [22] -168.3241 -168.3234 -168.3229 -168.3225 -168.3221 -168.3219 -168.3217 #> [29] -168.3215 -168.3214 -168.3213 #> #> $estim0 #> p0 mean0 sd0 p1 mean1 sd1 #> 1 1 0.9255842 1.427628 0 NaN NaN #> #> $estim1 #> p0 mean0 sd0 p1 mean1 sd1 #> 1 0.4099793 0.009548088 1.057611 0.5900207 2.052376 0.9803706 #> #> $loglik0 #> [1] -177.5597 #> #> $loglik1 #> [1] -168.3213 #> #> $lrts #> [1] 18.4767 #>