Answer To: Recently, many scholars have been interested in quantifying the effect of the national news media on...
Mohd answered on Apr 22 2021
FOXNEWS
FOXNEWS
-
4/22/2021
knitr::opts_chunk$set(echo = TRUE,cache = TRUE,warning = FALSE,message = FALSE,dpi = 180,fig.width = 8,fig.height = 5)
library(readr)
library(magrittr)
library(dplyr)
library(ggplot2)
foxnews <- read_csv("foxnews.csv")
na_vec<-which(!complete.cases(foxnews))
foxnews_C<-foxnews[-na_vec,]
foxnews_<-foxnews_C%>%
mutate(foxnews2000=ifelse(subrf2000>0,1,0))
foxnews0<-foxnews_%>%
filter(foxnews2000==0)
foxnews1<-foxnews_%>%
filter(foxnews2000==1)
qqnorm(foxnews0$male1990,main="male1990_QQPLOT")
qqline(foxnews0$male1990,col="red")
qqnorm(foxnews1$male1990,main="male1990_QQPLOT")
qqline(foxnews1$male1990,col="red")
qqnorm(foxnews0$hisp1990,main="hisp1990_0_QQPLOT")
qqline(foxnews0$hisp1990,col="red")
qqnorm(foxnews1$hisp1990,main="hisp1990_1_QQPLOT")
qqline(foxnews1$hisp1990,col="red")
qqnorm(foxnews0$logincome1990,main="logincome1990_0")
qqline(foxnews0$logincome1990,col="red")
qqnorm(foxnews1$logincome1990,main="logincome1990_1")
qqline(foxnews1$logincome1990,col="red")
qqnorm(foxnews0$black1990,main="black1990_0")
qqline(foxnews0$black1990,col="red")
qqnorm(foxnews1$black1990,main="black1990_1")
qqline(foxnews1$black1990,col="red")
qqnorm(foxnews0$college1990,main="college1990_0")
qqline(foxnews0$college1990,col="red")
qqnorm(foxnews1$college1990,main="college1990_1")
qqline(foxnews1$black1990,col="red")
summary(foxnews_)
## state town college1990 male1990
## Length:4269 Length:4269 Min. :0.00000 Min. :0.2845
## Class :character Class :character 1st Qu.:0.09033 1st Qu.:0.4785
## Mode :character Mode :character Median :0.13282 Median :0.4930
## Mean :0.16234 Mean :0.4932
## 3rd Qu.:0.20188 3rd Qu.:0.5056
## Max. :0.74692 Max. :0.8069
## black1990 hisp1990 income1990 logincome1990
## Min. :0.000000 Min. :0.000000 Min. : 0.420 Min. :-0.8676
## 1st Qu.:0.000000 1st Qu.:0.001495 1st Qu.: 1.856 1st Qu.: 0.6186
## Median :0.001348 Median :0.005960 Median : 2.523 Median : 0.9254
## Mean :0.022667 Mean :0.011549 Mean : 2.726 Mean : 0.9089
## 3rd Qu.:0.008178 3rd Qu.:0.013109 3rd Qu.: 3.350 3rd Qu.: 1.2089
## Max. :0.983871 Max. :0.361193 Max. :15.000 Max. : 2.7081
## subrf2000 gopvoteshare1992 gopvoteshare1996 gopvoteshare2000
## Min. :0.0000 Min. :0.02358 Min. :0.00813 Min. :0.02964
## 1st Qu.:0.0000 1st Qu.:0.42043 1st Qu.:0.37693 1st Qu.:0.45953
## Median :0.0000 Median :0.48783 Median :0.44362 Median :0.52933
## Mean :0.0544 Mean :0.48341 Mean :0.44502 Mean :0.52594
## 3rd Qu.:0.0000 3rd Qu.:0.55215 3rd Qu.:0.51222 3rd Qu.:0.59589
## Max. :1.0000 Max. :0.90598 Max. :0.90578 Max. :0.92505
## foxnews2000
## Min. :0.0000
## 1st Qu.:0.0000
## Median :0.0000
## Mean :0.1598
## 3rd Qu.:0.0000
## Max. :1.0000
Q2
set.seed(123)
kfox<-foxnews_%>%
select(college1990,male1990,logincome1990,hisp1990,black1990)
#step_normalize(all_numeric())
km.res <- kmeans(kfox, 2, nstart = 20)
#km.res$cluster
km.res$centers
## college1990 male1990 logincome1990 hisp1990 black1990
## 1 0.1140053 0.4874847 0.5403854 0.01076533 0.03361793
## 2 0.2058813 0.4983593 1.2407606 0.01225545 0.01280381
km.res$tot.withinss
## [1] 365.5437
Q3
foxnews_3<-foxnews_%>%
mutate(differ_repu=round(gopvoteshare2000-gopvoteshare1996,3))%>%
select(differ_repu,subrf2000)
cor(foxnews_3,method = "pearson")
## differ_repu subrf2000
## differ_repu 1.0000000 -0.0364548
## subrf2000 -0.0364548 1.0000000
Q4
mod<-lm(gopvoteshare1992~foxnews2000,data=foxnews_)
mod1<-lm(gopvoteshare1996~foxnews2000,data=foxnews_)
mod2<-lm(gopvoteshare2000~foxnews2000,data=foxnews_)
summary(mod)
##
## Call:
## lm(formula = gopvoteshare1992 ~ foxnews2000, data = foxnews_)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.45616 -0.06357 0.00345 0.06842 0.42623
##
## Coefficients:
## ...