4
$\begingroup$

Following some discussions with colleagues, I'm seeking for clarification on how to visualize an ANCOVA with visreg, and what the visualization actually shows.

I would like to run the following ANCOVA (data are at the end of this post), and then visualize the effect of "Treatment" on "Infection.Frequency" using visreg:

model <- lm(Infection.Frequency ~ Replicate + Treatment  + Size, d)
visreg(model,"Treatment")

enter image description here

My questions:

  1. At default, visreg plots 'conditional' plots. Instead, one can also plot 'contrast' plots like this: visreg(model,"Treatment",type="contrast")

    I'd like to get some input whether you would show a conditional plot in a publication to visualize the effect of 'Treatment', or rather the "contrast" plot? Why?

  2. I don't understand what the gray dots are in the conditional plot. These dots cannot represent the raw data, as some values are below zero but the raw values are all between 0 and 1.

    2.1 What do the gray dots show?

    2.2 Would you see a problem to instead underlie the model result with the real (raw) data? How would I plot the raw data instead?

  3. At default, visreg plots the 95% CI (gray shading), while other plotting packages (e.g., the "effects" R-package) plot SE instead at default. What makes more sense in your opinion?

  4. Assuming that the conditional plot would be good to visualize the effect of 'Treatment' (i.e., visreg(model,"Treatment")), how would you describe in a respective figure legend what is shown? Something like: "Depicted is the partial effect of Treatment on infection frequency. Blue lines depict XXXX surrounded by 95% CI (gray shading), with gray dots indicating XXXX."

Here are my data:

structure(list(ID = 1:486, Replicate = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 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L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("no", 
    "yes"), class = "factor"), Size = c(157.65, 145, 142.12, 
    142.35, 133.67, 146.48, 141.47, 135.46, 136.47, 132.8, 133.24, 
    141.34, 156.35, 131.81, 131.4, 135.62, 129.79, 130.99, 134.72, 
    153.48, 156.83, 129.47, 128.13, 133.72, 129.6, 160.32, 129.17, 
    159.64, 167.23, 152.78, 154, 151.81, 151.21, 145.42, 163.38, 
    162.8, 150.93, 156.2, 156.9, 155.25, 147.39, 162.33, 158.37, 
    150.96, 154.25, 161.04, 147.95, 151.35, 155.35, 150.04, 147.13, 
    149.74, 144.59, 155.81, 152.91, 163.86, 146.12, 154, 162.63, 
    152.78, 160.11, 157.81, 156.62, 151.18, 154.18, 161.27, 163.64, 
    155.37, 154.68, 155.28, 150.9, 150.68, 151.49, 157.76, 162.57, 
    153.54, 151.26, 147.88, 146.09, 146.54, 146.1, 145.68, 148.76, 
    143.8, 143.7, 139.64, 159.69, 155.51, 158.86, 156.24, 154.67, 
    161.87, 159.43, 156.01, 165.73, 156.3, 156.07, 154.9, 153.87, 
    151.69, 158.87, 160.65, 147.2, 156.32, 149.1, 149.55, 148.83, 
    151.35, 150.13, 154.37, 150.16, 163.96, 163.37, 162.64, 161.89, 
    161.73, 154.09, 154.89, 160.17, 162.48, 163.28, 155.78, 157.08, 
    149.99, 153.39, 150.38, 153.22, 149, 158.33, 153.65, 156.59, 
    153.42, 158.14, 147.56, 145.88, 150.83, 148.53, 140.33, 156.79, 
    152.05, 158.9, 159.38, 162.26, 155.06, 155.76, 147.85, 153.98, 
    160.62, 156.08, 144.76, 141.77, 152.68, 144.41, 144.87, 145.02, 
    143.98, 143.72, 162.94, 137.3, 134.55, 139.03, 136.46, 137.81, 
    132.84, 132.57, 132.76, 159.84, 167.01, 158.79, 163.68, 157.71, 
    152.31, 161.27, 160.11, 156.96, 165.69, 144.63, 155.6, 153.83, 
    161.22, 158.13, 154.06, 156.89, 157.31, 158.42, 158.33, 151.99, 
    153.59, 147.73, 159.22, 165.05, 153.33, 156.68, 149.17, 145.81, 
    149.65, 147.82, 147.48, 140.48, 142.58, 157.15, 162.69, 154.92, 
    161.11, 157.05, 159.73, 160.97, 159.83, 150.19, 149.75, 155.63, 
    151.99, 152.68, 157.09, 150.15, 155.54, 149.04, 149.41, 147.51, 
    156.42, 143.8, 151.34, 144.5, 146.57, 147.09, 138.36, 149.88, 
    160.64, 154.98, 163.59, 153.95, 158.39, 165.91, 164.23, 161.06, 
    158.33, 153.13, 160.46, 146.19, 147.85, 141.79, 156.88, 164.38, 
    159.07, 159.4, 150.57, 145.56, 142.46, 146.27, 147.79, 153.58, 
    146.41, 149.66, 137.71, 136.2, 160.72, 140.54, 126.43, 142.06, 
    127.99, 132.91, 145.9, 141.6, 151.76, 158.83, 156.66, 155.05, 
    153.76, 151.65, 149.41, 156.94, 156.89, 155.34, 141.51, 149.79, 
    150.4, 151.48, 153.33, 157.49, 157.28, 162.08, 151.3, 154.16, 
    150.62, 162.96, 166.48, 146.1, 155.47, 159.12, 160.27, 162.02, 
    148.22, 146.11, 151.94, 139.32, 146.76, 155.41, 136.2, 139.78, 
    133.53, 143.86, 138.02, 145.07, 135.91, 136.86, 131.58, 144, 
    134.32, 153.05, 162.54, 155.41, 162.58, 155.3, 163.16, 157.23, 
    150.75, 152.19, 152.6, 152.43, 150.21, 151.53, 150.8, 146.46, 
    146.2, 152.01, 146.78, 149.46, 146.59, 143.8, 145.13, 139.27, 
    135.42, 134.04, 130.73, 160.81, 155.78, 163.16, 159.74, 160.68, 
    155.54, 157.87, 155.35, 160.49, 155.59, 156.26, 152.39, 148.83, 
    161.35, 150.9, 157.71, 156.31, 156.6, 154.77, 142.44, 141.99, 
    155.9, 150.95, 147.17, 141.63, 141.03, 146.07, 156.74, 152.76, 
    156.66, 150.5, 148.39, 166.19, 162.73, 157.39, 152.46, 159.62, 
    151.22, 149.21, 147.35, 151.54, 145.67, 156.06, 143.3, 155.18, 
    139.14, 155.19, 163.97, 146.69, 149.62, 144.95, 138.92, 143.2, 
    129.25, 143.79, 141.64, 140.74, 141.38, 137.68, 140.43, 130.33, 
    134.52, 157.68, 136.02, 136.46, 137.57, 140.55, 133.57, 151.01, 
    148.56, 158.66, 161.24, 150.6, 159.28, 152.83, 152.79, 157.07, 
    158.08, 159.66, 154.62, 150.8, 157.01, 162.5, 158.37, 140.15, 
    157.62, 143.56, 147.63, 165.17, 160.16, 145.13, 159.51, 149.09, 
    145.65, 148.72, 142.57, 152.57, 138.88, 152.07, 153.03, 166.66, 
    158.92, 165.65, 163.69, 162.44, 157.61, 160.84, 163.3, 159.72, 
    152.97, 164.64, 158.04, 158.01, 153.76, 153.1, 155.84, 159.64, 
    145.36, 160.56, 147.04, 147.35, 156.84, 154.37, 149.9, 156.72, 
    146.95, 155.63, 141.59, 147.37, 164.76, 161.8, 160.5, 155.13, 
    154.33, 150.87, 152.64, 159.85, 154.68, 153.07, 150.23, 151.85, 
    152.05, 150.59, 142.87, 139.43, 143.72, 141.89, 141.62, 140.03, 
    133.78, 132.09, 138.19), Infection.Frequency = c(0.283730159, 
    0.677655678, 0.284090909, 0.176948052, 0.170995671, 0.170995671, 
    0.170995671, 0.254329004, 0.282106782, 0, 0.043927064, 0.170995671, 
    0.513257576, 0, 0.2263178, 0.300595238, 0.005952381, 0, 0.12195122, 
    0.385551948, 0.313852814, 0.113636364, 0.300757576, 0.076923077, 
    0.013704319, 0.581349206, 0, 0.590638528, 0.47481685, 0.071428571, 
    0.200757576, 0.170995671, 0.105263158, 0.184615385, 0.504329004, 
    0.486471861, 0.15, 0.25, 0.196428571, 0, 0.142857143, 0.170995671, 
    0.170995671, 0.111111111, 0.254329004, 0.320757576, 0.011363636, 
    0.073051948, 0.542919799, 0.431818182, 0, 0, 0.070422535, 
    0.073051948, 0.244047619, 0.273809524, 0.19047619, 0.494875223, 
    0.170995671, 0.170995671, 0.608766234, 0.318404635, 0.44047619, 
    0.25, 0.611471861, 0.585227273, 0.102813853, 0.011494253, 
    0, 0.102813853, 0.073051948, 0.352813853, 0.333333333, 0.426564027, 
    0.438852814, 0.041666667, 0.064814815, 0, 0.443722944, 0.108108108, 
    0.009009009, 0.086956522, 0.273809524, 0.288059163, 0.12797619, 
    0.170995671, 0.005952381, 0.442307692, 0.117063492, 0.273559774, 
    0.504578755, 0.323051948, 0.554924242, 0.385281385, 0.428030303, 
    0.420995671, 0, 0.602813853, 0.420995671, 0.494047619, 0.237794613, 
    0.450757576, 0.170995671, 0.112676056, 0.198051948, 0.133333333, 
    0.170995671, 0.193548387, 0.422979798, 0.233333333, 0, 0.226898102, 
    0.4375, 0.170995671, 0.54788961, 0.44047619, 0.416666667, 
    0.4375, 0.053191489, 0.477813853, 0.073051948, 0.357534707, 
    0.420995671, 0.22362725, 0.370995671, 0.006993007, 0.348214286, 
    0.28, 0.181818182, 0.543019481, 0.370995671, 0, 0.401764902, 
    0.323051948, 0.25, 0, 0.375683527, 0.184615385, 0.323051948, 
    0, 0.489177489, 0.489718615, 0.663961039, 0.487662338, 0.177218615, 
    0.25, 0.237662338, 0.496031746, 0.244047619, 0, 0.153846154, 
    0.01, 0.480769231, 0.200757576, 0.073051948, 0.241246499, 
    0.44047619, 0.44047619, 0.522727273, 0.254329004, 0.170995671, 
    0, 0.088235294, 0.176948052, 0, 0.051406926, 0.244047619, 
    0.56871118, 0.567424242, 0.410714286, 0.323051948, 0.415960851, 
    0.41294245, 0.170995671, 0.628663004, 0.275162338, 0.058823529, 
    0.412608225, 0.218885281, 0.587662338, 0.029761905, 0.250757576, 
    0.310530555, 0.244047619, 0.270995671, 0.170995671, 0.425865801, 
    0.308823529, 0.013452915, 0, 0.25, 0.038461538, 0.050632911, 
    0.200757576, 0.037313433, 0.220995671, 0, 0.016683023, 0.02739726, 
    0, 0.323051948, 0.661283892, 0.261904762, 0.431526807, 0.448051948, 
    0.470238095, 0.459325397, 0.431526807, 0.352813853, 0.25, 
    0.504329004, 0.513257576, 0.229761905, 0.073051948, 0.600732601, 
    0.498168498, 0.284090909, 0.013333333, 0.525162338, 0.170995671, 
    0.005780347, 0, 0.337662338, 0.392857143, 0, 0.210211357, 
    0.170995671, 0.641233766, 0.275162338, 0.343614719, 0.369047619, 
    0.513528139, 0.323051948, 0.273809524, 0.671245421, 0.200757576, 
    0.433608059, 0.450757576, 0, 0.611471861, 0, 0.44047619, 
    0.3125, 0.142857143, 0.170995671, 0.210526316, 0.45, 0.256313131, 
    0, 0.176948052, 0.205128205, 0.005952381, 0.573809524, 0.170995671, 
    0, 0.392857143, 0.126623377, 0, 0.022619048, 0, 0.337121212, 
    0, 0.013888889, 0.388528139, 0, 0.47797619, 0.44047619, 0.420995671, 
    0.545995671, 0.053571429, 0.451632926, 0.287714097, 0.311868687, 
    0, 0.420995671, 0, 0, 0.131875477, 0.420995671, 0.489718615, 
    0.513257576, 0.400757576, 0.406289789, 0.358495671, 0.2, 
    0.170995671, 0.406385281, 0.700757576, 0.597466259, 0.367424242, 
    0.25, 0.015873016, 0.005952381, 0.458333333, 0.170995671, 
    0, 0.420995671, 0.005952381, 0.048629829, 0.005952381, 0, 
    0.176948052, 0.170995671, 0, 0, 0.170995671, 0, 0, 0.25, 
    0.25, 0.190162907, 0.327380952, 0.200757576, 0.284090909, 
    0.551587302, 0.422619048, 0.163636364, 0.083333333, 0.188852814, 
    0.068965517, 0.039215686, 0.391233766, 0, 0.016129032, 0.195825799, 
    0, 0.028169014, 0.02, 0.220899471, 0.019230769, 0.047619048, 
    0, 0, 0.006711409, 0.660714286, 0.420995671, 0.326388889, 
    0.463528139, 0.19731146, 0.192307692, 0.532106782, 0.420995671, 
    0.636273449, 0, 0.313852814, 0.450757576, 0.420995671, 0.420995671, 
    0.153846154, 0.25, 0.65, 0.170995671, 0.715638528, 0.006622517, 
    0.082875458, 0.176470588, 0.263257576, 0.19047619, 0.005952381, 
    0.005952381, 0.170995671, 0.113207547, 0.641233766, 0.420995671, 
    0.470238095, 0.44047619, 0.367424242, 0.571428571, 0.01826484, 
    0.385281385, 0.19047619, 0.235294118, 0.25, 0.010638298, 
    0.613095238, 0.337662338, 0.358652313, 0.084745763, 0.331349206, 
    0.44047619, 0.529761905, 0.201028139, 0.343614719, 0.029761905, 
    0.498506023, 0.239219114, 0.472582973, 0.273809524, 0.026315789, 
    0.176948052, 0.068223443, 0.43452381, 0.19047619, 0.071428571, 
    0.222069597, 0.306709957, 0.029761905, 0, 0.575396825, 0.200757576, 
    0.246212121, 0.200757576, 0.027777778, 0.410714286, 0.561904762, 
    0.285714286, 0.090909091, 0.398214286, 0.009615385, 0.1754329, 
    0.083333333, 0.042857143, 0.273809524, 0.587662338, 0.170995671, 
    0.301587302, 0.25, 0.076923077, 0.013333333, 0.69534632, 
    0, 0, 0.384920635, 0.395400433, 0, 0.06122449, 0.3, 0, 0.015748031, 
    0.361471861, 0.41504329, 0, 0.170995671, 0.179166667, 0.418019481, 
    0.170995671, 0.388528139, 0.391233766, 0.024691358, 0.220238095, 
    0.361471861, 0.613095238, 0.206709957, 0, 0.550757576, 0.541666667, 
    0.04, 0.079545455, 0.043478261, 0.073051948, 0.041666667, 
    0.244047619, 0.200757576, 0.029761905, 0.361471861, 0.184163059, 
    0.291666667, 0.164383562, 0.361471861, 0.235240334, 0.443722944, 
    0.037037037, 0.276258829, 0.632575758, 0.361471861, 0, 0.43452381, 
    0.667027417, 0.43452381, 0.19047619, 0.422979798, 0.073051948, 
    0.513528139, 0.404761905, 0.491233766, 0.542919799, 0.311868687, 
    0, 0.553051948, 0.073051948, 0, 0.498971861, 0.200757576, 
    0.282106782, 0.170995671, 0.272186147)), row.names = c(NA, 
486L), class = "data.frame")
$\endgroup$
2
  • $\begingroup$ What is "replicate"? Are these repeated measures data? $\endgroup$ Apr 21, 2021 at 13:23
  • $\begingroup$ Sorry, I just deleted part of my post by mistake. But it's there again. – 'Replicate' is simply a replicate of the Treatment. Think of of a paired design in which there are 2 x 4 enclosures. You can think of "replicate" as 'Blocks' (N = 4), each of which has 2 enclosures with treatment "yes" and "no". $\endgroup$
    – 8armed
    Apr 21, 2021 at 13:45

2 Answers 2

4
$\begingroup$

The paper by Patrick Breheny and Woodrow Burchett (the authors of visreg) discuss all the issues raised in your question. Before I go into the specific questions, let's review what conditional and contrast plots show, respectively.

The conditional plot answers the question:

What is the relationship between $\mathrm{E}(Y)$ and $X_j$ (i.e. the predictor of interest), when we fix the other predictors in the model at some specific values, i.e. $\mathrm{x}_{-j}=\mathrm{x}^{*}_{-j}$?

The contrast plot answers the question:

How do changes in $X_j$ relative to a reference value $x^{*}_j$ affect $\mathrm{E}(Y)$?

One crucial difference is that the conditional plot requires specification of some $\mathrm{x}^{*}_{-j}$, whereas the contrast plot does not. As you haven't specified some values, visreg will do it for you (from the help page of the visreg function, emphasis mine):

If 'conditional' is selected, the plot returned shows the value of the variable on the x-axis and the change in response on the y-axis, holding all other variables constant (by default, median for numeric variables and most common category for factors).

You can specify your own values using the argument cond. There are some examples at the bottom of this answer.

As an advantage, the conditional plot is on the scale of the original variable $Y$ whereas the contrast plot is not.

Now to answer your questions:

1: It's up to you to decide: Look at the questions that both plots answer and decide what's most appropriate for your specific question.

2.1: The gray dots are partial residuals. They are defined as $r_j=r + \mathrm{x}_j\widehat{\beta}_j$, where $j$ denotes the variable of interest and $r$ are the residuals from the model. In the conditional plot, they are: $r_j=r+x_j\widehat{\beta}_j + \mathrm{x}_{-j}^{*}\widehat{\beta}_{-j}$.

2.2: Plotting the raw data makes little sense to me because you're looking at an effect of a variable of interest while the other variables are fixed to some values. In the raw data, the other variables are not fixed to some arbitrary value so that there could be a disconnect between the raw data and the plots.

3: Both visualize some kind of precision around the plotted estimate. Personally, I find the standard errors hard to interpret and prefer confidence intervals.

4: You could write something like: "Predicted infection frequency for 'treatment' and 'no treatment' (blue lines) with corresponding 95%-confidence intervals (gray bands) and partial residuals (gray dots). The depicted effects for Treatment are for Replicate 'C' and a Size of '152.46'."

Very important to note: Because you don't include an interaction term, the difference between 'treatment' and 'no treatment' is always going to be the same, regardless of what values the other predictors are fixed at (confidence intervals will differ, though). This difference is what the contrast plot shows. Try running the following:

visreg(mod, "Treatment", type = "conditional", cond = list(Size = 100, Replicate = "B"))
visreg(mod, "Treatment", type = "conditional", cond = list(Size = 100, Replicate = "A"))
visreg(mod, "Treatment", type = "conditional", cond = list(Size = 200, Replicate = "A"))
visreg(mod, "Treatment", type = "conditional", cond = list(Size = 200, Replicate = "B"))

All that's changing are the values on the y-axis and the widths of the confidence intervals. The difference between the predicted effects will stay the same.

$\endgroup$
2
  • 1
    $\begingroup$ Oh, that's a fantastic answer. Thank you a lot. I will let this all sink in and will ask again, in case something will remain unclear then. $\endgroup$
    – 8armed
    Apr 21, 2021 at 14:48
  • $\begingroup$ @8armed, if you think COOLSerdash's post has answered your question, please consider upvoting it (by clicking the upwards triangle at its left top &/or accepting it (by clicking the check mark below the vote total). $\endgroup$ Apr 21, 2021 at 21:58
3
$\begingroup$

I'm not a huge fan of such plots for presentation. You have one continuous covariate and one continuous response variable, so it's easy to make a scatterplot. Use different symbols and colors to indicate the groups. Then draw the model fit over the data. Because you have no interactions, there is only one slope for all lines. You arguably have 8 different intercepts / lines, because you have 2 (treatment) X 4 (replication) combinations. However, I gather the replications are a nuisance variable, so you can plot just two lines and average over the 4 possible replication intercepts. Remember that only the intercept for the control - replication A is explicitly given; the others need to be computed as the sum of the reference level intercept and the indicated mean difference. That yields the plot below:

d = structure(list(ID = 1:486, Replicate = structure(c(1L, 1L, 1L, 
                   ...
                   0.282106782, 0.170995671, 0.272186147)), row.names = c(NA, 
                   486L), class = "data.frame")

model <- lm(Infection.Frequency ~ Replicate + Treatment  + Size, d)
summary(model)
# ...
# Coefficients:
#                Estimate Std. Error t value Pr(>|t|)    
# (Intercept)  -1.1535131  0.1355653  -8.509 2.26e-16 ***
# ReplicateB    0.0157737  0.0228894   0.689    0.491    
# ReplicateC   -0.0020325  0.0219511  -0.093    0.926    
# ReplicateD    0.0156909  0.0223565   0.702    0.483    
# Treatmentyes -0.0773390  0.0156616  -4.938 1.09e-06 ***
# Size          0.0095294  0.0008997  10.591  < 2e-16 ***
# ...
# Residual standard error: 0.1713 on 480 degrees of freedom
# Multiple R-squared:  0.2133,  Adjusted R-squared:  0.2051 
# F-statistic: 26.03 on 5 and 480 DF,  p-value: < 2.2e-16

windows()
  plot(Infection.Frequency ~ Size, d, pch=as.numeric(d$Replicate),
       col=ifelse(d$Treatment=="yes", "blue", "red"))
  baseline = sum(rep(coef(model)[1:4], times=c(4,1,1,1)))/4
  abline(a=baseline,                b=coef(model)[6], lwd=2, col="red")
  abline(a=baseline+coef(model)[5], b=coef(model)[6], lwd=2, col="blue")
  legend("topleft", bty="n", col=rep(c("red","blue"), each=5),
         pch=c(1,2,3,4,NA,1,2,3,4,NA), lwd=c(NA,NA,NA,NA,2,NA,NA,NA,NA,2),
         legend=c("A treat data", "B treat data", "C treat data", 
                  "D treat data", "treat model", 
                  "A ctrl data", "B ctrl data", "C ctrl data", 
                  "D ctrl data", "ctrl model"))

enter image description here

To me, this is much more informative. It is more in keeping with what the typical reader is expecting, and doesn't need extensive explanation. I can immediately see that the blue (treated) data are lower. I can see that there is a prominent floor effect and resulting heteroscedasticity (confirmed with other plots).

$\endgroup$

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.