Gaussian mixture model

Gaussian mixture model

Value

An R6 object of class gaussianMixture.

Details

R6 class for fitting and storing a univariate Gaussian mixture model.

Applied after updating the parameters

Note

Version 1.0.2

Public fields

control

List to contain custom control parameters.

maxit

Integer, maximum number of iterations.

maxrestarts

Integer, maximum number of restarts.

abstol

Numeric, absolute level for convergence.

components

Integer, number of mixture components.

method

Character, package used for fitting.

Active bindings

means

Numeric vector containing the location parameter for each component.

sd

Numeric vector containing the scale parameter for each component.

p

Numeric vector containing the probability for each component.

coefficients

named list with mixture coefficients.

std.errors

named list with mixture parameters.

model

Tibble with mixture parameters, in order means, sd, p.

loglik

log-likelihood of the fitted series.

fitted

fitted series

responsabilities

resp

moments

Tibble with the theoric moments and the number of observations used for fit.

tidy

Tibble with estimated parameters, std.errors and statistics

Methods


Method new()

Initialize a gaussianMixture object.

Usage

gaussianMixture$new(
  components = 2,
  method = "mixtools",
  maxit = 5000,
  maxrestarts = 500,
  abstol = 1e-08
)

Arguments

components

(integer(1)), number of components.

method

Character, package used to fit the parameters. Can be mclust or mixtools.

maxit

(integer(1)) Numeric, maximum number of iterations.

maxrestarts

(integer(1)) Numeric, maximum number of restarts.

abstol

(numeric(1)) Numeric, absolute level for convergence.


Method set_time_series()

Set the time series internally

Usage

gaussianMixture$set_time_series(x, weights)

Arguments

x

vector

weights

observations weights, if a weight is equal to zero the observation is excluded, otherwise is included with unitary weight.


Method logLik()

Compute the log-likelihood.

Usage

gaussianMixture$logLik(x, params, per_obs = FALSE)

Arguments

x

vector

params

Optional. Named list with mixture parameters.

per_obs

Logical, when TRUE the log-likelihood is returned per observation, otherwise is summed.


Method E_step()

Compute the posterior probabilities (E-step),

Usage

gaussianMixture$E_step(x, params)

Arguments

x

Time series to fit.

params

A named list with mixture parameters.


Method classify()

Classify the time series in the components with highest likelihood.

Usage

gaussianMixture$classify(x)

Arguments

x

Time series to fit.


Method fit()

Fit the parameters with mclust package

Usage

gaussianMixture$fit(x, weights, mu_target = NA, var_target = NA)

Arguments

x

vector

weights

observations weights, if a weight is equal to zero the observation is excluded, otherwise is included with unitary weight.

mu_target

Numeric, target mean of the mixture to match.

var_target

Numeric, target variance of the mixture to match. When missing all the available observations will be used.


Method EM()

Fit the parameters (EM-algorithm)

Usage

gaussianMixture$EM(x, weights)

Arguments

x

vector

weights

observations weights, if a weight is equal to zero the observation is excluded, otherwise is included with unitary weight. When missing all the available observations will be used.


Method update()

Update the parameters inside the object.

Usage

gaussianMixture$update(means, sd, p)

Arguments

means

Named vector, new means parameters.

sd

Named vector, new std. deviation parameters.

p

Named vector, new probabilities.


Method update_logLik()

Update the log-likelihood with the current parameters

Usage

gaussianMixture$update_logLik()


Method filter()

Update the responsibilities, the log-likelihood, classify again the points and recompute empiric parameters.

Usage

gaussianMixture$filter()


Method Hessian()

Hessian matrix gaussianMixture class.

Usage

gaussianMixture$Hessian()


Method print()

Print method for gaussianMixture class.

Usage

gaussianMixture$print(label)

Arguments

label

Character, optional label.


Method clone()

The objects of this class are cloneable with this method.

Usage

gaussianMixture$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

gm <- gaussianMixture$new(components = 2)
gm$update(
  means = c(mu1 = -1, mu2 = 1),
  sd = c(sd1 = 0.5, sd2 = 1),
  p = c(p1 = 0.4, p2 = 0.6)
)
gm$coefficients
#> $means
#> mu1 mu2 
#>  -1   1 
#> 
#> $sd
#> sd1 sd2 
#> 0.5 1.0 
#> 
#> $p
#>  p1  p2 
#> 0.4 0.6 
#> 
gm$moments
#> # A tibble: 1 × 12
#>      m1    m2    m3    m4   mu2   mu3   mu4  mean variance skewness kurtosis
#>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>    <dbl>
#> 1   0.2   1.7   1.7  7.08  1.66 0.696  6.12   0.2     1.66    0.325   -0.780
#> # ℹ 1 more variable: nobs <int>