acs-class: Class '"acs"'

Description Objects from the Class Slots Methods Author(s) Examples

Description

The acs class provides a convenient wrapper for demographic data from the U.S. Census, especially the American Community Survey. Estimates and standard errors are kept together, along with geographic information and metadata necessary to manipulate and analyze data in this form.

Objects from the Class

acs objects can be created by calls of the form new("acs", ...), or through helper functions provided by the package (currently read.acs and acs.fetch), or from the output of subsetting or other calls on existing acs objects. Once created, acs objects can be manipulated through new methods to deal appropriately with common analytical tasks such as combining subgroups or geographies, mathematical operations on estimates, and computing (and plotting) confidence intervals.

Slots

endyear:

Object of class "integer" indicating the last year included in the dataset (e.g., 2012 for data from the 2008–2012 ACS)

span:

Object of class "integer" representing the number of years the dataset spans (e.g., 3 for data from the 2011–2013 ACS); for decennial census datasets (SF1 and SF3), span = 0.

geography:

Object of class "data.frame" containing columns extracted from the data's geographic header: typically includes geographic place names, census summary level values, and unique numeric identifiers, but can contain any geographic names or labels desired. When acs objects are created or modified, the first geography column will be used to label estimates and standard errors.

acs.colnames:

Object of class "character" giving the variable names for each column

modified:

Object of class "logical" to indicate whether the object has been modified since construction

acs.units:

Object of class "factor" designating the type of units in each column (e.g., count or percentage or dollars); only used minimally, to check appropriateness of some operations; mostly reserved for future functionality

currency.year:

Object of class "integer" indicating the year that all currency values have been adjusted to (by default the same as endyear, but able to be modified by the user for comparisons with other years; see currency.convert.)

estimate:

Object of class "matrix" holding the reported ACS estimates

standard.error:

Object of class "matrix" holding the calculated values of the standard errors for each estimate, derived from the reported 90% confidence intervals

Methods

acs.colnames

signature(object = "acs"): Standard accessor function; returns character vector

acs.units

signature(object = "acs"): Standard accessor function; returns factor vector

currency.year

signature(object = "acs"): Standard accessor function; returns integer

endyear

signature(object = "acs"): Standard accessor function; returns integer

estimate

signature(object = "acs"): Standard accessor function; returns matrix

geography

signature(object = "acs"): Standard accessor function; returns data.frame

modified

signature(object = "acs"): Standard accessor function; return logical

span

signature(object = "acs"): Standard accessor function; returns integer

standard.error

signature(object = "acs"): Standard accessor function; returns matrix

sum

signature(object = "acs"): Aggregates (adds) all estimates in the object, and adds the corresponding standard errors in a statistically appropriate way; returns new acs object

summary

signature(object = "acs"): Prints standard summary data on both estimates and standard errors

confint

signature(object = "acs"): Prints estimates with confidence intervals

[

signature(x = "acs"): subsetting works for acs objects using standard [i,j] square bracket notation, similar to two-dimensional matrices; returns a new acs object with estimates, standard errors, and associated metadata for "i" rows (geographies) and "j" columns (variable columns); essentially, subsetting for this class is structured to mirror standard operations on matrix objects

[<-

signature(x = "acs"): new values may be replaced/assigned to an existing acs object using standard [i,j] bracket notation. The assignment can accept a number of different forms: a valid acs object (including a subsetted one), a list of two matrices (ideally named "estimate" and "error" or "standard.error"), or a numeric object which may be coerced into a matrix (to be used as estimates, with zero-values assigned to corresponding standard errors).

In addition to these methods, new methods for basic arithmetic functions (+, -, *, /) have been provided to deal appropriately with combining estimates and standard errors.

Author(s)

Ezra Haber Glenn eglenn@mit.edu

Examples

 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
showClass("acs")
# load some data from the ACS
data(kansas09)
str(kansas09)

# access slots
endyear(kansas09)
span(kansas09)
estimate(kansas09)[1:5,1:5]
standard.error(kansas09[1:5,1:5])


# subset
kansas09[1:4,6:9]

# more complicated subsets
kansas09[c("Linn County, Kansas", "Wilson County, Kansas") ,
   grep(pattern="21.years", x=acs.colnames(kansas09))]

# addition on estimates and errors
kansas09[1:4,25]+kansas09[1:4,49]

# can even multiply and divide
# males per female, by county
kansas09[1:4,2]/kansas09[1:4,26]

# (males<5 plus females<5) * 12
(kansas09[7,3]+kansas09[7,27]) * 12

# some replacement: males<5 as a percentage of all males
kansas09[,3]=kansas09[,3]/kansas09[,2]

Example output

Loading required package: stringr
Loading required package: XML

Attaching package: 'acs'

The following object is masked from 'package:base':

    apply

Class "acs" [package "acs"]

Slots:
                                                                  
Name:         endyear           span      geography   acs.colnames
Class:        integer        integer     data.frame      character
                                                                  
Name:        modified      acs.units  currency.year       estimate
Class:        logical         factor        integer         matrix
                     
Name:  standard.error
Class:         matrix
Formal class 'acs' [package ".GlobalEnv"] with 9 slots
  ..@ endyear       : int 2009
  ..@ span          : int 5
  ..@ geography     :'data.frame':	105 obs. of  4 variables:
  .. ..$ Geography               : chr [1:105] "Allen County, Kansas" "Anderson County, Kansas" "Atchison County, Kansas" "Barber County, Kansas" ...
  .. ..$ Geographic.Summary.Level: int [1:105] 50 50 50 50 50 50 50 50 50 50 ...
  .. ..$ Geography.Identifier.1  : int [1:105] 20001 20003 20005 20007 20009 20011 20013 20015 20017 20019 ...
  .. ..$ Geography.Identifier    : chr [1:105] "05000US20001" "05000US20003" "05000US20005" "05000US20007" ...
  ..@ acs.colnames  : chr [1:55] "Universe...TOTAL.POPULATION..Total" "Universe...TOTAL.POPULATION..Male" "Universe...TOTAL.POPULATION..Male..Under.5.years" "Universe...TOTAL.POPULATION..Male..5.to.9.years" ...
  ..@ modified      : logi TRUE
  ..@ acs.units     : Factor w/ 5 levels "count","dollars",..: 1 1 1 1 1 1 1 1 1 1 ...
  ..@ currency.year : int 2009
  ..@ estimate      : num [1:105, 1:55] 13403 7900 16469 4714 27654 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:105] "Allen County, Kansas" "Anderson County, Kansas" "Atchison County, Kansas" "Barber County, Kansas" ...
  .. .. ..$ : chr [1:55] "Universe...TOTAL.POPULATION..Total" "Universe...TOTAL.POPULATION..Male" "Universe...TOTAL.POPULATION..Male..Under.5.years" "Universe...TOTAL.POPULATION..Male..5.to.9.years" ...
  ..@ standard.error: num [1:105, 1:55] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:105] "Allen County, Kansas" "Anderson County, Kansas" "Atchison County, Kansas" "Barber County, Kansas" ...
  .. .. ..$ : chr [1:55] "Universe...TOTAL.POPULATION..Total" "Universe...TOTAL.POPULATION..Male" "Universe...TOTAL.POPULATION..Male..Under.5.years" "Universe...TOTAL.POPULATION..Male..5.to.9.years" ...
[1] 2009
[1] 5
                        Universe...TOTAL.POPULATION..Total
Allen County, Kansas                                 13403
Anderson County, Kansas                               7900
Atchison County, Kansas                              16469
Barber County, Kansas                                 4714
Barton County, Kansas                                27654
                        Universe...TOTAL.POPULATION..Male
Allen County, Kansas                                 6580
Anderson County, Kansas                              3911
Atchison County, Kansas                              7925
Barber County, Kansas                                2332
Barton County, Kansas                               13313
                        Universe...TOTAL.POPULATION..Male..Under.5.years
Allen County, Kansas                                                 399
Anderson County, Kansas                                              273
Atchison County, Kansas                                              502
Barber County, Kansas                                                124
Barton County, Kansas                                                885
                        Universe...TOTAL.POPULATION..Male..5.to.9.years
Allen County, Kansas                                                304
Anderson County, Kansas                                             272
Atchison County, Kansas                                             657
Barber County, Kansas                                               139
Barton County, Kansas                                               841
                        Universe...TOTAL.POPULATION..Male..10.to.14.years
Allen County, Kansas                                                  578
Anderson County, Kansas                                               318
Atchison County, Kansas                                               515
Barber County, Kansas                                                 129
Barton County, Kansas                                                 992
                        Universe...TOTAL.POPULATION..Total
Allen County, Kansas                                     0
Anderson County, Kansas                                  0
Atchison County, Kansas                                  0
Barber County, Kansas                                    0
Barton County, Kansas                                    0
                        Universe...TOTAL.POPULATION..Male
Allen County, Kansas                             69.90881
Anderson County, Kansas                          29.17933
Atchison County, Kansas                          69.30091
Barber County, Kansas                            26.13982
Barton County, Kansas                            68.69301
                        Universe...TOTAL.POPULATION..Male..Under.5.years
Allen County, Kansas                                           12.765957
Anderson County, Kansas                                         6.686930
Atchison County, Kansas                                        17.629179
Barber County, Kansas                                           3.647416
Barton County, Kansas                                           1.215805
                        Universe...TOTAL.POPULATION..Male..5.to.9.years
Allen County, Kansas                                           47.41641
Anderson County, Kansas                                        27.35562
Atchison County, Kansas                                        71.12462
Barber County, Kansas                                          20.06079
Barton County, Kansas                                          77.81155
                        Universe...TOTAL.POPULATION..Male..10.to.14.years
Allen County, Kansas                                             46.80851
Anderson County, Kansas                                          28.57143
Atchison County, Kansas                                          65.04559
Barber County, Kansas                                            19.45289
Barton County, Kansas                                            77.81155
ACS DATA: 
 2005 -- 2009 ;
  Estimates w/90% confidence intervals;
  for different intervals, see confint()
                        Universe...TOTAL.POPULATION..Male..15.to.17.years
Allen County, Kansas    283 +/- 11                                       
Anderson County, Kansas 184 +/- 3                                        
Atchison County, Kansas 412 +/- 36                                       
Barber County, Kansas   103 +/- 109                                      
                        Universe...TOTAL.POPULATION..Male..18.and.19.years
Allen County, Kansas    267 +/- 132                                       
Anderson County, Kansas 121 +/- 50                                        
Atchison County, Kansas 375 +/- 254                                       
Barber County, Kansas   7 +/- 11                                          
                        Universe...TOTAL.POPULATION..Male..20.years
Allen County, Kansas    108 +/- 83                                 
Anderson County, Kansas 75 +/- 49                                  
Atchison County, Kansas 182 +/- 135                                
Barber County, Kansas   5 +/- 9                                    
                        Universe...TOTAL.POPULATION..Male..21.years
Allen County, Kansas    33 +/- 34                                  
Anderson County, Kansas 4 +/- 7                                    
Atchison County, Kansas 168 +/- 96                                 
Barber County, Kansas   81 +/- 49                                  
ACS DATA: 
 2005 -- 2009 ;
  Estimates w/90% confidence intervals;
  for different intervals, see confint()
                      Universe...TOTAL.POPULATION..Male..21.years
Linn County, Kansas   20 +/- 29                                  
Wilson County, Kansas 110 +/- 63                                 
                      Universe...TOTAL.POPULATION..Female..21.years
Linn County, Kansas   11 +/- 15                                    
Wilson County, Kansas 44 +/- 35                                    
ACS DATA: 
 2005 -- 2009 ;
  Estimates w/90% confidence intervals;
  for different intervals, see confint()
                        ( Universe...TOTAL.POPULATION..Male..85.years.and.over + Universe...TOTAL.POPULATION..Female..85.years.and.over )
Allen County, Kansas    310 +/- 80.4300938703916                                                                                         
Anderson County, Kansas 246 +/- 99.9249718538864                                                                                         
Atchison County, Kansas 425 +/- 112.16059914248                                                                                          
Barber County, Kansas   168 +/- 81.1233628494283                                                                                         
ACS DATA: 
 2005 -- 2009 ;
  Estimates w/90% confidence intervals;
  for different intervals, see confint()
                        ( Universe...TOTAL.POPULATION..Male : Universe...TOTAL.POPULATION..Female )
Allen County, Kansas    0.964385167814744 +/- 0.0234156104043347                                   
Anderson County, Kansas 0.980446227124593 +/- 0.016851805022657                                    
Atchison County, Kansas 0.927551498127341 +/- 0.0181987328141948                                   
Barber County, Kansas   0.979009235936188 +/- 0.0252629434427822                                   
Warning message:
In kansas09[1:4, 2]/kansas09[1:4, 26] :
  ** using the more conservative formula for ratio-type
    dividing, which does not assume that numerator is a subset of
    denominator; for more precise results when seeking a proportion
    and not a ratio, use divide.acs(..., method="proportion") **
ACS DATA: 
 2005 -- 2009 ;
  Estimates w/90% confidence intervals;
  for different intervals, see confint()
                     ( ( Universe...TOTAL.POPULATION..Male..Under.5.years + Universe...TOTAL.POPULATION..Female..Under.5.years ) * 12 )
Brown County, Kansas 8088 +/- 461.024945095165                                                                                         
Warning messages:
1: In kansas09[, 3]/kansas09[, 2] :
  ** using the more conservative formula for ratio-type
    dividing, which does not assume that numerator is a subset of
    denominator; for more precise results when seeking a proportion
    and not a ratio, use divide.acs(..., method="proportion") **
2: acs.colnames do not match but all rows changes;
using new acs.colnames 

acs documentation built on May 1, 2019, 8:41 p.m.