Wraps survey::svyglm(). Family argument accepts the same strings as the
Python module ("gaussian", "binomial", "poisson", "gamma", "negativebinomial")
or any R family object.
Usage
morie_survey_glm(
design,
formula,
family = c("gaussian", "binomial", "poisson", "gamma", "negativebinomial")
)Arguments
- design
A
survey::svydesignobject (when interfacing with thesurveypackage directly).- formula
A
formula(e.g.y ~ x1 + x2) for survey-weighted regression / GLM.- family
A
familyobject (e.g.stats::binomial()) passed to the survey-weighted GLM.
Examples
set.seed(1)
df <- data.frame(y = rnorm(40), x = rnorm(40), w = runif(40, 0.5, 2))
d <- morie_survey_design(df, "w")
str(morie_survey_glm(d, y ~ x), max.level = 1)
#> List of 33
#> $ coefficients : Named num [1:2] 0.11 0.123
#> ..- attr(*, "names")= chr [1:2] "(Intercept)" "x"
#> $ residuals : Named num [1:40] -0.716 0.105 -1.031 1.417 0.305 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ fitted.values : Named num [1:40] 0.0893 0.0783 0.1955 0.1782 0.0246 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ effects : Named num [1:40] -0.76 0.713 -0.857 1.679 0.417 ...
#> ..- attr(*, "names")= chr [1:40] "(Intercept)" "x" "" "" ...
#> $ R : num [1:2, 1:2] -6.325 0 -0.542 5.778
#> ..- attr(*, "dimnames")=List of 2
#> $ rank : int 2
#> $ qr :List of 5
#> ..- attr(*, "class")= chr "qr"
#> $ family :List of 12
#> ..- attr(*, "class")= chr "family"
#> $ linear.predictors: Named num [1:40] 0.0893 0.0783 0.1955 0.1782 0.0246 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ deviance : num 28.3
#> $ aic : logi NA
#> $ null.deviance : num 28.8
#> $ iter : int 2
#> $ weights : Named num [1:40] 0.68 1.352 0.858 1.225 1.336 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ prior.weights : Named num [1:40] 0.68 1.352 0.858 1.225 1.336 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ df.residual : num 38
#> $ df.null : int 39
#> $ y : Named num [1:40] -0.626 0.184 -0.836 1.595 0.33 ...
#> ..- attr(*, "names")= chr [1:40] "1" "2" "3" "4" ...
#> $ converged : logi TRUE
#> $ boundary : logi FALSE
#> $ model :'data.frame': 40 obs. of 3 variables:
#> ..- attr(*, "terms")=Classes 'terms', 'formula' language y ~ x
#> .. .. ..- attr(*, "variables")= language list(y, x)
#> .. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
#> .. .. .. ..- attr(*, "dimnames")=List of 2
#> .. .. ..- attr(*, "term.labels")= chr "x"
#> .. .. ..- attr(*, "order")= int 1
#> .. .. ..- attr(*, "intercept")= int 1
#> .. .. ..- attr(*, "response")= int 1
#> .. .. ..- attr(*, ".Environment")=<environment: 0x555874640788>
#> .. .. ..- attr(*, "predvars")= language list(y, x)
#> .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "numeric" "numeric" "numeric"
#> .. .. .. ..- attr(*, "names")= chr [1:3] "y" "x" "(weights)"
#> $ call : language svyglm(formula = fml, design = design, family = fam)
#> $ formula :Class 'formula' language y ~ x
#> .. ..- attr(*, ".Environment")=<environment: 0x555874640788>
#> $ terms :Classes 'terms', 'formula' language y ~ x
#> .. ..- attr(*, "variables")= language list(y, x)
#> .. ..- attr(*, "factors")= int [1:2, 1] 0 1
#> .. .. ..- attr(*, "dimnames")=List of 2
#> .. ..- attr(*, "term.labels")= chr "x"
#> .. ..- attr(*, "order")= int 1
#> .. ..- attr(*, "intercept")= int 1
#> .. ..- attr(*, "response")= int 1
#> .. ..- attr(*, ".Environment")=<environment: 0x555874640788>
#> .. ..- attr(*, "predvars")= language list(y, x)
#> .. ..- attr(*, "dataClasses")= Named chr [1:3] "numeric" "numeric" "numeric"
#> .. .. ..- attr(*, "names")= chr [1:3] "y" "x" "(weights)"
#> $ data :'data.frame': 40 obs. of 4 variables:
#> $ offset : NULL
#> $ control :List of 3
#> $ method : chr "glm.fit"
#> $ contrasts : NULL
#> $ xlevels : Named list()
#> $ naive.cov : num [1:2, 1:2] 0.02522 -0.00257 -0.00257 0.02995
#> ..- attr(*, "dimnames")=List of 2
#> $ cov.unscaled : num [1:2, 1:2] 0.018142 0.000503 0.000503 0.019629
#> ..- attr(*, "dimnames")=List of 2
#> $ survey.design :List of 9
#> ..- attr(*, "class")= chr [1:2] "survey.design2" "survey.design"
#> - attr(*, "class")= chr [1:3] "svyglm" "glm" "lm"
