Learn R Programming

weights (version 1.1.2)

stdz: Standardizes any numerical vector, with weights.

Description

stdz produces a standardized copy of any input variable. It can also standardize a weighted variable to produce a copy of the original variable standardized around its weighted mean and variance.

Usage

stdz(x, weight=NULL)

Value

A vector of length equal to x with a (weighted) mean of zero and a (weighted) standard deviation of 1.

Arguments

x

x should be a numerical vector which the researcher wishes to standardize.

weight

weight is an optional vector of weights to be used to determining the weighted mean and variance for standardization.

Author

Josh Pasek, Professor of Communication & Media and Political Science at the University of Michigan (www.joshpasek.com).

See Also

wtd.cor wtd.chi.sq wtd.t.test

Examples

Run this code
test <- c(1,1,1,1,1,1,2,2,2,3,3,3,4,4)
weight <- c(.5,.5,.5,.5,.5,1,1,1,1,2,2,2,2,2)

summary(stdz(test))
summary(stdz(test, weight))
Hmisc::wtd.mean(stdz(test, weight), weight)
Hmisc::wtd.var(stdz(test, weight), weight)

Run the code above in your browser using DataLab