1
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ ggplot2 might be a freaking great plotting package but I wasn't aware it did k-means clustering $\endgroup$ Jun 19 '15 at 17:43
  • $\begingroup$ you're right-it doesn't, R's stats package handles that. $\endgroup$
    – Alexander Sobin
    Jun 19 '15 at 17:58
  • $\begingroup$ You might want to add that to your answer... $\endgroup$ Jun 19 '15 at 18:00
  • 1
    $\begingroup$ Thank you all for your answers and comments. I have looked at k-means and mean shift as suggested, but it seems that they are meant for n-dimensional problems, with n >=2, while mine is a 1D one, as I have only one variable (exposure levels). Searching the internet, I found that such problems would be classified as segmentation or natural breaks problems (see, for example this answer ). Based on your experience, which package would you use? $\endgroup$ Jun 22 '15 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.