library(anesr)

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(coefplot)
## Warning: package 'coefplot' was built under R version 4.0.3
data("timeseries_2016")

anes16 <- timeseries_2016


clean <- function(x){ifelse (x < 0, NA, x)}

anes_clean <- anes16 %>%
    mutate(across (everything(), clean))

anes_clean <- anes_clean %>%
  mutate(V161158x = V161158x - 1 )


mod1 <- lm(V161087 ~ V161158x, data = anes_clean)

summary(mod1)
## 
## Call:
## lm(formula = V161087 ~ V161158x, data = anes_clean)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -70.64 -16.91  -4.17  14.36  93.83 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   6.1700     0.6715   9.189   <2e-16 ***
## V161158x     10.7454     0.1874  57.337   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 26.19 on 4209 degrees of freedom
##   (59 observations deleted due to missingness)
## Multiple R-squared:  0.4385, Adjusted R-squared:  0.4384 
## F-statistic:  3288 on 1 and 4209 DF,  p-value: < 2.2e-16
anes_clean <- anes_clean %>%
  
  mutate(gen = case_when (V161342 == 2 ~ 0 ,
                          V161342 == 1 ~ 1 ,
                          V161342 == 3 ~ 0
         ))
mod1 <- lm(V161087 ~ gen, data =  anes_clean)

summary(mod1)
## 
## Call:
## lm(formula = V161087 ~ gen, data = anes_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -40.743 -33.751  -3.751  29.257  66.249 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  33.7509     0.7378  45.744  < 2e-16 ***
## gen           6.9920     1.0763   6.496  9.2e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 34.76 on 4186 degrees of freedom
##   (82 observations deleted due to missingness)
## Multiple R-squared:  0.009981,   Adjusted R-squared:  0.009744 
## F-statistic:  42.2 on 1 and 4186 DF,  p-value: 9.198e-11
anes_clean <- anes_clean %>%
  
  mutate(V161081 = V161081 - 1)

mod2 <- lm(V161087 ~ V161081, data = anes_clean)

summary(mod2)
## 
## Call:
## lm(formula = V161087 ~ V161081, data = anes_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -44.922 -29.922  -4.922  25.078  85.631 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  14.3690     0.9846   14.59   <2e-16 ***
## V161081      30.5535     1.1418   26.76   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 32.3 on 4194 degrees of freedom
##   (74 observations deleted due to missingness)
## Multiple R-squared:  0.1458, Adjusted R-squared:  0.1456 
## F-statistic:   716 on 1 and 4194 DF,  p-value: < 2.2e-16
anes_clean <- anes_clean %>%
  
  mutate(V161361x = V161361x - 1)
  
  mod3 <- lm(V161087 ~ V161361x , data = anes_clean)
  
  summary(mod3)
## 
## Call:
## lm(formula = V161087 ~ V161361x, data = anes_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.440 -36.696  -6.729  32.884  63.433 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 37.43974    1.12754  33.205   <2e-16 ***
## V161361x    -0.03233    0.06815  -0.474    0.635    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 34.87 on 4028 degrees of freedom
##   (240 observations deleted due to missingness)
## Multiple R-squared:  5.585e-05,  Adjusted R-squared:  -0.0001924 
## F-statistic: 0.225 on 1 and 4028 DF,  p-value: 0.6353
mod1 <- lm(V161087 ~ V161158x, data = anes_clean)

mod2 <- lm(V161087 ~ V161081, data = anes_clean)

mod3 <- lm(V161087 ~ V161361x , data = anes_clean)

mod4 <- lm(V161087 ~ V161158x + gen + V161081 + V161361x , data = anes_clean) 

summary(mod4)
## 
## Call:
## lm(formula = V161087 ~ V161158x + gen + V161081 + V161361x, data = anes_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -75.451 -16.112  -0.608  16.754  92.790 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.87354    1.15632   3.350 0.000816 ***
## V161158x     9.93979    0.20945  47.456  < 2e-16 ***
## gen          3.33612    0.82445   4.046 5.30e-05 ***
## V161081     10.09316    1.02682   9.830  < 2e-16 ***
## V161361x    -0.29819    0.05134  -5.808 6.81e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.65 on 3971 degrees of freedom
##   (294 observations deleted due to missingness)
## Multiple R-squared:  0.461,  Adjusted R-squared:  0.4605 
## F-statistic: 849.1 on 4 and 3971 DF,  p-value: < 2.2e-16
coefplot::coefplot(mod4)

Written questions

1 1 The coefficent for party ID 2 Value is statistically signifigant using the 5% threshhold 3 Linea regression is appropriate

2 1 Men as opposed to those who donโ€™t identify as male is 6,992 point increase in support for Donal Trump on a 100 point scale

3 1 Those who think the country is on the wrong track tend to be 40 points higher on the feelings thermometer compared to those who think the country is on the right track

4 1 Income does not have a statistically signifigant effect when analyzing the estimated slope. Every point on the income scale leads to a .03233 points lower on the feelings scale for Donald Trump

5 1 2 Gender is not signifigant at the 5% threshhold