smd: Compute Standardized Mean Difference

Description Usage Arguments Value Examples

Description

Computes the standardized mean differnce (SMD) between two groups.

d = √{D' S^{-1} D}

where D is a vector of differences between group 1 and 2 and S is the covariance matrix of these differences. If D is length 1, the result is multplied by sign(D).

In the case of a numeric or integer variable, this is equivalent to:

d = \frac{\bar{x}_1 - \bar{x}_2}{√{(s^2_1 + s^2_2)/2}}

where \bar{x}_g is the sample mean for group g and s^2_g is the sample variance.

For a logical or factor with only two levels, the equation above is \bar{x}_g = \hat{p}_g, i.e. the sample proportion and s^2_g = \hat{p}_g(1 - \hat{p}_g).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'character,ANY,missing'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'character,ANY,numeric'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'logical,ANY,missing'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'logical,ANY,numeric'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'matrix,ANY,missing'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'matrix,ANY,numeric'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'list,ANY,missing'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'list,ANY,numeric'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'data.frame,ANY,missing'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

## S4 method for signature 'data.frame,ANY,numeric'
smd(x, g, w, std.error = FALSE, na.rm = FALSE, gref = 1L)

Arguments

x

a vector or matrix of values

g

a vector of at least 2 groups to compare. This should coercable to a factor.

w

a vector of numeric weights (optional)

std.error

Logical indicator for computing standard errors using compute_smd_var. Defaults to FALSE.

na.rm

Remove NA values from x? Defaults to FALSE.

gref

an integer indicating which level of g to use as the reference group. Defaults to 1.

Value

a data.frame containing standardized mean differences between levels of g for values of x. The data.frame contains the columns:

Examples

1
2
3
x <- rnorm(100)
g <- rep(1:2, each = 50)
smd(x, g)

smd documentation built on Oct. 23, 2020, 8:26 p.m.