This vignette unpacks how to find interesting individuals.

Let’s say we calculate a slope for each individual key, using keys_slope():

This is neat! But now we want to know those keys that are nearest to some set of summary statistics of the slope. By nearest here we mean which values have the smallest numerical difference.

Let’s say the five number summary:

If want to find those individuals that have slopes near these values.

We can do this using keys_near(), which returns those nearest to some summary statistics. In this case, it is the five number summary. In the next section we describe how you can provide your own named list of functions to use.

We can then join this information back against the data and plot those interesting individuals:

You could also, with a bit of work, show these lines against the background using gghighlight

Specify your own summaries for keys_near

You can specify your own list of summaries to pass to keys_near. For example, you could create your own summaries to give a sense of range. Note that the functions here start with b_, and are b_summaries provided by brolgar that have sensible defaults. You can read about them here, or with ?b_summaries

Implementation of keys_near

If you are interested in the specifics of how keys_near() works, this section describes how it is implemented in brolgar.

To get the data into the right format, there are a few steps.

First, we need to get the data into a format where we have all the statistics that we are interested in, along with the id, and the statistic of interest.

We can fit a linear model for each key in the dataset using key_slope().

We can then perform a summary of the statistic of interest, in this case the slope.

We then need to convert this into long format

We can then calculate the difference between each stat and the slope, .slope_xp:

With stats diff, we can then group by the stat, and find return those rows with the smallest difference between the statistic and the value:

We can see that we get the same output using keys_near():