This example will use R to downloard American Coummunity Survey summary file tables using the tidycensus package. The goal of this example is to illustrate how to download data from the Census API using R and to illustrate how to create basic descriptive maps of attributes.

The example will use Texas data from the 2010 American Community Survey summary file.

Get a Census developer API Key

Obtain one at http://api.census.gov/data/key_signup.html

Save your API key to your working directory

use census_api_key(key = "yourkeyhere", install = T)

one time to install your key for use in tidycensus

library(tidycensus)
census_api_key(key ="f67be5a86e696eebf0c84a5a20d85f2c04f7e9ef", overwrite= T  )
## To install your API key for use in future sessions, run this function with `install = TRUE`.
options(tigris_use_cache = TRUE)

Look at available ACS variables

library(tidyverse); library(sf)
## -- Attaching packages ---------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0     v purrr   0.2.5
## v tibble  1.4.2     v dplyr   0.7.6
## v tidyr   0.8.1     v stringr 1.3.1
## v readr   1.1.1     v forcats 0.3.0
## -- Conflicts ------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
v10_Profile <- load_variables(2010, "acs5/profile", cache = TRUE) #demographic profile tables
v10_tables <- load_variables(2010 , "acs5", cache = TRUE) #all tables
#v10_sf1_tables <- load_variables(2010 , "sf1", cache = TRUE) #all tables for 2010 SF1

View(v10_Profile)

#Search for variables by 
v10_Profile[grep(x = v10_Profile$label, "owner"), c("name", "label")]
## # A tibble: 4 x 2
##   name       label                                                        
##   <chr>      <chr>                                                        
## 1 DP04_0004  Estimate!!HOUSING OCCUPANCY!!Homeowner vacancy rate          
## 2 DP04_0004P Percent!!HOUSING OCCUPANCY!!Homeowner vacancy rate           
## 3 DP04_0047  Estimate!!HOUSING TENURE!!Average household size of owner-oc~
## 4 DP04_0047P Percent!!HOUSING TENURE!!Average household size of owner-occ~
v10_Profile[grep(x = v10_Profile$label, "value"), c("name", "label")]
## # A tibble: 0 x 2
## # ... with 2 variables: name <chr>, label <chr>

Extract from ACS housing data for 2010 for TX Census Tracts

tx_acs<-get_acs(geography = "tract", state="TX", year = 2010,
                variables=c( "DP04_0080PE", "DP04_0089E") ,
                geometry = T, output = "wide")
## Getting data from the 2006-2010 5-year ACS
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
## Getting data from the 2006-2010 5-year ACS
## Using the ACS Data Profile
#create a county FIPS code - 5 digit

tx_acs$county<-substr(tx_acs$GEOID, 1, 5)

#rename variables and filter missing cases
tx_acs2<-tx_acs%>%
  mutate(owner= DP04_0080PE, homevalue=DP04_0089E) %>%
#  st_transform(crs = 102740)%>%
  filter(complete.cases(owner, homevalue))

class(tx_acs2)
## [1] "sf"         "tbl_df"     "tbl"        "data.frame"

Test for variation across census tracts/counties in Texas

fit0<-lm(owner~factor(county), data=tx_acs2)
anova(fit0)
## Analysis of Variance Table
## 
## Response: owner
##                  Df  Sum Sq Mean Sq F value    Pr(>F)    
## factor(county)  253  647079 2557.62  11.919 < 2.2e-16 ***
## Residuals      4898 1051061  214.59                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following object is masked from 'package:tidyr':
## 
##     expand

Fit the random intercept model

fit1<-lmer(owner~1+(1|county), data= tx_acs2, REML= T)
summary(fit1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: owner ~ 1 + (1 | county)
##    Data: tx_acs2
## 
## REML criterion at convergence: 42696.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4128 -0.5804 -0.2579  0.3396  6.4370 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  county   (Intercept) 145.9    12.08   
##  Residual             214.3    14.64   
## Number of obs: 5152, groups:  county, 254
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  28.8494     0.8912   32.37

Include homevalue variable

fit2<-lmer(owner~homevalue+(1|county), data= tx_acs2, REML= T)
summary(fit2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: owner ~ homevalue + (1 | county)
##    Data: tx_acs2
## 
## REML criterion at convergence: 42356.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7379 -0.5970 -0.2141  0.3946  6.3198 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  county   (Intercept) 127.1    11.27   
##  Residual             200.6    14.16   
## Number of obs: 5152, groups:  county, 254
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) 35.225625   0.903791   38.98
## homevalue   -0.006173   0.000322  -19.17
## 
## Correlation of Fixed Effects:
##           (Intr)
## homevalue -0.373

Compare the two fits using a Likelihood ratio test

anova(fit1, fit2)
## refitting model(s) with ML (instead of REML)
## Data: tx_acs2
## Models:
## fit1: owner ~ 1 + (1 | county)
## fit2: owner ~ homevalue + (1 | county)
##      Df   AIC   BIC logLik deviance  Chisq Chi Df Pr(>Chisq)    
## fit1  3 42704 42724 -21349    42698                             
## fit2  4 42352 42378 -21172    42344 354.89      1  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Extract ICC from each fit

library(sjstats)
icc(fit1)
## 
## Linear mixed model
## 
## Family : gaussian (identity)
## Formula: owner ~ 1 + (1 | county)
## 
##   ICC (county): 0.4051
icc(fit2)
## 
## Linear mixed model
## 
## Family : gaussian (identity)
## Formula: owner ~ homevalue + (1 | county)
## 
##   ICC (county): 0.3878

The ICC in the second model is lower than the first because I reduced the variability by using a control variable.