Tidy Data, Weighted Insights

Analyzing Complex Survey Data in R

Book overview

Analysis framework

Loading packages

# install.packages(c("srvyr", "gtsummary"))
# pak::pak("tidy-survey-r/srvyrexploR)
library(srvyr)
library(gtsummary)
library(srvyrexploR)

summary(recs_2020)
     DOEID           ClimateRegion_BA         Urbanicity          Region    
 Min.   :100001   Cold       :7116    Urban Area   :12395   Northeast:3657  
 1st Qu.:104625   Mixed-Humid:5579    Urban Cluster: 2020   Midwest  :3832  
 Median :109248   Hot-Humid  :2545    Rural        : 4081   South    :6426  
 Mean   :109248   Hot-Dry    :1577                          West     :4581  
 3rd Qu.:113872   Marine     : 911                                          
 Max.   :118496   Very-Cold  : 572                                          
                  (Other)    : 196                                          
   REGIONC                        Division     STATE_FIPS       
 Length:18496       South Atlantic    :3256   Length:18496      
 Class :character   Pacific           :2497   Class :character  
 Mode  :character   East North Central:2014   Mode  :character  
                    Middle Atlantic   :1977                     
                    West South Central:1827                     
                    West North Central:1818                     
                    (Other)           :5107                     
  state_postal           state_name        HDD65           CDD65     
 CA     : 1152   California   : 1152   Min.   :    0   Min.   :   0  
 TX     : 1016   Texas        : 1016   1st Qu.: 2434   1st Qu.: 814  
 NY     :  904   New York     :  904   Median : 4396   Median :1179  
 FL     :  655   Florida      :  655   Mean   : 4272   Mean   :1526  
 PA     :  617   Pennsylvania :  617   3rd Qu.: 5810   3rd Qu.:1805  
 MA     :  552   Massachusetts:  552   Max.   :17383   Max.   :5534  
 (Other):13600   (Other)      :13600                                 
    HDD30YR         CDD30YR                       HousingUnitType 
 Min.   :    0   Min.   :   0   Mobile home               :  974  
 1st Qu.: 2898   1st Qu.: 601   Single-family detached    :12319  
 Median : 4825   Median :1020   Single-family attached    : 1751  
 Mean   : 4679   Mean   :1310   Apartment: 2-4 Units      : 1013  
 3rd Qu.: 6290   3rd Qu.:1703   Apartment: 5 or more units: 2439  
 Max.   :16071   Max.   :4905                                     
                                                                  
        YearMade      TOTSQFT_EN       TOTHSQFT        TOTCSQFT    
 1970-1979  :2817   Min.   :  200   Min.   :    0   Min.   :    0  
 2000-2009  :2748   1st Qu.: 1100   1st Qu.: 1000   1st Qu.:  460  
 Before 1950:2721   Median : 1700   Median : 1520   Median : 1200  
 1990-1999  :2451   Mean   : 1960   Mean   : 1744   Mean   : 1394  
 1980-1989  :2435   3rd Qu.: 2510   3rd Qu.: 2300   3rd Qu.: 2000  
 1960-1969  :1867   Max.   :15000   Max.   :15000   Max.   :14600  
 (Other)    :3457                                                  
 SpaceHeatingUsed   ACUsed       
 Mode :logical    Mode :logical  
 FALSE:751        FALSE:2325     
 TRUE :17745      TRUE :16171    
                                 
                                 
                                 
                                 
                                                               HeatingBehavior
 Set one temp and leave it                                             :7806  
 Manually adjust at night/no one home                                  :4654  
 Programmable or smart thermostat automatically adjusts the temperature:3310  
 Turn on or off as needed                                              :1491  
 No control                                                            : 438  
 Other                                                                 :  46  
 NA's                                                                  : 751  
 WinterTempDay   WinterTempAway  WinterTempNight
 Min.   :50.00   Min.   :50.00   Min.   :50.00  
 1st Qu.:68.00   1st Qu.:65.00   1st Qu.:65.00  
 Median :70.00   Median :68.00   Median :68.00  
 Mean   :69.77   Mean   :67.45   Mean   :68.01  
 3rd Qu.:72.00   3rd Qu.:70.00   3rd Qu.:70.00  
 Max.   :90.00   Max.   :90.00   Max.   :90.00  
 NA's   :751     NA's   :751     NA's   :751    
                                                                  ACBehavior  
 Set one temp and leave it                                             :6738  
 Manually adjust at night/no one home                                  :3637  
 Programmable or smart thermostat automatically adjusts the temperature:2638  
 Turn on or off as needed                                              :2746  
 No control                                                            : 409  
 Other                                                                 :   3  
 NA's                                                                  :2325  
 SummerTempDay   SummerTempAway  SummerTempNight    NWEIGHT       
 Min.   :50.00   Min.   :50.00   Min.   :50.00   Min.   :  437.9  
 1st Qu.:70.00   1st Qu.:70.00   1st Qu.:68.00   1st Qu.: 4018.7  
 Median :72.00   Median :74.00   Median :72.00   Median : 6119.4  
 Mean   :72.01   Mean   :73.45   Mean   :71.22   Mean   : 6678.7  
 3rd Qu.:75.00   3rd Qu.:78.00   3rd Qu.:74.00   3rd Qu.: 8890.0  
 Max.   :90.00   Max.   :90.00   Max.   :90.00   Max.   :29279.1  
 NA's   :2325    NA's   :2325    NA's   :2325                     
    NWEIGHT1        NWEIGHT2        NWEIGHT3        NWEIGHT4    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3950   1st Qu.: 3951   1st Qu.: 3954   1st Qu.: 3953  
 Median : 6136   Median : 6151   Median : 6151   Median : 6153  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8976   3rd Qu.: 8979   3rd Qu.: 8994   3rd Qu.: 8998  
 Max.   :30015   Max.   :29422   Max.   :29431   Max.   :29494  
                                                                
    NWEIGHT5        NWEIGHT6        NWEIGHT7        NWEIGHT8    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3957   1st Qu.: 3966   1st Qu.: 3944   1st Qu.: 3956  
 Median : 6134   Median : 6147   Median : 6135   Median : 6151  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8987   3rd Qu.: 8984   3rd Qu.: 8998   3rd Qu.: 8988  
 Max.   :30039   Max.   :29419   Max.   :29586   Max.   :29499  
                                                                
    NWEIGHT9       NWEIGHT10       NWEIGHT11       NWEIGHT12    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3947   1st Qu.: 3961   1st Qu.: 3950   1st Qu.: 3947  
 Median : 6139   Median : 6163   Median : 6140   Median : 6160  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8974   3rd Qu.: 8994   3rd Qu.: 8991   3rd Qu.: 8988  
 Max.   :29845   Max.   :29635   Max.   :29681   Max.   :29849  
                                                                
   NWEIGHT13       NWEIGHT14       NWEIGHT15       NWEIGHT16    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3967   1st Qu.: 3962   1st Qu.: 3958   1st Qu.: 3958  
 Median : 6142   Median : 6154   Median : 6145   Median : 6133  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8977   3rd Qu.: 8981   3rd Qu.: 8997   3rd Qu.: 8979  
 Max.   :29843   Max.   :30184   Max.   :29970   Max.   :29825  
                                                                
   NWEIGHT17       NWEIGHT18       NWEIGHT19       NWEIGHT20    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3958   1st Qu.: 3937   1st Qu.: 3947   1st Qu.: 3943  
 Median : 6126   Median : 6155   Median : 6153   Median : 6139  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8977   3rd Qu.: 8993   3rd Qu.: 8979   3rd Qu.: 8992  
 Max.   :30606   Max.   :29689   Max.   :29336   Max.   :30274  
                                                                
   NWEIGHT21       NWEIGHT22       NWEIGHT23       NWEIGHT24    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3960   1st Qu.: 3964   1st Qu.: 3943   1st Qu.: 3946  
 Median : 6135   Median : 6149   Median : 6148   Median : 6136  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8956   3rd Qu.: 8988   3rd Qu.: 8980   3rd Qu.: 8978  
 Max.   :29766   Max.   :29791   Max.   :30126   Max.   :29946  
                                                                
   NWEIGHT25       NWEIGHT26       NWEIGHT27       NWEIGHT28    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3952   1st Qu.: 3966   1st Qu.: 3942   1st Qu.: 3956  
 Median : 6150   Median : 6136   Median : 6125   Median : 6149  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8972   3rd Qu.: 8980   3rd Qu.: 8996   3rd Qu.: 8989  
 Max.   :30445   Max.   :29893   Max.   :30030   Max.   :29599  
                                                                
   NWEIGHT29       NWEIGHT30       NWEIGHT31       NWEIGHT32    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3970   1st Qu.: 3956   1st Qu.: 3944   1st Qu.: 3954  
 Median : 6146   Median : 6149   Median : 6144   Median : 6159  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8979   3rd Qu.: 8991   3rd Qu.: 8994   3rd Qu.: 8982  
 Max.   :30136   Max.   :29895   Max.   :29604   Max.   :29310  
                                                                
   NWEIGHT33       NWEIGHT34       NWEIGHT35       NWEIGHT36    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3964   1st Qu.: 3950   1st Qu.: 3967   1st Qu.: 3948  
 Median : 6148   Median : 6139   Median : 6141   Median : 6149  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8993   3rd Qu.: 8985   3rd Qu.: 8990   3rd Qu.: 8979  
 Max.   :29408   Max.   :29564   Max.   :30437   Max.   :27896  
                                                                
   NWEIGHT37       NWEIGHT38       NWEIGHT39       NWEIGHT40    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3955   1st Qu.: 3954   1st Qu.: 3940   1st Qu.: 3959  
 Median : 6133   Median : 6139   Median : 6147   Median : 6144  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8975   3rd Qu.: 8974   3rd Qu.: 8991   3rd Qu.: 8980  
 Max.   :30596   Max.   :30130   Max.   :29262   Max.   :30344  
                                                                
   NWEIGHT41       NWEIGHT42       NWEIGHT43       NWEIGHT44    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3975   1st Qu.: 3949   1st Qu.: 3947   1st Qu.: 3956  
 Median : 6153   Median : 6137   Median : 6157   Median : 6148  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8982   3rd Qu.: 8988   3rd Qu.: 9005   3rd Qu.: 8986  
 Max.   :29594   Max.   :29938   Max.   :29878   Max.   :29896  
                                                                
   NWEIGHT45       NWEIGHT46       NWEIGHT47       NWEIGHT48    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3952   1st Qu.: 3966   1st Qu.: 3938   1st Qu.: 3953  
 Median : 6149   Median : 6152   Median : 6150   Median : 6139  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8992   3rd Qu.: 8959   3rd Qu.: 8991   3rd Qu.: 8991  
 Max.   :29729   Max.   :29103   Max.   :30070   Max.   :29343  
                                                                
   NWEIGHT49       NWEIGHT50       NWEIGHT51       NWEIGHT52    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3947   1st Qu.: 3948   1st Qu.: 3958   1st Qu.: 3938  
 Median : 6146   Median : 6159   Median : 6150   Median : 6154  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8990   3rd Qu.: 8995   3rd Qu.: 8992   3rd Qu.: 9012  
 Max.   :29590   Max.   :30027   Max.   :29247   Max.   :29445  
                                                                
   NWEIGHT53       NWEIGHT54       NWEIGHT55       NWEIGHT56    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3959   1st Qu.: 3954   1st Qu.: 3945   1st Qu.: 3957  
 Median : 6156   Median : 6151   Median : 6143   Median : 6153  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 8979   3rd Qu.: 8973   3rd Qu.: 8977   3rd Qu.: 8995  
 Max.   :30131   Max.   :29439   Max.   :29216   Max.   :29203  
                                                                
   NWEIGHT57       NWEIGHT58       NWEIGHT59       NWEIGHT60    
 Min.   :    0   Min.   :    0   Min.   :    0   Min.   :    0  
 1st Qu.: 3942   1st Qu.: 3962   1st Qu.: 3965   1st Qu.: 3953  
 Median : 6138   Median : 6137   Median : 6144   Median : 6140  
 Mean   : 6679   Mean   : 6679   Mean   : 6679   Mean   : 6679  
 3rd Qu.: 9004   3rd Qu.: 8986   3rd Qu.: 8977   3rd Qu.: 8983  
 Max.   :29819   Max.   :29818   Max.   :29606   Max.   :29818  
                                                                
     BTUEL             DOLLAREL           BTUNG            DOLLARNG     
 Min.   :   143.3   Min.   : -889.5   Min.   :      0   Min.   :   0.0  
 1st Qu.: 20205.8   1st Qu.:  836.5   1st Qu.:      0   1st Qu.:   0.0  
 Median : 31890.0   Median : 1257.9   Median :  22012   Median : 313.9  
 Mean   : 37016.2   Mean   : 1424.8   Mean   :  36960   Mean   : 396.0  
 3rd Qu.: 48298.0   3rd Qu.: 1819.0   3rd Qu.:  62714   3rd Qu.: 644.9  
 Max.   :628155.5   Max.   :15680.2   Max.   :1134709   Max.   :8155.0  
                                                                        
     BTULP           DOLLARLP           BTUFO           DOLLARFO      
 Min.   :     0   Min.   :   0.00   Min.   :     0   Min.   :   0.00  
 1st Qu.:     0   1st Qu.:   0.00   1st Qu.:     0   1st Qu.:   0.00  
 Median :     0   Median :   0.00   Median :     0   Median :   0.00  
 Mean   :  3917   Mean   :  80.89   Mean   :  5109   Mean   :  88.43  
 3rd Qu.:     0   3rd Qu.:   0.00   3rd Qu.:     0   3rd Qu.:   0.00  
 Max.   :364215   Max.   :6621.44   Max.   :426268   Max.   :7003.69  
                                                                      
    BTUWOOD          TOTALBTU          TOTALDOL      
 Min.   :     0   Min.   :   1182   Min.   : -150.5  
 1st Qu.:     0   1st Qu.:  45565   1st Qu.: 1258.3  
 Median :     0   Median :  74180   Median : 1793.2  
 Mean   :  3596   Mean   :  83002   Mean   : 1990.2  
 3rd Qu.:     0   3rd Qu.: 108535   3rd Qu.: 2472.0  
 Max.   :500000   Max.   :1367548   Max.   :20043.4  
                                                     

Code examples

The End

Resources

Q & A