NMIwaldtest: Wald Test for Nested Multiply Imputed Datasets

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

Description

Performs a Wald test for nested multiply imputed datasets (NMIwaldtest) and ordinary multiply imputed datasets (MIwaldtest), see Reiter and Raghanuthan (2007). The correspondent statistic is also called the D_1 statistic.

The function create.designMatrices.waldtest is a helper function for the creation of design matrices.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
NMIwaldtest(qhat, u, Cdes = NULL, rdes = NULL, testnull = NULL)

MIwaldtest(qhat, u, Cdes = NULL, rdes = NULL, testnull = NULL)

## S3 method for class 'NMIwaldtest'
summary(object,digits=4,...)

## S3 method for class 'MIwaldtest'
summary(object,digits=4,...)

create.designMatrices.waldtest( pars , k )

Arguments

qhat

List or array of estimated parameters

u

List or array of estimated covariance matrices of parameters

Cdes

Design matrix C for parameter test (see Details)

rdes

Constant vector r (see Details)

testnull

Vector containing names of parameters which should be tested for a parameter value of zero.

object

Object of class NMIwaldtest

digits

Number of digits after decimal for print

...

Further arguments to be passed

pars

Vector of parameter names

k

Number of linear hypotheses which should be tested

Details

The Wald test is performed for a linear hypothesis C \bold{θ} = r for a parameter vector \bold{θ}.

Value

List with following entries

stat

Data frame with test statistic

qhat

Transformed parameter according to linear hypothesis

u

Covariance matrix of transformed parameters

Note

The function create.designMatrices.waldtest is a helper function for the creation of design matrices.

Author(s)

Alexander Robitzsch

References

Reiter, J. P. and Raghunathan, T. E. (2007). The multiple adaptations of multiple imputation. Journal of the American Statistical Association, 102, 1462-1471.

See Also

NMIcombine

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
## Not run: 
#############################################################################
# EXAMPLE 1: Nested multiple imputation and Wald test | TIMSS data
#############################################################################

library(BIFIEsurvey)
data(data.timss2 , package="BIFIEsurvey" )
datlist <- data.timss2         
# remove first four variables
M <- length(datlist)
for (ll in 1:M){
    datlist[[ll]] <- datlist[[ll]][ , -c(1:4) ]
               }
                
#***************
# (1) nested multiple imputation using mice
imp1 <- mice.nmi( datlist ,  m=3 , maxit=2 )
summary(imp1)

#**** Model 1: Linear regression with interaction effects
res1 <- with( imp1 , stats::lm( likesc ~ female*migrant + female*books  ) )
pres1 <- pool.mids.nmi( res1 )
summary(pres1)

# test whether both interaction effects equals zero
pars <- dimnames(pres1$qhat)[[3]]
des <- create.designMatrices.waldtest( pars = pars , k=2)
Cdes <- des$Cdes
rdes <- des$rdes
Cdes[1, "female:migrant"] <- 1
Cdes[2, "female:books"] <- 1
wres1 <- NMIwaldtest( qhat=pres1$qhat , u=pres1$u , Cdes=Cdes , rdes=rdes )
summary(wres1)

# a simpler specification is the use of "testnull"
testnull <- c("female:migrant" , "female:books")
wres1b <- NMIwaldtest( qhat=qhat , u=u , testnull=testnull )
summary(wres1b)

#**** Model 2: Multivariate linear regression
res2 <- with( imp1 , stats::lm( cbind( ASMMAT , ASSSCI ) ~ 
                           0 + I(1*(female==1)) + I(1*(female==0))   ) )
pres2 <- pool.mids.nmi( res2 )
summary(pres2)

# test whether both gender differences equals -10 points
pars <- dimnames(pres2$qhat)[[3]]
  ##  > pars
  ##  [1] "ASMMAT:I(1 * (female == 1))" "ASMMAT:I(1 * (female == 0))"
  ##  [3] "ASSSCI:I(1 * (female == 1))" "ASSSCI:I(1 * (female == 0))"

des <- create.designMatrices.waldtest( pars = pars , k=2)
Cdes <- des$Cdes
rdes <- c(-10,-10)
Cdes[1, "ASMMAT:I(1*(female == 1))"] <- 1
Cdes[1, "ASMMAT:I(1*(female == 0))"] <- -1
Cdes[2, "ASSSCI:I(1*(female == 1))"] <- 1
Cdes[2, "ASSSCI:I(1*(female == 0))"] <- -1

wres2 <- NMIwaldtest( qhat=pres2$qhat , u=pres2$u , Cdes=Cdes , rdes=rdes )
summary(wres2)

# test only first hypothesis
wres2b <- NMIwaldtest( qhat=pres2$qhat , u=pres2$u , Cdes=Cdes[1,,drop=FALSE] ,
                         rdes=rdes[1] )
summary(wres2b)

#############################################################################
# EXAMPLE 2: Multiple imputation and Wald test | TIMSS data
#############################################################################

library(BIFIEsurvey)
data(data.timss2 , package="BIFIEsurvey" )
dat <- data.timss2[[1]]
dat <- dat[ , - c(1:4) ]

# perform multiple imputation
imp <- mice::mice( dat , m=6 , maxit=3 )

# define analysis model
res1 <- with( imp , lm( likesc ~ female*migrant + female*books  ) )
pres1 <- mice::pool( res1 )
summary(pres1)

# Wald test for zero interaction effects
qhat <- pres1$qhat
u <- pres1$u
pars <- dimnames(pres1$qhat)[[2]]
des <- create.designMatrices.waldtest( pars = pars , k=2)
Cdes <- des$Cdes
rdes <- des$rdes
Cdes[1, "female:migrant"] <- 1
Cdes[2, "female:books"] <- 1

# apply MIwaldtest function
wres1 <- MIwaldtest( qhat , u , Cdes , rdes )
summary(wres1)

# use again "testnull"
testnull <- c("female:migrant" , "female:books")
wres1b <- MIwaldtest( qhat=qhat , u=u , testnull=testnull )
summary(wres1b)

#***** linear regression with cluster robust standard errors

# convert object of class mids into a list object
datlist_imp <- mids2datlist( imp )
# define cluster
idschool <- as.numeric( substring( data.timss2[[1]]$IDSTUD , 1 , 5 ) )
# linear regression
res2 <- lapply( datlist_imp , FUN = function(data){
           lm.cluster( data=data , formula=likesc ~ female*migrant + female*books ,
                            cluster= idschool ) } )
# extract parameters and covariance matrix
qhat <- lapply( res2 , FUN = function(rr){ coef(rr) } )
u <- lapply( res2 , FUN = function(rr){ vcov(rr) } )
# perform Wald test
wres2 <- MIwaldtest( qhat , u , Cdes , rdes )
summary(wres2)

## End(Not run)


Search within the miceadds package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.