Title: Homework 4
Author: Brandon Flores
Date: Sept. 22nd, 2021
When observing the data between the two variables of feelings toward Biden (X) and Trump (Y) in terms of a "Feeling Thermometer" on a scale of 0 (feeling extreamly cold towards) or 100 (feeling extreamly hot towards). This can also be interepted as degree of approval measured between these two candidates.

The relationship between feelings toward Biden (X) and feelings toward Trump (Y) is statistically signficant at the .001 level with a slope of -.816 being that as feelings toward Biden increase, feelings toward Trump decreases. This is a strongly negative relationship.

With a slope of -.816 expresses the fast decline of the correlation of the two variables giving an example of the polarization of the political enviroment in 2020.  

This is further shown with the y-intercept at about 87; expressing that when feelings toward Biden are at 0, feelings toward Trump are at about 87. Again the political polarization is being expressed. 

With the degree of effect that X (feelings toward Biden) has on the Y (feelings toward Trump) is at about 66%. This is reflected by the R-Square of .6659. Again meaning that 66% of the variance of the Y variable is explained by the linear relationship of the X variable. Not only does this again bring about the political polarization of 2020 but shows by this large r-square that much of that polarization is explained simply by the political differences in viewpoint. 
library(haven)
anes2020<-read_dta("C:\\Users\\BTP\\Downloads\\anes2020.dta")
anes2020$V202143[anes2020$V202143 <0] <- NA
anes2020$V202144[anes2020$V202144 <0] <- NA
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
ggplot(anes2020) + geom_point(mapping = aes(x=V202143, y=V202144)) +
ggtitle(label="The Political Thermometer")+
xlab(label="Feelings Toward Biden")+ 
ylab(label = "Feelings Toward Trump")
## Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.
## Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.
## Warning: Removed 957 rows containing missing values (geom_point).

scatter.smooth(anes2020$V202143,anes2020$V202144) 

cor(anes2020$V202143, anes2020$V202144, use = "complete.obs")
## [1] -0.816032
lmTrump = lm(V202144~V202143, data = anes2020)
summary(lmTrump)
## 
## Call:
## lm(formula = V202144 ~ V202143, data = anes2020)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -86.915  -9.258   4.446  13.085 104.446 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 86.915259   0.486131   178.8   <2e-16 ***
## V202143     -0.913617   0.007563  -120.8   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 23.16 on 7321 degrees of freedom
##   (957 observations deleted due to missingness)
## Multiple R-squared:  0.6659, Adjusted R-squared:  0.6659 
## F-statistic: 1.459e+04 on 1 and 7321 DF,  p-value: < 2.2e-16