The Golden Standardise
An important effect we want to take notice is how the men who have higher BPRS values at the beginning tend to have higher values throughout the study. This phenomenon is generally referred to as tracking.
The tracking phenomenon can be seen more clearly in a plot of the standardized values of each observation, i.e., the values obtained by subtracting the relevant occasion mean from the original observation and then dividing by the corresponding visit standard deviation.
$$standardised(x) = \frac{x - mean(x)}{ sd(x)}$$
REMEMBER: In ggplot2
or dplyr
syntax, you generally do not need to "quote" variable names!
This exercise is part of the course
Helsinki Open Data Science
Exercise instructions
- Assign
week
as the grouping variable - Standardise the variable
bprs
- Glimpse the data now with the standardised
brps
- Plot the data now with the standardised
brps
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# dplyr, tidyr and ggplot2 packages and BPRSL are available
# Standardise the variable bprs
BPRSL <- BPRSL %>%
group_by("Change me!") %>%
mutate(stdbprs = "Change me!") %>%
ungroup()
# Glimpse the data
glimpse(BPRSL)
# Plot again with the standardised bprs
ggplot(BPRSL, aes(x = week, y = stdbprs, linetype = subject)) +
geom_line() +
scale_linetype_manual(values = rep(1:10, times=4)) +
facet_grid(. ~ treatment, labeller = label_both) +
scale_y_continuous(name = "standardized bprs")