weighted_estimators {simPop} | R Documentation |
Weighted mean, variance, covariance matrix and correlation matrix
Description
Compute mean, variance, covariance matrix and correlation matrix, taking into account sample weights.
-
meanWt
: a simple wrapper that callsmean(x, na.rm=na.rm)
ifweights
is missing andweighted.mean(x, w=weights, na.rm=na.rm)
otherwise. Implemented methods for this generic are:-
meanWt.default(x, weights, na.rm=TRUE, ...)
-
meanWt.dataObj(x, vars, na.rm=TRUE, ...)
-
-
varWt
: callsvar(x, na.rm=na.rm)
ifweights
is missing. Implemented methods for this generic are:-
varWt.default(x, weights, na.rm=TRUE, ...)
-
varWt.dataObj(x, vars, na.rm=TRUE, ...)
-
-
covWt
andcovWt
: always remove missing values pairwise and callcov
andcor
, respectively, ifweights
is missing. Implemented methods for these generics are:-
covWt.default(x, y, weights, ...)
-
covWt.matrix(x, weights, ...)
-
covWt.data.frame(x, weights, ...)
-
covWt.dataObj(x, vars, ...)
-
corWt.default(x, y, weights, ...)
-
corWt.matrix(x, weights, ...)
-
corWt.data.frame(x, weights, ...)
-
corWt.dataObj(x, vars, ...)
-
The additional parameters are now described:
y: a numeric vector. If missing, this defaults to
x
.vars: a character vector of variable names that should be used for the calculation.
na.rm: a logical indicating whether any
NA
orNaN
values should be removed fromx
before computation. Note that the default isTRUE
.weights: an optional numeric vector containing sample weights.
Usage
meanWt(x, ...)
varWt(x, ...)
covWt(x, ...)
corWt(x, ...)
Arguments
x |
for |
... |
for the generic functions |
Value
For meanWt
, the (weighted) mean.
For varWt
, the (weighted) variance.
For covWt
, the (weighted) covariance matrix or, for the default
method, the (weighted) covariance.
For corWt
, the (weighted) correlation matrix or, for the default
method, the (weighted) correlation coefficient.
Note
meanWt
, varWt
, covWt
and corWt
all make use of
slot weights
of the input object if the dataObj
-method is
used.
Author(s)
Stefan Kraft and Andreas Alfons
See Also
mean
, weighted.mean
,
var
, cov
,
cor
Examples
data(eusilcS)
meanWt(eusilcS$netIncome, weights=eusilcS$rb050)
sqrt(varWt(eusilcS$netIncome, weights=eusilcS$rb050))
# dataObj-methods
inp <- specifyInput(data=eusilcS, hhid="db030", hhsize="hsize", strata="db040", weight="db090")
meanWt(inp, vars="netIncome")
sqrt(varWt(inp, vars="netIncome"))
corWt(inp, vars=c("age", "netIncome"))
covWt(inp, vars=c("age", "netIncome"))