Loading, setting up

d_to_model <- params$d_to_model

Descriptives

d_to_model %>% 
  select(n_tweets_by_user_in_state,
         voices, 
         national_school_lunch_program_fy_2016_fns_usda_gov,
         pct_students_frpl, 
         state_spending_on_public_elementary_secondary_spending_fy_2016_census_in_thousands,
         state_spending_per_child,
         urban_percentage_of_state_population_in_2015,
         three_year_average_of_state_poverty_rates_2015_2017,
         teacher_salaries_nea_2016,
         c_ideology,
         g_ideology,
         region_by_census,
         enrollment_in_public_ele_sec_education_digest_of_ed_stats_fall_2015_projected,
         staff_teachers,
         coordinators_teachers,
         time_of_account
  ) %>% 
  skimr::skim()
Data summary
Name Piped data
Number of rows 616208
Number of columns 16
_______________________
Column type frequency:
numeric 16
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
n_tweets_by_user_in_state 0 1 308.63 520.31 1.00 13.00 79.00 344.00 3230.00 ▇▁▁▁▁
voices 0 1 4997.19 3692.13 104.00 1908.00 5009.00 7958.00 12799.00 ▇▆▃▃▃
national_school_lunch_program_fy_2016_fns_usda_gov 0 1 1034926.29 1075027.49 50876.06 342539.73 598665.35 1013673.02 3377166.13 ▇▃▁▁▂
pct_students_frpl 318 1 0.51 0.08 0.28 0.45 0.49 0.59 0.75 ▂▅▅▇▁
state_spending_on_public_elementary_secondary_spending_fy_2016_census_in_thousands 0 1 21459518.17 22995511.74 1473360.00 6129735.00 11314646.00 27945116.00 82153002.00 ▇▂▁▂▁
state_spending_per_child 0 1 12.28 3.65 7.19 9.65 11.54 13.19 25.07 ▅▇▂▁▁
urban_percentage_of_state_population_in_2015 441 1 75.99 12.11 38.70 66.20 74.60 84.70 95.00 ▁▂▆▆▇
three_year_average_of_state_poverty_rates_2015_2017 441 1 12.73 1.78 6.70 11.70 13.40 13.80 20.00 ▁▂▇▁▁
teacher_salaries_nea_2016 441 1 54110.48 9500.70 42025.00 47755.00 51386.00 58140.00 79152.00 ▇▆▂▁▂
c_ideology 0 1 46.36 14.94 23.98 38.24 44.41 58.04 97.00 ▅▇▅▁▁
g_ideology 0 1 33.04 15.45 18.11 21.99 24.80 45.08 69.95 ▇▁▁▁▂
region_by_census 0 1 2.58 0.90 1.00 2.00 3.00 3.00 4.00 ▂▆▁▇▃
enrollment_in_public_ele_sec_education_digest_of_ed_stats_fall_2015_projected 0 1 1727295.50 1804836.38 95400.00 646200.00 917000.00 1715000.00 6294600.00 ▇▃▁▁▂
staff_teachers 0 1 2.06 0.28 1.51 1.90 2.02 2.06 3.17 ▁▇▁▁▁
coordinators_teachers 0 1 0.02 0.02 0.00 0.01 0.02 0.03 0.12 ▇▂▁▁▁
time_of_account 0 1 4.04 2.31 -0.49 2.19 3.95 6.32 9.46 ▅▇▇▇▂

Correlations

d_to_model %>% 
  select(n_tweets_by_user_in_state,
         voices, 
         national_school_lunch_program_fy_2016_fns_usda_gov,
         pct_students_frpl, 
         state_spending_on_public_elementary_secondary_spending_fy_2016_census_in_thousands,
         state_spending_per_child,
         urban_percentage_of_state_population_in_2015,
         three_year_average_of_state_poverty_rates_2015_2017,
         teacher_salaries_nea_2016,
         c_ideology,
         g_ideology,
         region_by_census,
         enrollment_in_public_ele_sec_education_digest_of_ed_stats_fall_2015_projected,
         staff_teachers,
         coordinators_teachers,
         time_of_account
  ) %>% 
  corrr::correlate() %>% 
  arrange(desc(n_tweets_by_user_in_state)) %>% 
  corrr::shave() %>% 
  corrr::fashion() %>% 
  knitr::kable()
## 
## Correlation method: 'pearson'
## Missing treated using: 'pairwise.complete.obs'
rowname n_tweets_by_user_in_state voices national_school_lunch_program_fy_2016_fns_usda_gov pct_students_frpl state_spending_on_public_elementary_secondary_spending_fy_2016_census_in_thousands state_spending_per_child urban_percentage_of_state_population_in_2015 three_year_average_of_state_poverty_rates_2015_2017 teacher_salaries_nea_2016 c_ideology g_ideology region_by_census enrollment_in_public_ele_sec_education_digest_of_ed_stats_fall_2015_projected staff_teachers coordinators_teachers time_of_account
time_of_account .12
region_by_census .03 .15
three_year_average_of_state_poverty_rates_2015_2017 .02 .41 .32
voices .02 .67 .60
pct_students_frpl .00 .60 .43 .29
staff_teachers -.02 -.04 .06 -.18 .07 .05
coordinators_teachers -.06 -.31 .10 -.30 .20 .09 .31
state_spending_per_child -.10 -.29 .02 -.49 .29 .28 -.32
urban_percentage_of_state_population_in_2015 -.10 .13 .50 -.09 .59 .28 -.28 .58
national_school_lunch_program_fy_2016_fns_usda_gov -.12 .67 .43 .93 .02 .50 .32 .31 .21
enrollment_in_public_ele_sec_education_digest_of_ed_stats_fall_2015_projected -.13 .62 .99 .40 .95 .05 .53 .29 .39 .26 .14
state_spending_on_public_elementary_secondary_spending_fy_2016_census_in_thousands -.13 .50 .93 .29 .29 .59 .21 .58 .41 .33 .10
teacher_salaries_nea_2016 -.13 -.17 .31 -.29 .58 .72 .58 -.26 .80 .74 -.28 .39
g_ideology -.13 -.35 .06 -.23 .33 .62 .35 -.33 .74 .71 -.23 .14 -.11
c_ideology -.18 -.28 .21 -.34 .41 .63 .46 -.24 .80 .71 -.44 .26 -.00 .14
n_tweets_by_user_in_state .02 -.12 .00 -.13 -.10 -.10 .02 -.13 -.18 -.13 .03 -.13 -.02 -.06 .12
d_user_level <- d_to_model %>% 
  distinct(screen_name, .keep_all = TRUE)

Analysis - at the individual level

d_user_level$pct_students_frpl_std <- as.vector(scale(d_user_level$pct_students_frpl * 100))
d_user_level$voices_std <- as.vector(scale(d_user_level$voices))

d_user_level$full_time_equivalent_fte_teachers_state_2015_16_std <- as.vector(scale(d_user_level$full_time_equivalent_fte_teachers_state_2015_16))

d_user_level$c_ideology_std <- as.vector(scale(d_user_level$c_ideology))

d_user_level$g_ideology_std <- as.vector(scale(d_user_level$g_ideology))

d_user_level$teacher_student_ratio_std <- as.vector(scale(d_user_level$teacher_student_ratio))

d_user_level$state_spending_per_child_std <- as.vector(scale(d_user_level$state_spending_per_child))

d_user_level$time_of_account_std <- as.vector(scale(d_user_level$time_of_account))
mnull <- glmer(n_tweets_by_user_in_state ~ 1 + 
                 
                 #scale(time_of_account)+
                 
                 #scale(voices) + 
                 
                 #scale(c_ideology) + 
                 #scale(g_ideology) + 
                 
                 #three_year_average_of_state_poverty_rates_2015_2017 +
                 #fct_students_frpl +
                 
               #state_spending_per_child +
               #total_students_state_2015_16 +
               
               #full_time_equivalent_fte_teachers_state_2015_16 +
               #scale(urban_percentage_of_state_population_in_2015) + 
               
               (1|state), 
               data = d_user_level,
               family = "poisson")

performance::icc(mnull)
## # Intraclass Correlation Coefficient
## 
##      Adjusted ICC: 0.638
##   Conditional ICC: 0.638
sjPlot::tab_model(mnull, show.std = "std")
## No variables could be standardized.
  n tweets by user in state
Predictors Incidence Rate Ratios std. Beta CI standardized CI p
(Intercept) 6.05 1.80 5.37 – 6.82 1.68 – 1.92 <0.001
Random Effects
σ2 0.15
τ00 state 0.27
ICC 0.64
N state 45
Observations 57690
Marginal R2 / Conditional R2 0.000 / 0.638
m1 <- glmer(n_tweets_by_user_in_state ~ 1 + 
              
                       time_of_account_std +
                       voices_std + 
                       full_time_equivalent_fte_teachers_state_2015_16_std +
                       
                       c_ideology_std + 
                       g_ideology_std + 
                       
                       pct_students_frpl_std + 
                       teacher_student_ratio_std + 
                       state_spending_per_child_std +
              
              (1|state), 
            data = d_user_level,
            family = "poisson")

performance::icc(m1)
## # Intraclass Correlation Coefficient
## 
##      Adjusted ICC: 0.519
##   Conditional ICC: 0.342
sjPlot::tab_model(m1, show.std = "std")
  n tweets by user in state
Predictors Incidence Rate Ratios std. Beta CI standardized CI p std. p
(Intercept) 6.43 1.86 5.23 – 7.90 1.65 – 2.07 <0.001 <0.001
time_of_account_std 1.21 0.19 1.21 – 1.22 0.19 – 0.20 <0.001 <0.001
voices_std 1.21 0.19 0.93 – 1.58 -0.08 – 0.47 0.148 0.165
full_time_equivalent_fte_teachers_state_2015_16_std 0.72 -0.33 0.52 – 0.98 -0.65 – -0.02 0.035 0.038
c_ideology_std 0.83 -0.18 0.70 – 0.99 -0.36 – -0.01 0.041 0.043
g_ideology_std 0.94 -0.06 0.77 – 1.16 -0.27 – 0.15 0.570 0.576
pct_students_frpl_std 0.99 -0.01 0.87 – 1.13 -0.14 – 0.13 0.934 0.935
teacher_student_ratio_std 1.11 0.11 0.94 – 1.33 -0.07 – 0.28 0.222 0.227
state_spending_per_child_std 1.05 0.05 0.86 – 1.28 -0.16 – 0.25 0.651 0.658
Random Effects
σ2 0.15
τ00 state 0.17
ICC 0.52
N state 44
Observations 57642
Marginal R2 / Conditional R2 0.341 / 0.683
performance::check_model(m1)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 57619 rows containing missing values (geom_text_repel).
## `geom_smooth()` using formula 'y ~ x'

margins::margins(m1)
## Average marginal effects
##  time_of_account_std voices_std
##                1.395      1.383
##  full_time_equivalent_fte_teachers_state_2015_16_std c_ideology_std
##                                               -2.399         -1.314
##  g_ideology_std pct_students_frpl_std teacher_student_ratio_std
##         -0.4227              -0.03996                     0.778
##  state_spending_per_child_std
##                        0.3313

Without voices

m2 <- glmer(n_tweets_by_user_in_state ~ 1 + 
              
                       time_of_account_std +
                       full_time_equivalent_fte_teachers_state_2015_16_std +
                       
                       c_ideology_std + 
                       g_ideology_std + 
                       
                       pct_students_frpl_std + 
                       teacher_student_ratio_std + 
                       state_spending_per_child_std +
              
              (1|state), 
            data = d_user_level,
            family = "poisson")

performance::icc(m2)
## # Intraclass Correlation Coefficient
## 
##      Adjusted ICC: 0.529
##   Conditional ICC: 0.374
sjPlot::tab_model(m2, show.std = "std")
  n tweets by user in state
Predictors Incidence Rate Ratios std. Beta CI standardized CI p std. p
(Intercept) 5.89 1.77 4.95 – 7.02 1.60 – 1.95 <0.001 <0.001
time_of_account_std 1.21 0.19 1.21 – 1.22 0.19 – 0.20 <0.001 <0.001
full_time_equivalent_fte_teachers_state_2015_16_std 0.83 -0.18 0.65 – 1.06 -0.43 – 0.06 0.141 0.142
c_ideology_std 0.82 -0.19 0.69 – 0.99 -0.37 – -0.02 0.035 0.034
g_ideology_std 0.93 -0.07 0.76 – 1.15 -0.28 – 0.14 0.520 0.516
pct_students_frpl_std 0.98 -0.02 0.86 – 1.13 -0.15 – 0.12 0.818 0.819
teacher_student_ratio_std 1.10 0.10 0.92 – 1.32 -0.08 – 0.27 0.292 0.286
state_spending_per_child_std 1.03 0.03 0.83 – 1.26 -0.18 – 0.23 0.812 0.811
Random Effects
σ2 0.15
τ00 state 0.17
ICC 0.53
N state 44
Observations 57642
Marginal R2 / Conditional R2 0.293 / 0.667
performance::check_model(m2)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 57616 rows containing missing values (geom_text_repel).
## `geom_smooth()` using formula 'y ~ x'

margins::margins(m2)
## Average marginal effects
##  time_of_account_std full_time_equivalent_fte_teachers_state_2015_16_std
##                1.395                                              -1.316
##  c_ideology_std g_ideology_std pct_students_frpl_std teacher_student_ratio_std
##          -1.395        -0.4944                -0.114                    0.6903
##  state_spending_per_child_std
##                        0.1794