knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(OLStrajr)
The OLStrajr package in R, designed as an adaptation of the OLStraj SAS macro reported in Carrig, Wirth, and Curran (2004), facilitates the generation of individual level plots. These plots can depict linear, quadratic, or both ordinary least squares (OLS) estimated trajectories, superimposed on the original data.
In the following demonstration, we use the rats dataset (for details, see ?OLStrajr::rats), which originates from Rogosa & Saner (1995). We will explore how the 'regtype' parameter of OLStraj can be used to study linear, quadratic, or both OLS-estimated trajectories.
data(rats) print(rats)
# Run OLS traj rats_lin <- OLStraj(data = rats, idvarname = "Rat", predvarname = "Week", outvarname = "Weight", varlist = c("t0", "t1", "t2", "t3", "t4"), timepts = c(0, 1, 2, 3, 4), regtype = "lin", int_bins = 3, lin_bins = 3) # Show linear trajectories rats_lin$individual_plots
Note: The cbc_lm vignette transforms the robbins data from wide to long format to run case-by-case regression. However, for models with a single independent variable, you can also obtain the cbc_lm output directly from the OLStraj results.
print(rats_lin$models)
OLStraj(data = rats, idvarname = "Rat", predvarname = "Week", outvarname = "Weight", varlist = c("t0", "t1", "t2", "t3", "t4"), timepts = c(0, 1, 2, 3, 4), regtype = "quad", int_bins = 3, lin_bins = 3)$individual_plots
In the resulting plots, the quadratic trajectory is depicted by a dashed line while the linear trajectory is represented by a solid line.
OLStraj(data = rats, idvarname = "Rat", predvarname = "Week", outvarname = "Weight", varlist = c("t0", "t1", "t2", "t3", "t4"), timepts = c(0, 1, 2, 3, 4), regtype = "both", int_bins = 3, lin_bins = 3)$individual_plots
The power of OLStrajr lies in its ability to quickly visualize the different approximations of the OLS trajectories. The package aids in the understanding of complex trends in the data and provides a solid base for further statistical analysis and interpretation.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.