library(tidyverse)
library(survey)
library(srvyr)
library(srvyrexploR)
04 - Statistical Testing
Slides
Your Turn
Set-up
Load necessary packages
Load in data and preview it
glimpse(recs_2020)
Rows: 18,496
Columns: 100
$ DOEID <dbl> 100001, 100002, 100003, 100004, 100005, 100006, 10000…
$ ClimateRegion_BA <fct> Mixed-Dry, Mixed-Humid, Mixed-Dry, Mixed-Humid, Mixed…
$ Urbanicity <fct> Urban Area, Urban Area, Urban Area, Urban Area, Urban…
$ Region <fct> West, South, West, South, Northeast, South, South, So…
$ REGIONC <chr> "WEST", "SOUTH", "WEST", "SOUTH", "NORTHEAST", "SOUTH…
$ Division <fct> Mountain South, West South Central, Mountain South, S…
$ STATE_FIPS <chr> "35", "05", "35", "45", "34", "48", "40", "28", "11",…
$ state_postal <fct> NM, AR, NM, SC, NJ, TX, OK, MS, DC, AZ, CA, TX, LA, M…
$ state_name <fct> New Mexico, Arkansas, New Mexico, South Carolina, New…
$ HDD65 <dbl> 3844, 3766, 3819, 2614, 4219, 901, 3148, 1825, 4233, …
$ CDD65 <dbl> 1679, 1458, 1696, 1718, 1363, 3558, 2128, 2374, 1159,…
$ HDD30YR <dbl> 4451, 4429, 4500, 3229, 4896, 1150, 3564, 2660, 4404,…
$ CDD30YR <dbl> 1027, 1305, 1010, 1653, 1059, 3588, 2043, 2164, 1407,…
$ HousingUnitType <fct> Single-family detached, Apartment: 5 or more units, A…
$ YearMade <ord> 1970-1979, 1980-1989, 1960-1969, 1980-1989, 1960-1969…
$ TOTSQFT_EN <dbl> 2100, 590, 900, 2100, 800, 4520, 2100, 900, 750, 760,…
$ TOTHSQFT <dbl> 2100, 590, 900, 2100, 800, 3010, 1200, 900, 750, 760,…
$ TOTCSQFT <dbl> 2100, 590, 900, 2100, 800, 3010, 1200, 0, 500, 760, 1…
$ SpaceHeatingUsed <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,…
$ ACUsed <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE…
$ HeatingBehavior <fct> Set one temp and leave it, Turn on or off as needed, …
$ WinterTempDay <dbl> 70, 70, 69, 68, 68, 76, 74, 70, 68, 70, 72, 74, 74, 7…
$ WinterTempAway <dbl> 70, 65, 68, 68, 68, 76, 65, 70, 60, 70, 70, 74, 74, 7…
$ WinterTempNight <dbl> 68, 65, 67, 68, 68, 68, 74, 68, 62, 68, 72, 74, 74, 6…
$ ACBehavior <fct> Set one temp and leave it, Turn on or off as needed, …
$ SummerTempDay <dbl> 71, 68, 70, 72, 72, 69, 68, NA, 72, 74, 77, 77, 74, 6…
$ SummerTempAway <dbl> 71, 68, 68, 72, 72, 74, 70, NA, 76, 74, 77, 77, 74, 6…
$ SummerTempNight <dbl> 71, 68, 68, 72, 72, 68, 70, NA, 68, 72, 77, 77, 74, 6…
$ NWEIGHT <dbl> 3284.104, 9007.387, 5669.002, 5294.239, 9935.465, 724…
$ NWEIGHT1 <dbl> 3273.053, 9019.564, 5793.353, 5361.146, 10047.545, 73…
$ NWEIGHT2 <dbl> 3349.139, 9081.268, 5913.554, 5361.706, 10261.682, 74…
$ NWEIGHT3 <dbl> 3344.876, 9020.409, 5762.743, 5371.011, 10036.522, 73…
$ NWEIGHT4 <dbl> 3437.284, 9213.074, 5870.261, 5392.846, 9960.953, 742…
$ NWEIGHT5 <dbl> 3415.582, 9117.337, 5720.669, 5327.617, 10107.863, 73…
$ NWEIGHT6 <dbl> 3354.813, 9178.697, 5662.939, 5353.957, 10298.428, 74…
$ NWEIGHT7 <dbl> 3372.342, 9095.936, 5699.536, 5325.316, 10064.709, 73…
$ NWEIGHT8 <dbl> 3364.035, 8920.480, 5704.027, 5375.732, 10096.509, 73…
$ NWEIGHT9 <dbl> 3361.912, 9188.981, 5667.670, 5391.379, 10321.424, 73…
$ NWEIGHT10 <dbl> 3301.569, 9060.009, 5793.325, 5500.628, 9943.547, 731…
$ NWEIGHT11 <dbl> 3211.291, 9127.404, 5806.321, 5427.320, 10266.593, 73…
$ NWEIGHT12 <dbl> 3500.495, 9264.304, 5650.394, 5384.442, 10127.061, 73…
$ NWEIGHT13 <dbl> 3313.754, 9222.011, 5648.461, 5302.085, 10240.975, 72…
$ NWEIGHT14 <dbl> 3359.110, 9199.014, 5828.712, 5362.226, 9871.649, 740…
$ NWEIGHT15 <dbl> 3423.682, 9143.214, 5641.887, 5383.136, 10275.303, 74…
$ NWEIGHT16 <dbl> 3383.601, 9042.382, 5717.847, 5380.916, 9921.199, 738…
$ NWEIGHT17 <dbl> 3312.112, 9416.815, 5968.713, 5418.300, 10311.952, 73…
$ NWEIGHT18 <dbl> 3324.383, 9162.681, 5828.370, 5356.271, 10004.213, 74…
$ NWEIGHT19 <dbl> 3366.644, 9191.950, 5814.049, 5343.187, 10437.297, 75…
$ NWEIGHT20 <dbl> 3326.643, 9091.550, 5697.447, 5360.409, 10100.730, 73…
$ NWEIGHT21 <dbl> 3339.910, 0.000, 5686.769, 5336.323, 9981.635, 7427.5…
$ NWEIGHT22 <dbl> 3292.197, 9097.877, 5738.946, 5389.830, 10000.278, 73…
$ NWEIGHT23 <dbl> 3277.697, 9319.896, 5944.649, 5397.093, 10179.723, 71…
$ NWEIGHT24 <dbl> 3340.406, 9080.729, 5819.996, 5448.089, 9825.700, 746…
$ NWEIGHT25 <dbl> 3386.445, 9406.487, 5823.075, 5382.111, 10149.386, 72…
$ NWEIGHT26 <dbl> 3300.574, 9255.867, 5650.188, 5386.710, 0.000, 7309.1…
$ NWEIGHT27 <dbl> 3311.546, 9318.078, 5862.116, 5351.082, 10140.604, 72…
$ NWEIGHT28 <dbl> 3347.637, 9154.189, 5706.909, 5371.439, 9948.403, 750…
$ NWEIGHT29 <dbl> 3355.638, 9371.695, 5618.615, 5361.572, 10064.708, 73…
$ NWEIGHT30 <dbl> 3322.423, 9137.197, 5795.544, 5381.218, 10082.927, 73…
$ NWEIGHT31 <dbl> 3255.840, 9233.363, 5994.544, 5319.728, 10132.977, 73…
$ NWEIGHT32 <dbl> 3317.937, 9114.608, 0.000, 5338.558, 9978.370, 7302.5…
$ NWEIGHT33 <dbl> 3401.811, 9176.872, 5637.872, 0.000, 10213.075, 7326.…
$ NWEIGHT34 <dbl> 3363.592, 9191.207, 5619.040, 5379.523, 9964.337, 724…
$ NWEIGHT35 <dbl> 3303.528, 9100.344, 5652.289, 5363.277, 10070.847, 0.…
$ NWEIGHT36 <dbl> 3333.027, 9071.530, 5834.171, 5476.866, 9987.947, 735…
$ NWEIGHT37 <dbl> 3389.869, 9263.141, 5712.198, 5386.333, 10120.314, 73…
$ NWEIGHT38 <dbl> 3381.503, 9077.901, 5765.422, 5326.402, 10023.636, 73…
$ NWEIGHT39 <dbl> 3328.893, 9011.009, 5887.338, 5420.540, 10023.919, 73…
$ NWEIGHT40 <dbl> 3292.829, 9166.222, 5649.809, 5370.189, 10184.527, 73…
$ NWEIGHT41 <dbl> 3295.089, 9091.334, 5957.748, 5339.323, 10069.084, 73…
$ NWEIGHT42 <dbl> 3413.593, 9193.664, 5592.619, 5328.788, 9958.721, 743…
$ NWEIGHT43 <dbl> 3263.710, 9215.337, 6035.472, 5409.435, 10352.485, 73…
$ NWEIGHT44 <dbl> 3342.446, 9048.092, 5732.384, 5416.488, 10091.807, 74…
$ NWEIGHT45 <dbl> 3275.274, 9258.580, 5876.696, 5453.165, 10227.529, 74…
$ NWEIGHT46 <dbl> 3364.248, 9170.518, 5653.511, 5449.444, 10069.384, 73…
$ NWEIGHT47 <dbl> 3336.066, 9260.064, 5763.458, 5375.551, 9995.686, 732…
$ NWEIGHT48 <dbl> 3329.151, 9105.220, 5928.968, 5407.834, 10197.608, 73…
$ NWEIGHT49 <dbl> 3348.061, 9116.891, 5772.333, 5399.779, 10093.620, 74…
$ NWEIGHT50 <dbl> 3357.231, 9261.127, 5785.452, 5359.408, 10196.251, 73…
$ NWEIGHT51 <dbl> 3335.188, 8955.288, 5635.561, 5447.619, 10017.094, 73…
$ NWEIGHT52 <dbl> 3240.132, 9000.296, 5944.330, 5344.453, 9954.142, 749…
$ NWEIGHT53 <dbl> 3429.728, 9290.375, 5683.500, 5437.803, 10050.961, 74…
$ NWEIGHT54 <dbl> 3294.084, 9199.326, 5735.631, 5377.898, 10018.844, 72…
$ NWEIGHT55 <dbl> 3397.713, 8958.782, 5674.564, 5357.470, 10309.728, 75…
$ NWEIGHT56 <dbl> 3292.610, 9232.597, 5660.854, 5421.025, 10142.763, 73…
$ NWEIGHT57 <dbl> 0.000, 9140.427, 5917.193, 5365.230, 10176.828, 7383.…
$ NWEIGHT58 <dbl> 3369.768, 9306.997, 5571.015, 5402.057, 10043.143, 75…
$ NWEIGHT59 <dbl> 3358.163, 9061.782, 5887.092, 5402.772, 10247.911, 73…
$ NWEIGHT60 <dbl> 3404.031, 8957.915, 5837.846, 5350.860, 10110.301, 75…
$ BTUEL <dbl> 42723.28, 17889.29, 8146.63, 31646.53, 20027.42, 4896…
$ DOLLAREL <dbl> 1955.06, 713.27, 334.51, 1424.86, 1087.00, 1895.66, 1…
$ BTUNG <dbl> 101924.43, 10145.32, 22603.08, 55118.66, 39099.51, 36…
$ DOLLARNG <dbl> 701.8300, 261.7348, 188.1400, 636.9100, 376.0400, 439…
$ BTULP <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,…
$ DOLLARLP <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,…
$ BTUFO <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,…
$ DOLLARFO <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,…
$ BTUWOOD <dbl> 0, 0, 0, 0, 0, 3000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ TOTALBTU <dbl> 144647.71, 28034.61, 30749.71, 86765.19, 59126.93, 85…
$ TOTALDOL <dbl> 2656.8900, 975.0048, 522.6500, 2061.7700, 1463.0400, …
glimpse(anes_2020)
Rows: 7,453
Columns: 65
$ V200001 <dbl> 200015, 200022, 200039, 200046, 200053, 200060…
$ CaseID <dbl> 200015, 200022, 200039, 200046, 200053, 200060…
$ V200002 <hvn_lbll> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,…
$ InterviewMode <fct> Web, Web, Web, Web, Web, Web, Web, Web, Web, W…
$ V200010b <dbl> 1.0057375, 1.1634731, 0.7686811, 0.5210195, 0.…
$ Weight <dbl> 1.0057375, 1.1634731, 0.7686811, 0.5210195, 0.…
$ V200010c <dbl> 2, 2, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2…
$ VarUnit <fct> 2, 2, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2…
$ V200010d <dbl> 9, 26, 41, 29, 23, 37, 7, 37, 32, 41, 22, 7, 3…
$ Stratum <fct> 9, 26, 41, 29, 23, 37, 7, 37, 32, 41, 22, 7, 3…
$ V201006 <hvn_lbll> 2, 3, 2, 3, 2, 1, 2, 3, 2, 2, 2, 2, 2, 1,…
$ CampaignInterest <fct> Somewhat interested, Not much interested, Some…
$ V201023 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1…
$ EarlyVote2020 <fct> NA, NA, NA, NA, NA, NA, NA, NA, Yes, NA, NA, N…
$ V201024 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1…
$ V201025x <hvn_lbll> 3, 3, 3, 3, 3, 3, 3, 2, 4, 3, 3, 3, 2, 4,…
$ V201028 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1…
$ V201029 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1…
$ V201101 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 2, …
$ V201102 <hvn_lbll> 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, 1, 2,…
$ VotedPres2016 <fct> Yes, Yes, Yes, Yes, Yes, No, Yes, No, Yes, Yes…
$ V201103 <hvn_lbll> 2, 5, 1, 1, 2, -1, 5, -1, 1, 1, -1, 1, -1…
$ VotedPres2016_selection <fct> Trump, Other, Clinton, Clinton, Trump, NA, Oth…
$ V201228 <hvn_lbll> 2, 5, 3, 2, 3, 3, 2, 2, 3, 1, 1, 1, 2, 1,…
$ V201229 <hvn_lbll> 1, -1, -1, 2, -1, -1, 2, 2, -1, 2, 1, 2, …
$ V201230 <hvn_lbll> -1, 2, 3, -1, 2, 3, -1, -1, 2, -1, -1, -1…
$ V201231x <hvn_lbll> 7, 4, 3, 6, 4, 3, 6, 6, 4, 2, 1, 2, 7, 2,…
$ PartyID <fct> Strong republican, Independent, Independent-de…
$ V201233 <hvn_lbll> 5, 5, 4, 3, 5, 4, 4, 1, 3, 3, 2, 3, 4, 5,…
$ TrustGovernment <fct> Never, Never, Some of the time, About half the…
$ V201237 <hvn_lbll> 3, 4, 4, 2, 4, 2, 4, 1, 3, 2, 4, 3, 4, 3,…
$ TrustPeople <fct> About half the time, Some of the time, Some of…
$ V201507x <hvn_lbll> 46, 37, 40, 41, 72, 71, 37, 45, 70, 43, 3…
$ Age <dbl> 46, 37, 40, 41, 72, 71, 37, 45, 70, 43, 37, 55…
$ AgeGroup <fct> 40-49, 30-39, 40-49, 40-49, 70 or older, 70 or…
$ V201510 <hvn_lbll> 6, 3, 2, 4, 8, 3, 4, 2, 2, 4, 2, 2, 2, 7,…
$ Education <fct> Bachelor's, Post HS, High school, Post HS, Gra…
$ V201546 <hvn_lbll> 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2,…
$ V201547a <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201547b <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201547c <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201547d <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201547e <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201547z <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201549x <hvn_lbll> 3, 4, 1, 4, 5, 1, 1, 1, 1, 3, 3, 1, 1, 4,…
$ RaceEth <fct> "Hispanic", "Asian, NH/PI", "White", "Asian, N…
$ V201600 <hvn_lbll> 1, 2, 2, 1, 1, 2, 2, 2, 2, 1, 2, 1, 2, 1,…
$ Gender <fct> Male, Female, Female, Male, Male, Female, Fema…
$ V201607 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201610 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201611 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201613 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201615 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201616 <hvn_lbll> -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -…
$ V201617x <hvn_lbll> 21, 13, 17, 7, 22, 3, 4, 3, 10, 11, 9, 18…
$ Income <fct> "$175,000-249,999", "$70,000-74,999", "$100,00…
$ Income7 <fct> $125k or more, $60k to < 80k, $100k to < 125k,…
$ V202051 <hvn_lbll> -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1…
$ V202066 <hvn_lbll> 1, 4, 4, 4, 4, 4, 4, 1, -1, 4, 4, 4, 4, -…
$ V202072 <hvn_lbll> -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1,…
$ VotedPres2020 <fct> NA, Yes, Yes, Yes, Yes, Yes, Yes, NA, Yes, Yes…
$ V202073 <hvn_lbll> -1, 3, 1, 1, 2, 1, 2, -1, -1, 1, 1, 1, 2,…
$ V202109x <hvn_lbll> 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,…
$ V202110x <hvn_lbll> -1, 3, 1, 1, 2, 1, 2, -1, 1, 1, 1, 1, 2, …
$ VotedPres2020_selection <fct> NA, Other, Biden, Biden, Trump, Biden, Trump, …
Find codebooks here:
Create design objects for usage
<- anes_2020 %>%
anes_des mutate(Weight = V200010b / sum(V200010b) * 231034125) %>%
as_survey_design(
weights = Weight,
strata = V200010d,
ids = V200010c,
nest = TRUE
)
<- recs_2020 %>%
recs_des as_survey_rep(
weights = NWEIGHT,
repweights = NWEIGHT1:NWEIGHT60,
type = "JK1",
scale = 59 / 60,
mse = TRUE
)
Exercises - Part 1
- For households that use thermostats, they are asked what temperature they set their home during the daytime in the winter (
WinterTempDay
) and in the summer (SummerTempDay
). Test whether daytime winter and daytime summer temperatures of homes are set the same.
# Hint - you'll need the recs_des object
- In 2015, the average household spent $1,856 on energy expenditure1. Accounting for inflation, this would be $2,036 in 2020. Test whether energy costs (
TOTALDOL
) have increased in 2020 from 2015, accounting for inflation.
# Hint - you'll need the recs_des object
- Advanced bonus exercise Look through the RECS dataset and develop your own hypothesis about a mean or difference of means and test it!
Exercises - Part 2
- Is there a relationship between party identification (
PartyID
) and whether people voted early (EarlyVote2020
)?
# Hint - you'll need the anes_des object
- Is there a relationship between party identification (
PartyID
) and trust in the government (TrustGovernment
)? Use Wald as thestatistic
option.
# Hint - you'll need the anes_des object
- Is there a difference in the distribution of gender (
Gender
) across early voting status (EarlyVote2020
)?
# Hint - you'll need the anes_des object
- Advanced bonus exercise Look through the ANES dataset and develop your own hypothesis and test it!
Solutions
See the solutions
Exercises - Part 1
- For households that use thermostats, they are asked what temperature they set their home during the daytime in the winter (
WinterTempDay
) and in the summer (SummerTempDay
). Test whether daytime winter and daytime summer temperatures of homes are set the same.
Show code
%>%
recs_des filter(!is.na(SummerTempDay), !is.na(WinterTempDay)) %>%
svyttest(WinterTempDay - SummerTempDay ~ 0, design = .)
Design-based one-sample t-test
data: WinterTempDay - SummerTempDay ~ 0
t = -43.106, df = 58, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-2.031155 -1.850883
sample estimates:
mean
-1.941019
- In 2015, the average household spent $1,856 on energy expenditure2. Accounting for inflation, this would be $2,036 in 2020. Test whether energy costs (
TOTALDOL
) have increased in 2020 from 2015, accounting for inflation.
Show code
%>%
recs_des svyttest(I(TOTALDOL - 2036) ~ 0, design = .)
Design-based one-sample t-test
data: I(TOTALDOL - 2036) ~ 0
t = -23.079, df = 58, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-164.7926 -138.4885
sample estimates:
mean
-151.6406
Exercises - Part 2
- Is there a relationship between party identification (
PartyID
) and whether people voted early (EarlyVote2020
)?
Show code
%>%
anes_des filter(!is.na(PartyID), !is.na(EarlyVote2020)) %>%
group_by(PartyID, EarlyVote2020) %>%
summarize(
p = survey_mean()
)
# A tibble: 14 × 4
# Groups: PartyID [7]
PartyID EarlyVote2020 p p_se
<fct> <fct> <dbl> <dbl>
1 Strong democrat Yes 0.777 0.0519
2 Strong democrat No 0.223 0.0519
3 Not very strong democrat Yes 0.672 0.134
4 Not very strong democrat No 0.328 0.134
5 Independent-democrat Yes 0.665 0.0608
6 Independent-democrat No 0.335 0.0608
7 Independent Yes 0.695 0.0760
8 Independent No 0.305 0.0760
9 Independent-republican Yes 0.776 0.0936
10 Independent-republican No 0.224 0.0936
11 Not very strong republican Yes 0.641 0.112
12 Not very strong republican No 0.359 0.112
13 Strong republican Yes 0.703 0.0678
14 Strong republican No 0.297 0.0678
Show code
%>%
anes_des filter(!is.na(PartyID), !is.na(EarlyVote2020)) %>%
svychisq(~ EarlyVote2020 + PartyID, design = .)
Pearson's X^2: Rao & Scott adjustment
data: NextMethod()
F = 0.46943, ndf = 4.9476, ddf = 232.5385, p-value = 0.797
- Is there a relationship between party identification (
PartyID
) and trust in the government (TrustGovernment
)? Use Wald as thestatistic
option.
Show code
%>%
anes_des filter(!is.na(PartyID), !is.na(TrustGovernment)) %>%
group_by(PartyID, TrustGovernment) %>%
summarize(
p = survey_mean()
)
# A tibble: 35 × 4
# Groups: PartyID [7]
PartyID TrustGovernment p p_se
<fct> <fct> <dbl> <dbl>
1 Strong democrat Always 0.0144 0.00452
2 Strong democrat Most of the time 0.124 0.00977
3 Strong democrat About half the time 0.353 0.0171
4 Strong democrat Some of the time 0.420 0.0175
5 Strong democrat Never 0.0888 0.0126
6 Not very strong democrat Always 0.0207 0.00874
7 Not very strong democrat Most of the time 0.101 0.0154
8 Not very strong democrat About half the time 0.296 0.0248
9 Not very strong democrat Some of the time 0.466 0.0228
10 Not very strong democrat Never 0.116 0.0182
# ℹ 25 more rows
Show code
%>%
anes_des filter(!is.na(PartyID), !is.na(TrustGovernment)) %>%
svychisq(~ TrustGovernment + PartyID, design = ., statistic = "Wald")
Design-based Wald test of association
data: NextMethod()
F = 15.134, ndf = 24, ddf = 51, p-value = 1.142e-15
- Is there a difference in the distribution of gender (
Gender
) across early voting status (EarlyVote2020
)?
Show code
# Hint - you'll need the anes_des object
%>%
anes_des filter(!is.na(Gender), !is.na(EarlyVote2020)) %>%
group_by(Gender, EarlyVote2020) %>%
summarize(
p = survey_mean()
)
# A tibble: 4 × 4
# Groups: Gender [2]
Gender EarlyVote2020 p p_se
<fct> <fct> <dbl> <dbl>
1 Male Yes 0.781 0.0345
2 Male No 0.219 0.0345
3 Female Yes 0.679 0.0331
4 Female No 0.321 0.0331
Show code
%>%
anes_des filter(!is.na(Gender), !is.na(EarlyVote2020)) %>%
svychisq(~ Gender + EarlyVote2020, design = ., statistic = "Wald")
Design-based Wald test of association
data: NextMethod()
F = 4.6322, ndf = 1, ddf = 47, p-value = 0.03655