Good things come in Summary graphs
With large numbers of observations, graphical displays of individual response profiles are of little use and investigators then commonly produce graphs showing average (mean) profiles for each treatment group along with some indication of the variation of the observations at each time point, in this case the standard error of mean
$$se = \frac{sd(x)}{\sqrt{n}}$$
This exercise is part of the course
Helsinki Open Data Science
Exercise instructions
- Create the summary data
BPRSS
with the mean and standard error of the variablebprs
- Glimpse the data
- Plot the mean profiles (with
geom_errorbar()
line commented out) - Uncomment the
geom_errorbar()
line and plot the mean profiles again - Note the considerable overlap in the mean profiles of the two treatment groups suggesting there might be little difference between the two groups in respect to the mean BPRS values
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# dplyr, tidyr & ggplot2 packages and BPRSL are available
# Number of weeks, baseline (week 0) included
n <- BPRSL$week %>% unique() %>% length()
# Summary data with mean and standard error of bprs by treatment and week
BPRSS <- BPRSL %>%
group_by(treatment, week) %>%
summarise( mean = "Change me!", se = "Change me!" ) %>%
ungroup()
# Glimpse the data
glimpse(BPRSS)
# Plot the mean profiles
ggplot(BPRSS, aes(x = week, y = mean, linetype = treatment, shape = treatment)) +
geom_line() +
scale_linetype_manual(values = c(1,2)) +
geom_point(size=3) +
scale_shape_manual(values = c(1,2)) +
#geom_errorbar(aes(ymin=mean-se, ymax=mean+se, linetype="1"), width=0.3) +
theme(legend.position = c(0.8,0.8)) +
scale_y_continuous(name = "mean(bprs) +/- se(bprs)")