Learn R Programming

gtx (version 0.0.8)

fitmix.r2: For finite mixture of univariate Gaussian densities, computes proportion of variance explained by the mixture labels.

Description

Computes the true R-squared if the mixture labels were known without error. Currently only works if all components have the same variance.

Usage

fitmix.r2(p, mu, sigma)

Arguments

p
Real vector of mixture proportions.
mu
Real vector of mixture component means.
sigma
Mixture component standard deviation, same for all components.

Value

The R-squared value for a (hypothetical) regression of data values onto mixture label, as a k level factor.

Examples

Run this code
xx <- fitmix.simulate(100, c(0.49, 0.42, 0.09), c(0, 1, 2), c(.3, .3, .3))

## additive model, common variance, Hardy--Weinberg
fit.a <- fitmix(xx, 3, maxit = 10, restarts = 3,
                sigma.common = TRUE, p.binomial = TRUE, mu.additive = TRUE)
fitmix.plot(xx, fit.a$p, fit.a$mu, fit.a$sigma)
fitmix.r2(fit.a$p, fit.a$mu, unique(fit.a$sigma))

Run the code above in your browser using DataLab