superbToWide: superbToWide: Reshape long data frame to wide, suitable for...

View source: R/superbToWide.R

superbToWideR Documentation

superbToWide: Reshape long data frame to wide, suitable for superbPlot

Description

The function suberbToWide() is an extension to Navarro's WideToLong function with ample checks to make sure all is legit, so that the data is suitably organized for suberb. See \insertCitecgh21superb for more. Other techniques are available to transform long to wide, but many asked for it within superb.

Usage

superbToWide(
  data,
  id = NULL,
  BSFactors = NULL,
  WSFactors = NULL,
  variable = NULL
)

Arguments

data

Dataframe in long format

id

A column with unique identifiers per subject

BSFactors

The name(s) of the between-subject factor(s) as string(s)

WSFactors

The name(s) of the within-subject factor(s) as string(s)

variable

The dependent variable as string

Value

A wide-format data frame ready for superbPlot() or superbData(). All other variables will be erased.

References

\insertAllCited

Examples

library(ggplot2)
library(gridExtra)

# Example using the built-in dataframe Orange. 
superbToWide(Orange, id = "Tree", WSFactors = c("age"), variable = "circumference") 

# Optional: change column names to shorten "circumference" to "DV"
names(Orange) <- c("Tree","age","DV")
# turn the data into a wide format
Orange.wide <- superbToWide(Orange, id = "Tree", WSFactors = c("age"), variable = "DV") 

# Makes the plots two different way:
p1=superbPlot( Orange.wide, WSFactors = "age(7)",
  variables = c("DV_118","DV_484","DV_664","DV_1004","DV_1231","DV_1372","DV_1582"),
  adjustments = list(purpose = "difference", decorrelation = "none")
) + 
  xlab("Age level") + ylab("Trunk diameter (mm)") +
  coord_cartesian( ylim = c(0,250) ) + labs(title="Basic confidence intervals")

p2=superbPlot( Orange.wide, WSFactors = "age(7)",
  variables = c("DV_118","DV_484","DV_664","DV_1004","DV_1231","DV_1372","DV_1582"),
  adjustments = list(purpose = "difference", decorrelation = "CA")
) + 
  xlab("Age level") + ylab("Trunk diameter (mm)") +
  coord_cartesian( ylim = c(0,250) ) + labs(title="Decorrelated confidence intervals")
grid.arrange(p1,p2,ncol=2)



superb documentation built on May 29, 2024, 8:51 a.m.