R365: Day 19 – Jitter and Rug

Every once in a while you want to make your data just a little bit off, so that you can add some stochasticity to a model for example. {jitter} is a program that lets you add a uniformly distributed amount of variation to data. It uses runif() to add and subtract a little bit from your data. You can control how much “jitter” is in your data by altering the ‘factor’, the second portion of the jitter(x, factor, amount) program. You can also set it by adjusting the actual amount, which I think is taken as 1= completely different data. I talked about using jitter in other ways earlier on when I mentioned that jitter can be used to mimic variation that is typically seen in hand drawn lines, like in xkcd.com comic strips.

Rplot08 Rplot07 Rplot01

plot(jitter(a,1), main="Jitter with Factor 1")
 plot(jitter(a,10), main="Jitter with Factor 10")
 plot(jitter(a,100), main="Jitter with Factor 100")


At the bottom of the {jitter} vignette, they suggest checking out {rug}, which I had never heard of. The description of the function is a bit weird, it says, “Adds a rug representation (1-d plot) of the data to the plot”. Are we talking Persian here? Maybe something more modern?

After puttering around with {rug} for a while, it seems to show where your data is condensed on one axis, by default the x-axis. This could be useful if you wanted to have a visualization for when things typically occur. The example they give in the vignette uses the {faithful} dataset, which records the waiting and erupting times for Old Faithful Geyser in Yellowstone National Park, and shows that most of the eruptions fall into one of two groups. I am not sure I really like {rug} because while it does condense data, it also loses data. It also is not any sort of statistical tool (as far as I can tell), so it won’t give you useful summary statistics. Also, Vernon, if you are reading this, Mode 4 Lyfe!



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s