# Many similar models - Part 1: How to make a function for model fitting

In this post I discuss how to construct the formula that can be passed to model fitting functions like lm(). I then demonstrate how to use this within a user-created function in order to streamline the process of fitting many similar models.

# The small multiples plot: how to combine ggplot2 plots with one shared axis

There are a variety of ways to combine ggplot2 plots with a single shared axis, but things can get tricky if you want a lot of control over all plot elements. I show three approaches to make such a plot: using facets, with package cowplot, and with package egg.

# Embedding subplots in ggplot2 graphics

I first learned about embedding many small subplots into a larger plot as a way to visualize large datasets with package ggsubplot. Embedding subplots is still possible in ggplot2 today with the annotation_custom() function. I demonstrate one approach to do this, making many subplots in a loop and then adding them to the larger plot.

# Custom contrasts in emmeans

One of the nice things about emmeans is that you can build custom comparisons for any groups or combinations of groups. I give an example showing how to set these up.

# Getting started with emmeans

Post hoc comparisons are made easy in package emmeans. This post goes through some of the basics for those just getting started with the package.

# Lots of zeros or too many zeros?: Thinking about zero inflation in count data

When working with counts, having many zeros does not necessarily indicate zero inflation. I demonstrate this by simulating data from the negative binomial and generalized Poisson distributions. I then show one way to check if the data has excess zeros compared to the number of zeros expected based on the model.

# How to plot fitted lines with ggplot2

I show a general approach for plotting fitted lines with ggplot2 that works across many different model types.

# Analysis essentials: An example directory structure for an analysis using R

I go through an example of the directory structure I used to organize my data, analysis scripts, and outputs for a recent collaborative analysis I did using R.

# The log-0 problem: analysis strategies and options for choosing c in log(y + c)

Analyzing positive data with 0 values can be challenging, since a direct log transformation isn't possible. I discuss some of the things to consider when deciding on an analysis strategy for such data and then explore the effect of the value of the constant, c, when using log(y + c) as the response variable.

# Getting started simulating data in R: some helpful functions and how to use them

Here is the written version of a talk I gave at the Eugene R Users Group.

# Automating exploratory plots with ggplot2 and purrr

In this post I show an example of how to automate the process of making many exploratory plots in ggplot2 with multiple continuous response and explanatory variables. To loop through both x and y variables involves nested looping. In the latter section of the post I go over options for saving the resulting plots, either together in a single document, separately, or by creating combined plots prior to saving.

# Creating legends when aesthetics are constants in ggplot2

Getting a legend in ggplot2 when the aesthetic value is set to be constant instead of a variable can be tricky. I go through an example of a situation where this might be useful and show how to first get a legend and then how to "prettify" that legend.

# Simulate! Simulate! - Part 3: The Poisson edition

Extending my simulation examples into the world of generalized linear models, I simulate Poisson data to explore what a quadratic relationship looks like on the scale of the data when fitting a generalized linear model with a log link.

# Time after time: calculating the autocorrelation function for uneven or grouped time series

Checking for autocorrelation must be done carefully when some observations are missing from a time series or the time series is measured for independent groups. I show an approach where I pad the dataset with NA via tidyr::complete() to fill in any missed sampling times and make sure groups are considered independent prior to calculating the autocorrelation function.

# A closer look at replicate() and purrr::map() for simulations

In this post I delve into the details of the R functions I've been using in my simulation examples, focusing on the replicate() function and the map family of functions from the purrr package. I spend a little time showing the parallels between the replicate() function and a for() loop.

# Simulate! Simulate! - Part 2: A linear mixed model

In my second simulation example I show how to simulate data from a basic two-level hierarchical design. I go on to explore how well the random effects variance component is estimated for different sample sizes.

# Unstandardizing coefficients from a GLMM

Unstandardizing coefficients in order to interpret them on the original scale can be needed when explanatory variables were standardized to help with model convergence when fitting generalized linear mixed models. Here I show one approach to unstandardizing for a generalized linear mixed model fit with lme4.

# Making many added variable plots with purrr and ggplot2

In this post I show one approach for making added variable plots from a model with many continuous explanatory variables. Since this is done for every variable in the model, I show how to automate the process via functions from package purrr.

# Reversing the order of a ggplot2 legend

A quick example of reversing the legend order in a ggplot2 plot, which is done via guide_legend() instead of by changing the order of the levels in the dataset.

# Simulate! Simulate! - Part 1: A linear model

Where I discuss simulations, why I love them, and get started on a simulation series with a simple two-group linear model simulation. #### Ariel Muldoon

I currently work as a consulting statistician, advising natural and social science researchers on statistics, statistical programming, and study design. I create and teach R workshops for applied science graduate students who are just getting started in R, where my goal is to make their transition to a programming language as smooth as possible. See my workshop materials at my website.