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 regression M-estimate with Huber psi-function
m <- svyratio_huber(~payroll, ~employment, dn, k = 8)
# Regression inference
summary(m)
# Extract the coefficients
coef(m)
# Extract estimated standard error
SE(m)
# Extract variance/ covariance matrix
vcov(m)
# Diagnostic plots (e.g., standardized residuals against fitted values)
plot(m, which = 1L)
# Plot of the robustness weights of the M-estimate against its residuals
plot(residuals(m), robweights(m))
Run the code above in your browser using DataLab