Analysis on Twitter data

Loading the libraries and Twitter data

rm(list=ls()) 
#setwd("D:/emre/SkyDrive/makale/Twitter/Incivility/Revisit/")
library("foreign")
library("sjmisc")
library("sjPlot")
library("lessR")
## 
## lessR 3.5.0      feedback: gerbing@pdx.edu      web: lessRstats.com
## -------------------------------------------------------------------
## 1. Read a text, Excel, SPSS, SAS or R data file from your computer
##    into the mydata data table, enter:  mydata <- Read()  
## 2. For a list of help topics and functions, enter:  Help()
## 3. Use theme function for global settings, Ex: theme(colors="gray")
## 
## Attaching package: 'lessR'
## The following object is masked from 'package:sjmisc':
## 
##     rec
library("pander")
twitter_data <- read.dta("D:/emre/SkyDrive/makale/Twitter/Incivility/Revisit/TwitterKasimRS12N.dta")

Cleaning data and formating the variables

Contains.Link <- twitter_data$Link
Contains.Retweet <- twitter_data$Retweet
Candidate.Age<- twitter_data$Aday_yas
Candidate.Party <- twitter_data$c_party
Previously.Candidate <- twitter_data$c_prevcandidate
Contains.Link[Contains.Link > 1] <- 1
twitter_data$Retweet[twitter_data$Retweet > 1] <- 1
Candidate.Age[Candidate.Age < 25] <- NA

Incivility <- ordered(twitter_data$Incivility, levels=c(0,1), labels=c("No", "Yes"))

Candidate.Party.CHP <- relevel(Candidate.Party, ref = "CHP")
Candidate.Party.MHP <- relevel(Candidate.Party, ref = "MHP")
Candidate.Party.AKP <- relevel(Candidate.Party, ref = "AKP")
Candidate.Party.HDP <- relevel(Candidate.Party, ref = "HDP")

Twitter specific model

twitter <- glm(Incivility ~  Candidate.Party+ Candidate.Age + 
                  Previously.Candidate + Contains.Retweet+
                  Contains.Link, data= twitter_data, family = binomial)
panderOptions("digits", 2)
pander(twitter)
Fitting generalized (binomial/logit) linear model: Incivility ~ Candidate.Party + Candidate.Age + Previously.Candidate + Contains.Retweet + Contains.Link (continued below)
  Estimate Std. Error z value
Candidate.PartyCHP 0.51 0.15 3.5
Candidate.PartyMHP 1.8 0.11 16
Candidate.PartyHDP 1 0.12 8.6
Candidate.Age 0.016 0.0052 3
Previously.CandidateYes -0.32 0.084 -3.8
Contains.Retweet 0.88 0.085 10
Contains.Link -0.2 0.083 -2.4
(Intercept) -4.4 0.27 -16
  Pr(>|z|)
Candidate.PartyCHP 0.00054
Candidate.PartyMHP 5.3e-58
Candidate.PartyHDP 0.0000000000000000061
Candidate.Age 0.0024
Previously.CandidateYes 0.00015
Contains.Retweet 0.00000000000000000000000021
Contains.Link 0.018
(Intercept) 2.3e-57
#With Tone
#twitterT <- glm(Incivility ~ Tone + Candidate.Party+ Candidate.Age + 
#                 Previously.Candidate + Contains.Retweet+
#                 Contains.Link, family = binomial)

#Party Comparisons
#twitter <- glm(Incivility ~ Candidate.Party.CHP+ Candidate.Age + 
                 #Previously.Candidate + Contains.Retweet+
                 #Contains.Link, family = binomial)

#twitter <- glm(Incivility ~ Candidate.Party.MHP+ Candidate.Age + 
                #Previously.Candidate + Contains.Retweet+
                 #Contains.Link, family = binomial)

Descriptive tables of Twitter data

sjp.frq(twitter_data$Tone, show.prc = T)

sjp.frq(twitter_data$Incivility, show.prc = T)

t1 <- sjt.glm(twitter, show.se = T, show.r2 = T,  use.viewer = TRUE)
## Waiting for profiling to be done...
pander(t1)
## Warning in pander.default(t1): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtglm", reverting to default.
t2<-sjt.xtab(Incivility, Candidate.Party, use.viewer = TRUE,  show.col.prc = T, tdcol.col = "black")
pander(t2)
## Warning in pander.default(t2): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtxtab", reverting to default.
t3<-sjt.xtab(Incivility, Previously.Candidate, use.viewer = TRUE, show.col.prc = TRUE, tdcol.col = "black")
pander(t3)
## Warning in pander.default(t3): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtxtab", reverting to default.
t4<-sjt.xtab(Incivility, Contains.Retweet, use.viewer = TRUE, show.col.prc = TRUE, tdcol.col = "black")
pander(t4)
## Warning in pander.default(t4): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtxtab", reverting to default.
t5<-sjt.xtab(Incivility, Contains.Link, use.viewer = TRUE, show.col.prc = TRUE, tdcol.col = "black")
pander(t5)
## Warning in pander.default(t5): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtxtab", reverting to default.

Plots of Twitter specific model

sjp.glm(twitter, sort.est= FALSE, title = "Incivility - Twitter Specific Model")
## Waiting for profiling to be done...

sjp.glm(twitter, type="slope")

sjp.glm(twitter, type="slope", show.ci = T)

sjp.glm(twitter, type="eff", show.ci = T)

sjp.glm(twitter, type="pred", show.ci = T, vars=  "Previously.Candidate")


Analysis on Newspaper data

Loading data

np_data <- read.dta("D:/emre/SkyDrive/makale/Twitter/Incivility/Revisit/GazeteKasimRS12.dta")
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated

Formating data

Newspaper.ideology <- np_data$np_pro
Message.sender <- np_data$sender_gov
Time.focus <- np_data$time_focus
Message.content <- np_data$content

Incivility <- ordered(np_data$incivility, levels=c(0,1), labels=c("No", "Yes"))


Newspaper.ideology.c <- relevel(np_data$np_pro, ref = "main stream")

Newspaper Specific Model

np <- glm(incivility ~ Newspaper.ideology.c  + Message.sender + 
            Time.focus + Message.content, data= np_data, family = binomial)
panderOptions("digits", 2)
pander(np)
Fitting generalized (binomial/logit) linear model: incivility ~ Newspaper.ideology.c + Message.sender + Time.focus + Message.content (continued below)
  Estimate Std. Error z value
Newspaper.ideology.canti-government -0.093 0.27 -0.34
Newspaper.ideology.cpro-government -0.17 0.34 -0.51
Message.sendergovernment -0.96 0.28 -3.4
Time.focusRetrospective 0.97 0.19 5.1
Message.contentPolicy -1.6 0.28 -5.6
(Intercept) 0.66 0.31 2.1
  Pr(>|z|)
Newspaper.ideology.canti-government 0.73
Newspaper.ideology.cpro-government 0.61
Message.sendergovernment 0.0006
Time.focusRetrospective 0.00000033
Message.contentPolicy 0.00000002
(Intercept) 0.032

Descriptive tables of Newspaper data

n1<-sjt.glm(np, use.viewer = TRUE, show.se = T, show.r2 = T)
## Waiting for profiling to be done...
pander(n1)
## Warning in pander.default(n1): No pander.method for "sjTable", reverting to
## default.No pander.method for "sjtglm", reverting to default.

Plots of Newspaper Specific Model

sjp.glm(np, sort.est= FALSE, title = "Incivility - Newspaper Specific Model")
## Waiting for profiling to be done...

———Comparison Models———

Comparison Model Newspapers

np_comp <- glm(incivility ~  Message.sender + 
                 Time.focus + Message.content, data= np_data, family = binomial)
#Table
sjt.glm(np_comp, use.viewer = TRUE, show.se = T, show.r2 = T)
## Waiting for profiling to be done...
panderOptions("digits", 2)
pander(np_comp)
Fitting generalized (binomial/logit) linear model: incivility ~ Message.sender + Time.focus + Message.content
  Estimate Std. Error z value Pr(>|z|)
Message.sendergovernment -1 0.2 -5.2 0.00000019
Time.focusRetrospective 0.96 0.19 5.2 0.00000025
Message.contentPolicy -1.6 0.27 -5.9 0.0000000034
(Intercept) 0.62 0.28 2.2 0.025
#Plot
sjp.glm(np_comp, sort.est= FALSE, title = "Incivility - Newspapers Comparison Model")
## Waiting for profiling to be done...

sjp.glm(np_comp, type="slope", show.ci = T)

sjp.glm(np_comp, type="pred", show.ci = T, vars=  "Message.content")

Comparison Model Twitter

Message.Sender <- twitter_data$cpgroup
Time.focus <- twitter_data$Odak
twt_comp <- glm(Incivility ~ Message.Sender + Time.focus + twitter_data$MessageContent, data= twitter_data, family = binomial)
panderOptions("digits", 2)
pander(twt_comp)
Fitting generalized (binomial/logit) linear model: Incivility ~ Message.Sender + Time.focus + twitter_data$MessageContent (continued below)
  Estimate Std. Error z value
Message.SenderGovernment -1.4 0.096 -14
Time.focusRetrospective 3.6 0.41 8.8
twitter_data$MessageContentPolicy 1.5 0.088 17
(Intercept) -5.8 0.41 -14
  Pr(>|z|)
Message.SenderGovernment 3.4e-46
Time.focusRetrospective 0.0000000000000000016
twitter_data$MessageContentPolicy 1.3e-61
(Intercept) 1.2e-44
#Table
sjt.glm(twt_comp, use.viewer = TRUE, show.se = T, show.r2 = T)
## Waiting for profiling to be done...
#Plot
sjp.glm(twt_comp, sort.est= FALSE, "Incivility - Twitter Comparison Model")
## Warning: Invalid `type` argument. Defaulting to `dots`.
## Waiting for profiling to be done...