## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "", prompt = TRUE, dpi = 36, fig.align = "center" ) ## ----------------------------------------------------------------------------- library("robsurvey", quietly = TRUE) ## ----------------------------------------------------------------------------- attach(workplace) ## ----------------------------------------------------------------------------- head(workplace, 3) ## ----eval = FALSE------------------------------------------------------------- # library("survey") ## ----echo = FALSE------------------------------------------------------------- suppressPackageStartupMessages(library(survey)) ## ----eval = FALSE------------------------------------------------------------- # dn <- svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight, # data = workplace, calibrate.formula = ~-1 + strat) ## ----echo = FALSE------------------------------------------------------------- dn <- if (packageVersion("survey") >= "4.2") { svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight, data = workplace, calibrate.formula = ~-1 + strat) } else { svydesign(ids = ~ID, strata = ~strat, fpc = ~fpc, weights = ~weight, data = workplace) } ## ----echo = FALSE, results = "asis"------------------------------------------- survey_version <- packageVersion("survey") if (survey_version < "4.2") { cat(paste0('
')) } ## ----echo = FALSE, fig.show = "hold", out.width = "50%", fig.asp = 0.5-------- layout(matrix(1:2, ncol = 2)) par(mar = c(4, 1, 1, 1)) svyboxplot(payroll~ 1, dn, all.outliers = TRUE, xlab = "payroll", horizontal = TRUE) svyboxplot(log(payroll) ~ 1, dn, all.outliers = TRUE, xlab = "log(payroll)", horizontal = TRUE) ## ----echo = FALSE, out.width = "50%"------------------------------------------ par(mar = c(5, 4, 1, 0)) plot(weights(dn), dn$variables$payroll, ylab = "payroll (log scale)", log = "y", panel.first = grid(col = "grey", lty = 2)) ## ----------------------------------------------------------------------------- weighted_total_huber(payroll, weight, k = 8, type = "rht") ## ----------------------------------------------------------------------------- m <- svytotal_huber(~payroll, dn, k = 8, type = "rht") m ## ----------------------------------------------------------------------------- summary(m) ## ----------------------------------------------------------------------------- coef(m) vcov(m) SE(m) ## ----------------------------------------------------------------------------- scale(m) ## ----eval = FALSE------------------------------------------------------------- # plot(residuals(m), robweights(m)) ## ----echo = FALSE, out.width = "50%"------------------------------------------ par(mar = c(5, 4, 1, 0)) plot(residuals(m), robweights(m))