weighted.scale {corpcor}R Documentation

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 simple number (weighted.var)

Author(s)

Rainer Opgen-Rhein (http://www.statistik.lmu.de/~opgen/) and Korbinian Strimmer (http://www.statistik.lmu.de/~strimmer/).

See Also

weighted.mean.

Examples

# 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


[Package corpcor version 1.3.1 Index]