data(UPBdata)
##############################
## weighting-based approach ##
##############################
weightData <- neWeight(negaff ~ att + gender + educ + age,
data = UPBdata)
## stratum-specific natural effects
# bootstrap SE
if (FALSE) {
weightFit1b <- neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = weightData)
summary(weightFit1b)
}
# robust SE
weightFit1r <- neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = weightData, se = "robust")
summary(weightFit1r)
## population-average natural effects
expFit <- glm(att ~ gender + educ + age, data = UPBdata)
# bootstrap SE
if (FALSE) {
weightFit2b <- neModel(UPB ~ att0 * att1, family = binomial,
expData = weightData, xFit = expFit)
summary(weightFit2b)
}
# robust SE
weightFit2r <- neModel(UPB ~ att0 * att1, family = binomial,
expData = weightData, xFit = expFit, se = "robust")
summary(weightFit2r)
###############################
## imputation-based approach ##
###############################
impData <- neImpute(UPB ~ att * negaff + gender + educ + age,
family = binomial, data = UPBdata)
## stratum-specific natural effects
# bootstrap SE
if (FALSE) {
impFit1b <- neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = impData)
summary(impFit1b)
}
# robust SE
impFit1r <- neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = impData, se = "robust")
summary(impFit1r)
## population-average natural effects
# bootstrap SE
if (FALSE) {
impFit2b <- neModel(UPB ~ att0 * att1, family = binomial,
expData = impData, xFit = expFit)
summary(impFit2b)
}
# robust SE
impFit2r <- neModel(UPB ~ att0 * att1, family = binomial,
expData = impData, xFit = expFit, se = "robust")
summary(impFit2r)
# check with vgam (VGAM package)
# library(VGAM)
# weightData <- neWeight(negaff ~ att + gender + educ + age, family = uninormal, data = UPBdata, FUN = vgam)
# impData <- neImpute(UPB ~ att + negaff + gender + educ + age, family = binomialff, data = UPBdata, FUN = vgam)
# debug(neModel)
# weightFit <- neModel(UPB ~ att0 + att1 + gender + educ + age, family = binomial, expData = weightData, nBoot = 2)
# impFit <- neModel(UPB ~ att0 + att1 + gender + educ + age, family = binomial, expData = impData, nBoot = 2)
# summary(weightFit)
# summary(impFit)
# warning!
impFit <- neModel(UPB ~ att0 * att1 + gender + educ + age, family = binomial, expData = impData, nBoot = 2)
# inverse propensity score weighting
expFit <- glm(att ~ gender + educ + age, data = UPBdata)
impFit <- neModel(UPB ~ att0 + att1, family = binomial, expData = impData, xFit = expFit, nBoot = 2)
Run the code above in your browser using DataLab