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

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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.

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

Value

A vector or a matrix depending on the requested statistic.

Note

If data is of class BIFIEdata and no weights are specified, sample weights are extracted from the BIFIEdata object.

Author(s)

Alexander Robitzsch

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#############################################################################
# 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 <- miceadds::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 <- miceadds::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 <- miceadds::mice.nmi( datlist , imputationMethod=impMethod , predictorMatrix=predM, 
                m=4 , maxit=3 )
# object of class nested.datlist
datlist <- miceadds::mids2datlist(imp1)
# object of class NestedImputationList
imp2 <- miceadds::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)	

miceadds documentation built on Aug. 9, 2017, 5:04 p.m.