Learn R Programming

miceadds (version 2.2-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 (nested) multiply imputed data sets 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" )
ma.wtd.skewnessNA(data, weights = NULL , vars = NULL , method = "unbiased" )
ma.wtd.curtosisNA(data, weights = NULL , vars = NULL , method = "unbiased" )
ma.wtd.quantileNA( data , weights = NULL , vars = NULL , type = 7 , probs = seq(0,1,.25) )

Arguments

data
Numeric data vector or data frame or objects of one of the classes datlist, imputationList, mids, mids.1chain, nested.datlist, NestedImputationList or BIFIEdata.
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 further details.
type
Quantile type. This specification follows TAM::weighted_quantile
probs
Vector of probabilities used for calculation of quantiles.

Value

A vector or a matrix depending on the requested statistic.

Details

Contrary to ordinary R practice, missing values are ignored in the calculation of descriptive statistics.

ma.wtd.meanNA
weighted means
ma.wtd.sdNA
weighted standard deviations
ma.wtd.covNA
weighted covariance matrix
ma.wtd.corNA
weighted correlation matrix
ma.wtd.skewnessNA
weighted skewness
ma.wtd.curtosisNA
weighted (excess) curtosis

See Also

Some functions for weighted statistics: stats::weighted.mean, stats::cov.wt, Hmisc::wtd.var, TAM::weighted_quantile, ... 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 )

# weighted curtosis
ma.wtd.skewnessNA( dat[,"books"] , weights=data.ma01$studwgt )
# compare with result in TAM
TAM::weighted_skewness( x=dat[,"books"] , w=data.ma01$studwgt )

# weighted curtosis
ma.wtd.curtosisNA( dat , weights=data.ma01$studwgt , vars = c("books","hisei") ) 
# result in TAM
TAM::weighted_curtosis( dat[,"books"] , w=data.ma01$studwgt )
TAM::weighted_curtosis( dat[,"hisei"] , w=data.ma01$studwgt )

## Not run: 
# #############################################################################
# # 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)	
# 
# # weighted quantiles
# ma.wtd.quantileNA( implist, weights=data.ma05$studwgt, vars = c("manote","Dscore")) 
# 
# #############################################################################
# # 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 )
# 
# #############################################################################
# # EXAMPLE 4: Multiply imputed datasets in BIFIEdata format
# #############################################################################
# 
# library(BIFIEsurvey)
# data(data.timss1, package="BIFIEsurvey")
# data(data.timssrep, package="BIFIEsurvey")
# 
# # create BIFIEdata object
# bdat <- BIFIEsurvey::BIFIE.data( data.list=data.timss1 , wgt= data.timss1[[1]]$TOTWGT ,
#             wgtrep=data.timssrep[, -1 ] )
# summary(bdat)            
# # create BIFIEdata object in a compact way
# bdat2 <- BIFIEsurvey::BIFIE.data( data.list=data.timss1 , wgt= data.timss1[[1]]$TOTWGT ,
#             wgtrep=data.timssrep[, -1 ] , cdata=TRUE)
# summary(bdat2)  
# 
# # compute skewness
# ma.wtd.skewnessNA( bdat , vars = c("ASMMAT" , "books" ) )
# ma.wtd.skewnessNA( bdat2 , vars = c("ASMMAT" , "books" ) )
# 
# #############################################################################
# # EXAMPLE 5: Nested multiply imputed datasets in BIFIEdata format
# #############################################################################
# 
# data(data.timss4, package="BIFIEsurvey")
# data(data.timssrep, package="BIFIEsurvey")
# 
# # nested imputed dataset, save it in compact format
# bdat <- BIFIE.data( data.list=data.timss4 , wgt= data.timss4[[1]][[1]]$TOTWGT ,
#             wgtrep=data.timssrep[, -1 ] , NMI=TRUE , cdata=TRUE )
# summary(bdat)            
# # skewness
# ma.wtd.skewnessNA( bdat , vars = c("ASMMAT" , "books" ) )
# 
# ## End(Not run)	

Run the code above in your browser using DataLab