head(workplace)
library(survey)
# Survey design for stratified simple random sampling without replacement
dn <- if (packageVersion("survey") >= "4.2") {
# survey design with pre-calibrated weights
svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight,
data = workplace, calibrate.formula = ~-1 + strat)
} else {
# legacy mode
svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight,
data = workplace)
}
# Compute the regression estimate (weighted least squares)
m <- svyreg(payroll ~ employment, dn)
# Regression inference
summary(m)
# Extract the coefficients
coef(m)
# Extract variance/ covariance matrix
vcov(m)
# Diagnostic plots (e.g., Normal Q-Q-plot)
plot(m, which = 2L)
Run the code above in your browser using DataLab