# Find threshold for time varying samples

I have a df containing samples of a time varying quantity (namely, exposure to electromagnetic field generated by a GSM station), and I use the mixtools package to find a fitting mixture model (tipically, a 2- or 3-component guassian mixture) because I assume that (or rather, want to test if) samples come from different pdf's based on the hour of the day (e.g., with larger mean during peak hours and lower ones during off-peak hours).

It seems to me that normalmixEM function included in the package does not return any threshold values that can be used to assign samples to the various distributions: how can I achieve that?

Should that function be unavailable in the mixtools package, could you please point me to a more general tool that would help me clustering values, also considering that it should make its own initial guess of the threshold values?

Many thanks! Nicola

The Gaussian mixture distribution is defined as

$$p(x) = \sum_{i=1}^k \; \lambda_i \,\mathcal{N}(x | \mu_i, \sigma_i^2)$$

where $$\lambda_i \in (0, 1)$$ is the mixing weight and $$\mu_i, \sigma_i^2$$ are the parameters for the $$i$$-th component. Writing it differently, if we use $$Z$$ to denote class membership, then we can write this as

$$p(x) = \sum_{i=1}^k \; p(x|Z=i)\; p(Z=i)$$

where $$p(x|Z=i)$$ is $$\mathcal{N}(x | \mu_i, \sigma_i^2)$$, and $$p(Z=i)=\lambda_i$$, and this is just the law of total probability. Notice that you could just use Bayes theorem to obtain

$$p(Z=i|x) = \frac{p(x|Z=i)\; p(Z=i)}{\sum_{j=1}^k \;p(x|Z=j)\; p(Z=j)} = \frac{\lambda_i \,\mathcal{N}(x | \mu_i, \sigma_i^2)}{\sum_{j=1}^k \; \lambda_j \,\mathcal{N}(x | \mu_j, \sigma_j^2)}$$

All the information needed is there in the object returned by this function, since it returns the lambda, mu, and sigma parameters. Given the probabilities, you can make assignments to clusters.

You can check this example from Wikipedia describing EM algorithm for estimating parameters of Gaussian mixture distribution for more details.

I would use the ggplot2 package in R to plot either a k-means or a mean shift. Your hypothesis seems to suggest that you expect 2 clusters(?) (peak hours, non-peak hours) these plots would help show that.

For an introduction to ggplot2, start here

• ggplot2 might be a freaking great plotting package but I wasn't aware it did k-means clustering Commented Jun 19, 2015 at 17:43
• you're right-it doesn't, R's stats package handles that.
– Alexander Sobin
Commented Jun 19, 2015 at 17:58