quadratic_trajectory

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(OLStrajr)

Introduction

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.

Displaying the rats Dataset

data(rats)
print(rats)

Plotting Linear Trajectories

# 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)

Plotting Quadratic Trajectories

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

Plotting Linear & Quadratic Trajectories

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.



Try the OLStrajr package in your browser

Any scripts or data that you put into this service are public.

OLStrajr documentation built on July 9, 2023, 5:30 p.m.