Learn R Programming

corpcor (version 1.4.0)

weighted.scale: Weighted Expectations and Variance

Description

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

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

Usage

weighted.var(xvec, w) 
  weighted.moments(x, w)
  weighted.scale(x, w, center=TRUE, scale=TRUE, wm)

Arguments

xvec
a vector
x
a matrix
w
data weights
center
logical value
scale
logical value
wm
list with variances and means as returned by weighted.moments. Will be computed from x if missing.

Value

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

See Also

weighted.mean.

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)
weighted.scale(X)
weighted.scale(X, w) # take into account data weights

Run the code above in your browser using DataLab