Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/helper_functions.R

Find a density peak in the provided vector of values and return the lower and upper bounds around that peak.

1 |

`data` |
Vector of numbers. |

`width` |
The returned lower and upper bounds for the peak are calculated based on how much larger is the difference between the values at the "i"" and "i + faction size" index of sorted data is; i is itterated from the index of the most dense region to the left (for lower bound) and to the right (for upper bound), which increases the above mentioned difference as the region is becomming less dense. The itteration is stopped when the difference gets larger than the minimum difference times 1/width. This means, by default with width = 0.5, the difference can reach double the minimum difference. |

`fraction` |
How large is the proportion of values that we look at when distances as mentioned above. By default with fraction = 0.1, we look at 10% of values. |

This functions finds a density peak in the provided vector of values and returns the lower and upper bounds around that peak. First, we sort the input data, let's call it x, and look at a fraction of values at a time. Say we have 1,000 values in our input vector and fraction is 0.1 (10%), meaning we look at regions spanning 100 values. We will find the most dense region by itterating the possible starting index from 1 to 899 and minimizing the difference between the sorted values at potential starting index and corresponding ending index (100 values apart). Finding the minimum difference equals to finding the most dense region. Next we find the lower and upper bounds for the peak based on how much larger is the difference between the values at the "i"" and "i + faction size" index of sorted data is; i is itterated from the index of the most dense region to the left (for lower bound) and to the right (for upper bound), which increases the above mentioned difference as the region is becomming less dense. The itteration is stopped when the difference gets larger than the minimum difference times 1/width. This means, by default with width = 0.5, the difference can reach double the minimum difference.

A list with 2 components, "lo" and "hi", identifying the lower and the upper bounds for the peak.

Wayne Moore, Faysal El Khettabi, Josef Spidlen

1 |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.