top of page

Descriptive Statistics


ds = dataset you are currently using.

DV = dependent variable of interest

IV = independent variable of interest

XYXY = dummy name for a variable, matrix, or data frame into which you are moving information.

Extract descriptives, by levels of independent variable as.factor!!!!!

Step 1: Tell R that your independent variables have discrete levels

R assumes that variables are continuous. In order to tell it otherwise, use the factor function.


ds$IV <- as.factor(ds$IV)

ds$Subject <- as.factor(ds$Subject)


At this step, you can also add labels to the data if you desire


ds$IV <- factor(ds$IV,
                   levels = c(0,1),
                   labels = c("Label for 0", "Label for 1"))


Step 2: Extract descriptives

The psych package includes a describeBy function that allows descriptives to be produced with respect to any independent variables.

  • To get main effects, simply only include one IV

  • mat=TRUE outputs data in a matrix format, which makes it easier to work with

  • again, type refers to the manner in which skew and kurtosis are calculated

    • Per Joanes and Gill (1998), type 2 has been adopted by SPSS, SAS, and Excel

  • digits=2 refers to the number of significant digits reported. Adjust as needed



XYXY <-describeBy(ds$DV,

group = ds$IV1 : ds$IV2,


type = 2,

digits = 2)


bottom of page