Learn R Programming

miceadds (version 1.6-0)

ma.wtd.statNA: Some Multivariate Descriptive Statistics for Weighted Data in miceadds

Description

Some multivariate descriptive statistics for weighted datasets in miceadds. A list of multiply imputed data is also allowed as input.

Usage

ma.wtd.meanNA(data, weights = NULL , vars = NULL )
ma.wtd.sdNA(data, weights = NULL , vars = NULL , method = "unbiased" )
ma.wtd.covNA(data, weights = NULL , vars = NULL , method = "unbiased" )
ma.wtd.corNA(data, weights = NULL , vars = NULL , method = "unbiased" )

Arguments

data
Numeric data frame or objects of one of the classes datlist, imputationList, mids, mids.1chain, nested.datlist or NestedImputationList.
weights
Optional vector of sampling weights
vars
Optional vector of variable names
method
Computation method for covariances. These amount to choosing the divisor $(n-1)$ (method="unbiased") instead of $n$ (method="ML"). See stats::cov.wt for furthe

Value

  • A vector or a matrix depending on the requested statistic.

Details

Contrary to ordinary Rpractice, missing values are ignored in the calculation of descriptive statistics. ll{ ma.wtd.meanNA weighted means ma.wtd.sdNA weighted standard deviations ma.wtd.covNA weighted covariance matrix ma.wtd.corNA weighted correlation matrix }

See Also

stats::weighted.mean stats::cov.wt, Hmisc::wtd.var See micombine.cor for statistical inference of correlation coefficients.

Examples

Run this code
#############################################################################
# EXAMPLE 1: Weighted statistics for a single dataset data.ma01
#############################################################################

data(data.ma01)
dat <- as.matrix(data.ma01[,-c(1:3)])

# weighted mean
ma.wtd.meanNA( dat , weights=data.ma01$studwgt  ) 

# weighted SD
ma.wtd.sdNA( dat , weights=data.ma01$studwgt  ) 

# weighted covariance for selected variables
ma.wtd.covNA( dat , weights=data.ma01$studwgt , vars = c("books","hisei") )

# weighted correlation
ma.wtd.corNA( dat , weights=data.ma01$studwgt )

#############################################################################
# EXAMPLE 2: Weighted statistics multiply imputed dataset
#############################################################################

library(mitools)
data(data.ma05)
dat <- data.ma05

# do imputations
resp <- dat[ , - c(1:2) ]
# object of class mids
imp <- mice::mice( resp , imputationMethod="norm" , maxit=3 , m=5 )
# object of class datlist
datlist <- mids2datlist( imp )
# object of class imputationList
implist <- mitools::imputationList(datlist)

# weighted means
ma.wtd.meanNA(datlist)
ma.wtd.meanNA(implist)
ma.wtd.meanNA(imp)	

#############################################################################
# EXAMPLE 3: Weighted statistics nested multiply imputed dataset
#############################################################################

library(BIFIEsurvey)
data(data.timss2 , package="BIFIEsurvey" )
datlist <- data.timss2   # list of 5 datasets containing 5 plausible values

#** define imputation method and predictor matrix
data <- datlist[[1]]
V <- ncol(data)
# variables
vars <- colnames(data)
# variables not used for imputation
vars_unused <- scan.vec("IDSTUD TOTWGT  JKZONE  JKREP" )
#- define imputation method
impMethod <- rep("norm" , V )
names(impMethod) <- vars
impMethod[ vars_unused ] <- ""
#- define predictor matrix
predM <- matrix( 1 , V , V )
colnames(predM) <- rownames(predM) <- vars
diag(predM) <- 0
predM[ , vars_unused ] <- 0

# object of class mids.nmi
imp1 <- mice.nmi( datlist , imputationMethod=impMethod , predictorMatrix=predM, 
                m=4 , maxit=3 )
# object of class nested.datlist
datlist <- mids2datlist(imp1)
# object of class NestedImputationList
imp2 <- NestedImputationList(datlist)

# weighted correlations
vars <- c("books","ASMMAT","likesc")
ma.wtd.corNA( datlist ,  vars = vars )
ma.wtd.corNA( imp2 ,  vars = vars )
ma.wtd.corNA( imp1 ,  vars = vars )

Run the code above in your browser using DataLab