emCalcMix: emCalcMix(x,densities,p,maxiter,conv)

Description Usage Arguments Value Author(s) Examples

View source: R/emCalcMix.R

Description

This function performs the Expectation-Maximization Algorithm to estimate a vector of class proportions for a single feature in a data set wih an unknown set of class proportions. Called by featureMixtureProportion.

Usage

1
emCalcMix(x, densities, p = rep(0.2, 5), maxiter = 2000, conv = 1e-05)

Arguments

x

A vector of observed feature values for specified feature. Defaults to NULL.

densities

List of k density function; one per class. Flexible length, which must equal k.

p

Vector of class starting proportion estimates. Default is .2 for 5 classes.

maxiter

Maximum number of iterations of the EM algorithm allowed. Default is 2000.

conv

Convergence criteria for change in likelihood function. Change between

Value

A list containing the following components:

p = vector of 5 estimated mixing proportions for feature.

iter = number of iterations before algorithm converged or was stopped.

allp = (iter x 5) data frame containing all phat iterated estimates.

logl = Vector of log-likelihood values, with one log-lik value for each iteration.

Author(s)

Jennifer Starling

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Define ctrl object.
em <- emCalcMix(f_sample,densities,p=rep(.2,5),maxiter=1000,conv=.00001)

##Sample density function:
f_class1 = df[df$class=="eb",f_name]
<c2><a0> <c2><a0> 	kd1 <c2><a0>= density(f_class1)
<c2><a0> <c2><a0> 	dens1 = function(x)
	{
		min_den <- quantile(kd1$y,.05)
		de <- approx(kd1$x,kd1$y,x)$y
		de[is.na(de)] <- min_den
		return(de)
	}

jstarling1/starlib documentation built on May 20, 2019, 2:12 a.m.