Closed Yingyan-Wu closed 1 year ago
@Yingyan-Wu I would use the cWeights=TRUE
argument and a set of weights set to one. What that does is make the weights conditional on the higher-level weights. So a weight of one gives the unit the same weight as level-two group (which is the same as making them certainty units).
Here is an example using PISA data where I use cWeights=TRUE
and make a variable named one
that is always one.
library(EdSurvey)
#read in data
downloadPISA("~/", year=2012)
cntl <- readPISA("~/PISA/2012", countries="USA")
data <- getData(cntl,c("schoolid","pv1math","st29q03","sc14q02","st04q01",
"escs","w_fschwt","w_fstuwt"),
omittedLevels=FALSE, addAttributes=FALSE)
# Remove NA and omitted Levels
om <- c("Invalid", "N/A", "Missing", "Miss", NA, "(Missing)")
for (i in 1:ncol(data)) {
data <- data[!data[,i] %in% om,]
}
#relevel factors for model
data$st29q03 <- relevel(data$st29q03, ref="Strongly agree")
data$sc14q02 <- relevel(data$sc14q02, ref="Not at all")
m1 <- mix(pv1math ~ st29q03 + sc14q02 +st04q01+escs+ (1|schoolid), data=data,
weights=c("one", "w_fschwt"), cWeights=TRUE)
summary(m1)
# Call:
# mix(formula = pv1math ~ st29q03 + sc14q02 + st04q01 + escs +
# (1 | schoolid), data = data, weights = c("one", "w_fschwt"),
# cWeights = TRUE)
#
# Variance terms:
# Level Group Name Variance Std. Error Std.Dev.
# 2 schoolid (Intercept) 1095 264.1 33.08
# 1 Residual 5114 202.7 71.51
# Groups:
# Level Group n size mean wgt sum wgt
# 2 schoolid 157 192.1 30161
# 1 Obs 3136 143.9 451370
#
# Fixed Effects:
# Estimate Std. Error t value
# (Intercept) 494.942 7.047 70.231
# st29q03Agree -23.922 7.200 -3.322
# st29q03Disagree -26.202 6.294 -4.163
# st29q03Strongly disagree -55.030 12.336 -4.461
# sc14q02Very little -18.374 14.030 -1.310
# sc14q02To some extent -10.597 13.295 -0.797
# sc14q02A lot -25.308 7.997 -3.165
# st04q01Male 12.286 3.720 3.303
# escs 28.726 2.561 11.218
#
# lnl= -2587214.68
# Intraclass Correlation= 0.1763
I hope that helps!
I was wondering how to set the lower level weights if we have higher level weights and we are not expecting the lower level weights to be different.
More specifically, the data structure I'm currently dealing with is that it's a longitudinal dataset where multiple observations are nested in each participant and sampling weights existed for participant level. In terms of taking the sampling weights into account and since we want the observation to represent one observation within the participant, I set the lower weight (observation level) to be 1s. I'm wondering if this is the correct way to deal with the problem.
Let me know if anything needs to be clarified. Thank you in advance.