descript: Descriptive Statistics

View source: R/descript.R

descriptR Documentation

Descriptive Statistics

Description

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

Usage

descript(..., data = NULL,
        print = c("all", "default", "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, append = TRUE, check = TRUE, output = TRUE)

Arguments

...

a numeric vector, matrix or data frame with numeric variables, i.e., factors and character variables are excluded from ... before conducting the analysis. Alternatively, an expression indicating the variable names in data e.g., descript(x1, x2, x3, data = dat). Note that the operators ., +, -, ~, :, ::, and ! can also be used to select variables, see 'Details' in the df.subset function.

data

a data frame when specifying one or more variables in the argument .... Note that the argument is NULL when specifying a numeric vector, matrix, or data frame for the argument ....

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. Alternatively, a character string indicating the variable name of the grouping variable in data can be specified.

split

a numeric vector, character vector or factor as split variable. Alternatively, a character string indicating the variable name of the split variable in data can be specified.

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 ..., but not to group or split.

write

a character string naming a file for writing the output into either a text file with file extension ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), 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 ..., 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

# Example 1a: Descriptive statistics for 'mpg'
descript(mtcars$mpg)

# Example 1b: Alternative specification using the 'data' argument
descript(mpg, data = mtcars)

# Example 2: Descriptive statistics, print results with 3 digits
descript(mtcars$mpg, digits = 3)

# Example 3a: Descriptive statistics for x1, print all available statistical measures
descript(mtcars$mpg, print = "all")

# Example 3b: Descriptive statistics for x1, print default plus median
descript(mtcars$mpg, print = c("default", "med"))

# Example 4a: Descriptive statistics for 'mpg', 'cyl', and 'disp'
descript(mtcars[, c("mpg", "cyl", "disp")])

# Example 4b: Alternative specification using the 'data' argument
descript(mpg:disp, data = mtcars)

# Example 5a: Descriptive statistics, analysis by 'vs' separately
descript(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)

# Example 5b: Alternative specification using the 'data' argument
descript(mpg:disp, data = mtcars, group = "vs")

# Example 6: Descriptive statistics, analysis by 'vs' separately, sort by variables
descript(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, sort.var = TRUE)

# Example 7: Descriptive statistics, split analysis by 'am'
descript(mtcars[, c("mpg", "cyl", "disp")], split = mtcars$am)

# Example 8a: Descriptive statistics,analysis by 'vs' separately, split analysis by 'am'
descript(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, split = mtcars$am)

# Example 8b: Alternative specification using the 'data' argument
descript(mpg:disp, data = mtcars, group = "vs", split = "am")

## Not run: 
# Example 11a: Write results into a text file
descript(mtcars[, c("mpg", "cyl", "disp")], write = "Descript.txt")

# Example 11b: Write results into an Excel file
descript(mtcars[, c("mpg", "cyl", "disp")], write = "Descript.xlsx")

result <- descript(mtcars[, c("mpg", "cyl", "disp")], output = FALSE)
write.result(result, "Descript.xlsx")

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to descript in misty...