Learn R Programming

corpcor (version 1.4.2)

wt.scale: Weighted Expectations and Variances

Description

wt.var estimate the unbiased variance taking into account data weights.

wt.moments produces the weighted mean and weighted variance for each column of a matrix. wt.scale centers and standardized a matrix using the weighted means and variances.

Usage

wt.var(xvec, w) 
  wt.moments(x, w)
  wt.scale(x, w, center=TRUE, scale=TRUE, scale.by=c("sd", "mean"))

Arguments

xvec
a vector
x
a matrix
w
data weights
center
logical value
scale
logical value
scale.by
determines whether the columns are standardized by the standard errors of the respective variables ("sd", the default) or by the column means ("mean").

Value

  • A rescaled matrix (wt.scale), a list containing the column means and variances (wt.moments), or single number (wt.var)

See Also

weighted.mean, cov.wt.

Examples

Run this code
# load corpcor library
library("corpcor")

# generate some data
p <- 5
n <- 5
X <- matrix(rnorm(n*p), nrow = n, ncol = p)
w <- c(1,1,1,3,3)/9


# standardize matrix
scale(X)
wt.scale(X)
wt.scale(X, w) # take into account data weights

Run the code above in your browser using DataLab