| svyreg | R Documentation |
Weighted least squares estimator of regression
svyreg(formula, design, var = NULL, na.rm = FALSE, ...)
formula |
a |
design |
an object of class |
var |
a one-sided |
na.rm |
|
... |
additional arguments (currently not used). |
Package survey must be attached to the search path in order to use
the functions (see library or require).
svyreg computes the regression coefficients by weighted least
squares.
Models for svyreg_rob are specified symbolically. A typical
model has the form response ~ terms where response is
the (numeric) response vector and terms is a series of terms
which specifies a linear predictor for response; see
formula and lm.
A formula has an implied intercept term. To remove this use either
y ~ x - 1 or y ~ 0 + x; see formula for more
details of allowed formulae.
Object of class svyreg_rob.
Overview (of all implemented functions)
summary, coef,
residuals, fitted,
SE and vcov
plot for regression diagnostic plot methods
Robust estimating methods svyreg_huberM,
svyreg_huberGM, svyreg_tukeyM and
svyreg_tukeyGM.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.