1) Define a count outcome for the dataset of your choosing, the Area Resource File used in class provides many options here
The count outcome will be those considered the "working poor". This will be observed by looking at the rate of those who are living in poverty but are also apart of the work force.
a. State a research question about your outcome
Are those considered the working poor associtaed with their regional context? ie are some regions of the US have larger proportions of the working poor than other parts of the US.
b. Is an offset term necessary? why or why not? If an offset term is need, what is the appropriate offset?
When observing the data a offset is needed because of the distrobution of the population regarding the question at hand. Being that the question was not asked to all individuals. This is again shown through the distrobution that is shown.
By accounting for this by adding 1 to the variable will help correct this error so that the outcomes of the models are equally shown.
2) Consider a Poisson regression model for the outcome
a. Evaluate the level of dispersion in the outcome
From the dispersion shown in the models it sits at about 33 times more variation in the data.
b. Is the Poisson model a good choice?
With the outcome being 0 it is not a good choice for the data.
3) Consider a Negative binomial model
4) Compare the model fits of the alternative models using AIC
When observing the AIC's of the various models the best fitted model would be glmnb being that it is the lowest AIC. The binomial fit was the worst with the negative binomial having better outcomes; with negative binmial model 1 being the best fit.
library(haven)
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(scales)
library(sur)
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
library(summarytools)
library(Rmisc)
## Loading required package: lattice
library(car)
## Loading required package: carData
##
## Attaching package: 'carData'
## The following objects are masked from 'package:sur':
##
## Anscombe, States
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(forcats)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble 3.1.6 v purrr 0.3.4
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.1.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x plyr::arrange() masks dplyr::arrange()
## x readr::col_factor() masks scales::col_factor()
## x purrr::compact() masks plyr::compact()
## x plyr::count() masks dplyr::count()
## x purrr::discard() masks scales::discard()
## x plyr::failwith() masks dplyr::failwith()
## x dplyr::filter() masks stats::filter()
## x plyr::id() masks dplyr::id()
## x dplyr::lag() masks stats::lag()
## x plyr::mutate() masks dplyr::mutate()
## x car::recode() masks dplyr::recode()
## x plyr::rename() masks dplyr::rename()
## x purrr::some() masks car::some()
## x plyr::summarise() masks dplyr::summarise()
## x plyr::summarize() masks dplyr::summarize()
## x tibble::view() masks summarytools::view()
library(survey)
## Loading required package: grid
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
## Loading required package: survival
##
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
##
## dotchart
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(grid)
library(Matrix)
library(caret)
##
## Attaching package: 'caret'
## The following object is masked from 'package:survival':
##
## cluster
## The following object is masked from 'package:purrr':
##
## lift
temp <- tempfile()
#Download the SAS dataset as a ZIP compressed archive
download.file("https://data.hrsa.gov/DataDownload/AHRF/AHRF_2019-2020_SAS.zip", temp)
#Read SAS data into R
ahrf<-haven::read_sas(unz(temp,
filename = "ahrf2020.sas7bdat"))
rm(temp)
ahrf2<-ahrf%>%
mutate(cofips = f00004,
coname = f00010,
state = f00011,
popn = f1198414,
poverty = f1441911,
laborfc14 = f1451014,
uninsured14 = f1551715,
workingpoor = 1000*(f1441911/f1451014), #Rate per 1000 working poor
majoritypop10 = f0453710,
hsdegree14 =f1448114,
medianage10= f1348310,
rucc = as.factor(f0002013) )%>%
mutate(rucc = droplevels(rucc, ""))%>%
dplyr::select(laborfc14,
uninsured14,
workingpoor,
state,
cofips,
coname,
popn,
medianage10,
poverty,
rucc,
majoritypop10,
hsdegree14)%>%
filter(complete.cases(.))%>%
as.data.frame()
options(tigris_class="sf")
library(tigris)
## To enable
## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
usco<-counties(cb = T, year= 2016)
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
usco$cofips<-usco$GEOID
sts<-states(cb = T, year = 2016)
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======== | 11%
|
|======== | 12%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================= | 47%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 51%
|
|==================================== | 51%
|
|===================================== | 53%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|============================================ | 63%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
sts<-st_boundary(sts)%>%
filter(!STATEFP %in% c("02", "15", "60", "66", "69", "72", "78"))%>%
st_transform(crs = 2163)
ahrf_m<-left_join(usco, ahrf2,
by = "cofips")%>%
filter(is.na(workingpoor)==F,
!STATEFP %in% c("02", "15", "60", "66", "69", "72", "78"))%>%
st_transform(crs = 2163)
glimpse(ahrf_m)
## Rows: 3,100
## Columns: 22
## $ STATEFP <chr> "19", "19", "20", "20", "20", "21", "21", "21", "21", "2~
## $ COUNTYFP <chr> "107", "189", "093", "123", "187", "005", "029", "049", ~
## $ COUNTYNS <chr> "00465242", "00465283", "00485011", "00485026", "0048505~
## $ AFFGEOID <chr> "0500000US19107", "0500000US19189", "0500000US20093", "0~
## $ GEOID <chr> "19107", "19189", "20093", "20123", "20187", "21005", "2~
## $ NAME <chr> "Keokuk", "Winnebago", "Kearny", "Mitchell", "Stanton", ~
## $ LSAD <chr> "06", "06", "06", "06", "06", "06", "06", "06", "06", "0~
## $ ALAND <dbl> 1500067253, 1037261946, 2254696689, 1817632928, 17621045~
## $ AWATER <dbl> 1929323, 3182052, 1133601, 44979981, 178555, 6311537, 83~
## $ cofips <chr> "19107", "19189", "20093", "20123", "20187", "21005", "2~
## $ laborfc14 <dbl> 5255, 5551, 1755, 2840, 1046, 11242, 41271, 17270, 47976~
## $ uninsured14 <dbl> 366, 309, 357, 291, 230, 725, 2441, 1351, 3432, 298, 385~
## $ workingpoor <dbl> 261.4653, 179.2470, 234.7578, 220.4225, 108.0306, 197.74~
## $ state <chr> "19", "19", "20", "20", "20", "21", "21", "21", "21", "2~
## $ coname <chr> "Keokuk", "Winnebago", "Kearny", "Mitchell", "Stanton", ~
## $ popn <dbl> 10231, 10559, 3915, 6284, 2111, 21888, 77955, 35758, 982~
## $ medianage10 <dbl> 43.8, 43.5, 35.5, 45.6, 35.6, 38.4, 38.2, 39.8, 38.8, 39~
## $ poverty <dbl> 1374, 995, 412, 626, 113, 2223, 7911, 5401, 14948, 2079,~
## $ rucc <fct> 08, 07, 09, 07, 09, 06, 01, 02, 03, 09, 03, 06, 05, 09, ~
## $ majoritypop10 <dbl> 98.4, 96.1, 87.3, 98.0, 83.7, 95.5, 96.8, 92.2, 91.2, 95~
## $ hsdegree14 <dbl> 92.5, 91.8, 74.1, 95.7, 81.8, 88.7, 88.0, 85.4, 90.0, 78~
## $ geometry <MULTIPOLYGON [m]> MULTIPOLYGON (((632645.1 -3..., MULTIPOLYGO~
ahrf_m%>%
ggplot()+
geom_histogram(aes(x = workingpoor))+
labs(title = "Distribution of the Rates of in US Counties",
subtitle = "2015 - 2019")+
xlab("Rate per 1,000 working poor")+
ylab ("Frequency")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
library(tmap)
## Warning: package 'tmap' was built under R version 4.1.3
tm_shape(ahrf_m)+
tm_polygons(col = "workingpoor",
border.col = NULL,
title="working poor Rt",
palette="Blues",
style="quantile",
n=5,
showNA=T, colorNA = "grey50")+
tm_format(format= "World",
main.title="US Working Poor rate by County",
legend.position = c("left", "bottom"),
main.title.position =c("center"))+
tm_scale_bar(position = c(.1,0))+
tm_compass()+
tm_shape(sts)+
tm_lines( col = "black")
library(VGAM)
## Loading required package: stats4
## Loading required package: splines
##
## Attaching package: 'VGAM'
## The following object is masked from 'package:caret':
##
## predictors
## The following object is masked from 'package:survey':
##
## calibrate
## The following object is masked from 'package:tidyr':
##
## fill
## The following object is masked from 'package:car':
##
## logit
library(svyVGAM)
library(gtsummary)
## #BlackLivesMatter
##
## Attaching package: 'gtsummary'
## The following object is masked from 'package:plyr':
##
## mutate
glm1<- glm(workingpoor ~ majoritypop10 + rucc + hsdegree14 + medianage10,
data = ahrf_m,
family =gaussian)
glm1<-glm1%>%
tbl_regression()
summary(glm1)
## Length Class Mode
## table_body 24 broom.helpers list
## table_styling 7 -none- list
## N 1 -none- numeric
## n 1 -none- numeric
## model_obj 30 glm list
## inputs 10 -none- list
## call_list 15 -none- list
glmb<- glm(cbind(poverty, laborfc14-uninsured14) ~ majoritypop10 + rucc + hsdegree14 + medianage10,
data = ahrf_m,
family = binomial)
glmb%>%
tbl_regression()
| Characteristic | log(OR)1 | 95% CI1 | p-value |
|---|---|---|---|
| Percent White Population 2010 | -0.01 | -0.01, -0.01 | <0.001 |
| rucc | |||
| 01 | — | — | |
| 02 | 0.28 | 0.28, 0.28 | <0.001 |
| 03 | 0.39 | 0.39, 0.39 | <0.001 |
| 04 | 0.46 | 0.46, 0.46 | <0.001 |
| 05 | 0.44 | 0.44, 0.44 | <0.001 |
| 06 | 0.46 | 0.46, 0.46 | <0.001 |
| 07 | 0.46 | 0.46, 0.46 | <0.001 |
| 08 | 0.52 | 0.51, 0.52 | <0.001 |
| 09 | 0.56 | 0.56, 0.56 | <0.001 |
| % Persons 25+ w/HS Dipl or more 2014-18 | -0.05 | -0.05, -0.05 | <0.001 |
| Median Age 2010 | -0.01 | -0.01, -0.01 | <0.001 |
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||
summary(glmb)
##
## Call:
## glm(formula = cbind(poverty, laborfc14 - uninsured14) ~ majoritypop10 +
## rucc + hsdegree14 + medianage10, family = binomial, data = ahrf_m)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -234.78 -11.22 0.20 12.04 291.79
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.720e+00 2.901e-03 1282.3 <2e-16 ***
## majoritypop10 -5.846e-03 1.371e-05 -426.4 <2e-16 ***
## rucc02 2.793e-01 4.615e-04 605.2 <2e-16 ***
## rucc03 3.936e-01 6.335e-04 621.2 <2e-16 ***
## rucc04 4.597e-01 8.716e-04 527.4 <2e-16 ***
## rucc05 4.421e-01 1.384e-03 319.5 <2e-16 ***
## rucc06 4.612e-01 8.707e-04 529.7 <2e-16 ***
## rucc07 4.575e-01 1.125e-03 406.7 <2e-16 ***
## rucc08 5.188e-01 2.074e-03 250.2 <2e-16 ***
## rucc09 5.596e-01 1.931e-03 289.8 <2e-16 ***
## hsdegree14 -4.918e-02 3.612e-05 -1361.5 <2e-16 ***
## medianage10 -6.742e-03 5.091e-05 -132.4 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 7794269 on 3099 degrees of freedom
## Residual deviance: 2984682 on 3088 degrees of freedom
## AIC: 3015257
##
## Number of Fisher Scoring iterations: 4
glmb%>%
tbl_regression(exponentiate=TRUE)
| Characteristic | OR1 | 95% CI1 | p-value |
|---|---|---|---|
| Percent White Population 2010 | 0.99 | 0.99, 0.99 | <0.001 |
| rucc | |||
| 01 | — | — | |
| 02 | 1.32 | 1.32, 1.32 | <0.001 |
| 03 | 1.48 | 1.48, 1.48 | <0.001 |
| 04 | 1.58 | 1.58, 1.59 | <0.001 |
| 05 | 1.56 | 1.55, 1.56 | <0.001 |
| 06 | 1.59 | 1.58, 1.59 | <0.001 |
| 07 | 1.58 | 1.58, 1.58 | <0.001 |
| 08 | 1.68 | 1.67, 1.69 | <0.001 |
| 09 | 1.75 | 1.74, 1.76 | <0.001 |
| % Persons 25+ w/HS Dipl or more 2014-18 | 0.95 | 0.95, 0.95 | <0.001 |
| Median Age 2010 | 0.99 | 0.99, 0.99 | <0.001 |
|
1
OR = Odds Ratio, CI = Confidence Interval
|
|||
summary(ahrf_m$workingpoor)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 35.21 231.98 330.56 364.97 454.48 1926.34
ahrf_m$workingpoor<- ahrf_m$workingpoor +1
glmp_s <- glm(poverty ~ offset(log(laborfc14)) + majoritypop10 + rucc + hsdegree14 + medianage10,
data=ahrf_m,
family=poisson)
glmp_s%>%
tbl_regression(exp = TRUE)
| Characteristic | IRR1 | 95% CI1 | p-value |
|---|---|---|---|
| Percent White Population 2010 | 0.99 | 0.99, 0.99 | <0.001 |
| rucc | |||
| 01 | — | — | |
| 02 | 1.30 | 1.30, 1.30 | <0.001 |
| 03 | 1.45 | 1.45, 1.45 | <0.001 |
| 04 | 1.55 | 1.55, 1.56 | <0.001 |
| 05 | 1.49 | 1.49, 1.50 | <0.001 |
| 06 | 1.55 | 1.55, 1.55 | <0.001 |
| 07 | 1.55 | 1.54, 1.55 | <0.001 |
| 08 | 1.64 | 1.64, 1.65 | <0.001 |
| 09 | 1.72 | 1.71, 1.72 | <0.001 |
| % Persons 25+ w/HS Dipl or more 2014-18 | 0.96 | 0.96, 0.96 | <0.001 |
| Median Age 2010 | 1.00 | 1.00, 1.00 | <0.001 |
|
1
IRR = Incidence Rate Ratio, CI = Confidence Interval
|
|||
scale<-sqrt(glmp_s$deviance/glmp_s$df.residual)
scale
## [1] 33.36306
1-pchisq(glmp_s$deviance,
df = glmp_s$df.residual)
## [1] 0
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:gtsummary':
##
## select
## The following object is masked from 'package:dplyr':
##
## select
glmnb<- glm.nb(poverty ~ offset(log(laborfc14)) + majoritypop10 + rucc + hsdegree14 + medianage10,
data=ahrf_m)
glmnb%>%
tbl_regression( exp= T)
| Characteristic | IRR1 | 95% CI1 | p-value |
|---|---|---|---|
| Percent White Population 2010 | 0.99 | 0.99, 0.99 | <0.001 |
| rucc | |||
| 01 | — | — | |
| 02 | 1.32 | 1.26, 1.38 | <0.001 |
| 03 | 1.44 | 1.37, 1.50 | <0.001 |
| 04 | 1.53 | 1.45, 1.61 | <0.001 |
| 05 | 1.51 | 1.40, 1.63 | <0.001 |
| 06 | 1.46 | 1.40, 1.53 | <0.001 |
| 07 | 1.48 | 1.41, 1.55 | <0.001 |
| 08 | 1.54 | 1.46, 1.63 | <0.001 |
| 09 | 1.46 | 1.40, 1.53 | <0.001 |
| % Persons 25+ w/HS Dipl or more 2014-18 | 0.96 | 0.96, 0.96 | <0.001 |
| Median Age 2010 | 1.00 | 1.00, 1.01 | 0.039 |
|
1
IRR = Incidence Rate Ratio, CI = Confidence Interval
|
|||
summary(glmnb)
##
## Call:
## glm.nb(formula = poverty ~ offset(log(laborfc14)) + majoritypop10 +
## rucc + hsdegree14 + medianage10, data = ahrf_m, init.theta = 9.591768601,
## link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -5.3482 -0.7375 -0.0526 0.5451 4.2687
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.7252555 0.0906498 30.064 <2e-16 ***
## majoritypop10 -0.0082458 0.0004223 -19.525 <2e-16 ***
## rucc02 0.2740366 0.0229773 11.926 <2e-16 ***
## rucc03 0.3622826 0.0234321 15.461 <2e-16 ***
## rucc04 0.4245816 0.0273643 15.516 <2e-16 ***
## rucc05 0.4119731 0.0378603 10.881 <2e-16 ***
## rucc06 0.3810258 0.0216493 17.600 <2e-16 ***
## rucc07 0.3908380 0.0231282 16.899 <2e-16 ***
## rucc08 0.4333748 0.0285743 15.167 <2e-16 ***
## rucc09 0.3810267 0.0246276 15.472 <2e-16 ***
## hsdegree14 -0.0410839 0.0010613 -38.711 <2e-16 ***
## medianage10 0.0029610 0.0014324 2.067 0.0387 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(9.5918) family taken to be 1)
##
## Null deviance: 7174.7 on 3099 degrees of freedom
## Residual deviance: 3168.5 on 3088 degrees of freedom
## AIC: 53887
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 9.592
## Std. Err.: 0.242
##
## 2 x log-likelihood: -53860.785
library(gamlss)
## Warning: package 'gamlss' was built under R version 4.1.3
## Loading required package: gamlss.data
##
## Attaching package: 'gamlss.data'
## The following object is masked from 'package:datasets':
##
## sleep
## Loading required package: gamlss.dist
## Warning: package 'gamlss.dist' was built under R version 4.1.3
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
##
## collapse
## Loading required package: parallel
## ********** GAMLSS Version 5.4-1 **********
## For more on GAMLSS look at https://www.gamlss.com/
## Type gamlssNews() to see new features/changes/bug fixes.
##
## Attaching package: 'gamlss'
## The following object is masked from 'package:caret':
##
## calibration
library(splines)
glmnb2<-gamlss(poverty ~ offset(log(laborfc14)) + majoritypop10 + rucc + hsdegree14 + medianage10,
family = NBII,
data=ahrf_m)
## GAMLSS-RS iteration 1: Global Deviance = 66522.62
## GAMLSS-RS iteration 2: Global Deviance = 65543.46
## GAMLSS-RS iteration 3: Global Deviance = 64324.03
## GAMLSS-RS iteration 4: Global Deviance = 62774.12
## GAMLSS-RS iteration 5: Global Deviance = 60828.06
## GAMLSS-RS iteration 6: Global Deviance = 58629.86
## GAMLSS-RS iteration 7: Global Deviance = 57048.52
## GAMLSS-RS iteration 8: Global Deviance = 56658.46
## GAMLSS-RS iteration 9: Global Deviance = 56634.27
## GAMLSS-RS iteration 10: Global Deviance = 56633.65
## GAMLSS-RS iteration 11: Global Deviance = 56633.64
## GAMLSS-RS iteration 12: Global Deviance = 56633.64
summary(glmnb2)
## ******************************************************************
## Family: c("NBII", "Negative Binomial type II")
##
## Call: gamlss(formula = poverty ~ offset(log(laborfc14)) +
## majoritypop10 + rucc + hsdegree14 + medianage10,
## family = NBII, data = ahrf_m)
##
## Fitting method: RS()
##
## ------------------------------------------------------------------
## Mu link function: log
## Mu Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.2867006 0.0727581 31.429 <2e-16 ***
## majoritypop10 -0.0059825 0.0003706 -16.141 <2e-16 ***
## rucc02 0.2800264 0.0133278 21.011 <2e-16 ***
## rucc03 0.3944736 0.0179243 22.008 <2e-16 ***
## rucc04 0.4722770 0.0242087 19.509 <2e-16 ***
## rucc05 0.4289190 0.0375942 11.409 <2e-16 ***
## rucc06 0.5361440 0.0228504 23.463 <2e-16 ***
## rucc07 0.5447936 0.0285650 19.072 <2e-16 ***
## rucc08 0.7382480 0.0453919 16.264 <2e-16 ***
## rucc09 0.9069472 0.0389288 23.298 <2e-16 ***
## hsdegree14 -0.0371041 0.0009444 -39.290 <2e-16 ***
## medianage10 -0.0008204 0.0015103 -0.543 0.587
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## Sigma link function: log
## Sigma Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.04854 0.02627 268.3 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------------------------------
## No. of observations in the fit: 3100
## Degrees of Freedom for the fit: 13
## Residual Deg. of Freedom: 3087
## at cycle: 12
##
## Global Deviance: 56633.64
## AIC: 56659.64
## SBC: 56738.15
## ******************************************************************
AIC(glmp_s, glmb,glmnb, glmnb2)
## df AIC
## glmp_s 12 3468919.52
## glmb 12 3015257.04
## glmnb 13 53886.78
## glmnb2 13 56659.64