descript: Descriptive Statistics

View source: R/descript.R

descriptR Documentation

Descriptive Statistics

Description

This function computes summary statistics for one or more variables, optionally by a grouping and/or split variable.

Usage

descript(x,
        print = c("all", "n", "nNA", "pNA", "m", "se.m", "var", "sd", "min",
                  "p25", "med", "p75", "max", "range", "iqr", "skew", "kurt"),
        group = NULL, split = NULL, sort.var = FALSE, na.omit = FALSE,
        digits = 2, as.na = NULL, write = NULL, check = TRUE, output = TRUE)

Arguments

x

a numeric vector, matrix or data frame with numeric variables, i.e., factors and character variables are excluded from x before conducting the analysis.

print

a character vector indicating which statistical measures to be printed on the console, i.e. n (number of observations), nNA (number of missing values), pNA (percentage of missing values), m (arithmetic mean), se.m (standard error of the arithmetic mean), var (variance), sd (standard deviation), med (median),min (minimum), p25 (25th percentile, first quartile), p75 (75th percentile, third quartile), max (maximum), range (range), iqr (interquartile range), skew (skewness), and kurt (excess kurtosis). The default setting is print = ("n", "nNA", "pNA", "m", "sd", "min", "max", "skew", "kurt").

group

a numeric vector, character vector or factor as grouping variable.

split

a numeric vector, character vector or factor as split variable.

sort.var

logical: if TRUE, output table is sorted by variables when specifying group.

na.omit

logical: if TRUE, incomplete cases are removed before conducting the analysis (i.e., listwise deletion).

digits

an integer value indicating the number of decimal places to be used.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis. Note that as.na() function is only applied to x, but not to group or split.

write

a character string for writing the results into a Excel file naming a file with or without file extension '.xlsx', e.g., "Results.xlsx" or "Results".

check

logical: if TRUE, argument specification is checked.

output

logical: if TRUE, output is shown on the console.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

data

list with the input specified in x, group, and split

args

specification of function arguments

result

result table(s)

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.

See Also

ci.mean, ci.mean.diff, ci.median, ci.prop, ci.prop.diff, ci.var, ci.sd, freq, crosstab, multilevel.descript, na.descript.

Examples

dat <- data.frame(group1 = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
                  group2 = c(1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2),
                  x1 = c(3, 1, 4, 2, 5, 3, 2, 4, NA, 4, 5, 3),
                  x2 = c(4, NA, 3, 6, 3, 7, 2, 7, 5, 1, 3, 6),
                  x3 = c(7, 8, 5, 6, 4, NA, 8, NA, 6, 5, 8, 6))

# Descriptive statistics for x1
descript(dat$x1)

# Descriptive statistics for x1, print results with 3 digits
descript(dat$x1, digits = 3)

# Descriptive statistics for x1, convert value 4 to NA
descript(dat$x1, as.na = 4)

# Descriptive statistics for x1, print all available statistical measures
descript(dat$x1, print = "all")

# Descriptive statistics for x1, x2, and x3
descript(dat[, c("x1", "x2", "x3")])

# Descriptive statistics for x1, x2, and x3,
# listwise deletion for missing data
descript(dat[, c("x1", "x2", "x3")], na.omit = TRUE)

# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately
descript(dat[, c("x1", "x2", "x3")], group = dat$group1)

# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately, sort by variables
descript(dat[, c("x1", "x2", "x3")], group = dat$group1, sort.var = TRUE)

# Descriptive statistics for x1, x2, and x3,
# split analysis by group1
descript(dat[, c("x1", "x2", "x3")], split = dat$group1)

# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately, split analysis by group2
descript(dat[, c("x1", "x2", "x3")], group = dat$group1, split = dat$group2)

## Not run: 
# Write Results into a Excel file
descript(dat[, c("x1", "x2", "x3")], write = "Descript.xlsx")

result <- descript(dat[, c("x1", "x2", "x3")], output = FALSE)
write.result(result, "Descript.xlsx")

## End(Not run)

misty documentation built on Nov. 15, 2023, 1:06 a.m.

Related to descript in misty...