# Set the working directory to the location on your computer to which you downloaded the files from OSF. You will also need to download the datasets to this exact same location - Do NOT rename the files!!!
x <- getwd()
setwd(x)
library(knitr)
library(reshape2)
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
library(lattice)
library(magrittr)
library(lme4)
## Warning: package 'lme4' was built under R version 3.6.2
## Loading required package: Matrix
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 3.6.2
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library (psych)
library (gtools)
## 
## Attaching package: 'gtools'
## The following object is masked from 'package:psych':
## 
##     logit
library (multicon)
## Loading required package: abind
## Loading required package: foreach
library (dplyr)
twitBFIdata <- read.table("Twitter Target self-report w TID.csv", header = T, sep = ",")
igBFIdata <- read.table("Instagram Target self-report w TID.csv", header = T, sep = ",")
twitSECSdata <- read.table("Twitter Target self-report SECS.csv", header = T, sep = ",")
igSECSdata <- read.table("Instagram Target self-report SECS.csv", header = T, sep = ",")
#reverse score items
revcols = c(11,16,26,31,36,51,12,17,22,37,42,47,3,8,23,28,48,58,4,9,24,29,44,49,5,25,30,45,50,55)
twitBFIdata[,revcols] = 6 - twitBFIdata[,revcols]

#create key for scoring.  
BFIkeys.list<-list("Ext"=c(1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56), "Agr"=c(2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57), "Con"=c(3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58), "Neur"=c(4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59), "Open"=c(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60))

#Score the measure and enter the scores in a data frame  
twitBFIout <- scoreTest(twitBFIdata, BFIkeys.list, rel=T, maxScore=5, minScore=1, check.keys=T)
describe(twitBFIout$scores)
##      vars  n mean   sd median trimmed  mad  min  max range  skew kurtosis
## Ext     1 74 3.37 0.72   3.38    3.36 0.68 1.50 5.00  3.50  0.08    -0.14
## Agr     2 74 3.80 0.62   3.88    3.82 0.68 2.42 5.00  2.58 -0.33    -0.74
## Con     3 74 3.63 0.68   3.58    3.64 0.74 1.42 5.00  3.58 -0.34     0.23
## Neur    4 74 2.97 0.90   3.08    2.97 1.05 1.00 4.83  3.83 -0.06    -0.59
## Open    5 74 3.90 0.59   4.00    3.93 0.49 2.42 5.00  2.58 -0.42    -0.37
##        se
## Ext  0.08
## Agr  0.07
## Con  0.08
## Neur 0.11
## Open 0.07
twitBFIout$rel
##      raw_alpha std.alpha   G6(smc) average_r       S/N        ase     mean
## Ext  0.8494683 0.8516152 0.8850936 0.3235334  5.739234 0.02534263 3.365581
## Agr  0.8193527 0.8394304 0.8683710 0.3034526  5.227830 0.02984279 3.795045
## Con  0.8625929 0.8683612 0.8943854 0.3547188  6.596542 0.02288202 3.626126
## Neur 0.9172579 0.9166673 0.9230170 0.4782628 11.000084 0.01383471 2.968468
## Open 0.8189579 0.8260122 0.8606535 0.2834764  4.747529 0.03033694 3.899775
##             sd        NA
## Ext  0.7207739 0.2927104
## Agr  0.6181226 0.3362576
## Con  0.6773183 0.3470942
## Neur 0.9047800 0.4853434
## Open 0.5894138 0.2813425
twitBFIscore<-data.frame(twitBFIout$scores, twitBFIdata$TID)

describe(twitBFIscore)
##                 vars  n  mean    sd median trimmed   mad  min    max
## Ext                1 74  3.37  0.72   3.38    3.36  0.68 1.50   5.00
## Agr                2 74  3.80  0.62   3.88    3.82  0.68 2.42   5.00
## Con                3 74  3.63  0.68   3.58    3.64  0.74 1.42   5.00
## Neur               4 74  2.97  0.90   3.08    2.97  1.05 1.00   4.83
## Open               5 74  3.90  0.59   4.00    3.93  0.49 2.42   5.00
## twitBFIdata.TID    6 75 75.68 43.61  76.00   75.67 56.34 2.00 150.00
##                  range  skew kurtosis   se
## Ext               3.50  0.08    -0.14 0.08
## Agr               2.58 -0.33    -0.74 0.07
## Con               3.58 -0.34     0.23 0.08
## Neur              3.83 -0.06    -0.59 0.11
## Open              2.58 -0.42    -0.37 0.07
## twitBFIdata.TID 148.00  0.00    -1.25 5.04
#Set up for confidence intervals

Ext.M <- 3.37
Ext.SD <- 0.72
Ext.N <- 74

Agr.M <- 3.80
Agr.SD<-0.62
Agr.N<-74

Con.M<-3.63
Con.SD<-0.68
Con.N<-74

Neur.M<-2.97
Neur.SD<-0.90
Neur.N<-74

Open.M<-3.90
Open.SD<-0.59
Open.N<-74

#Ext CI
error1 <- qt(0.975,df=Ext.N-1)*Ext.SD/sqrt(Ext.N)
Ext.left <- Ext.M-error1
Ext.right <- Ext.M+error1
Ext.left
## [1] 3.20319
Ext.right
## [1] 3.53681
#Agr CI
error2 <- qt(0.975,df=Agr.N-1)*Agr.SD/sqrt(Agr.N)
Agr.left <- Agr.M-error2
Agr.right <- Agr.M+error2
Agr.left
## [1] 3.656358
Agr.right
## [1] 3.943642
#Con CI
error3 <- qt(0.975,df=Con.N-1)*Con.SD/sqrt(Con.N)
Con.left <- Con.M-error3
Con.right <- Con.M+error3
Con.left
## [1] 3.472457
Con.right
## [1] 3.787543
#Open CI
error4 <- qt(0.975,df=Open.N-1)*Open.SD/sqrt(Open.N)
Open.left <- Open.M-error4
Open.right <- Open.M+error4
Open.left
## [1] 3.763308
Open.right
## [1] 4.036692
#Neur CI
error5 <- qt(0.975,df=Neur.N-1)*Open.SD/sqrt(Neur.N)
Neur.left <- Neur.M-error4
Neur.right <- Neur.M+error4
Neur.left
## [1] 2.833308
Neur.right
## [1] 3.106692
#reverse score items
revcols = c(11,16,26,31,36,51,12,17,22,37,42,47,3,8,23,28,48,58,4,9,24,29,44,49,5,25,30,45,50,55)
igBFIdata[,revcols] = 6 - igBFIdata[,revcols]

#create key for scoring.  
BFIkeys.list<-list("Ext"=c(1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56), "Agr"=c(2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57), "Con"=c(3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58), "Neur"=c(4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59), "Open"=c(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60))

#Score the measure and enter the scores in a data frame  
igBFIout <- scoreTest(igBFIdata, BFIkeys.list, rel=T, maxScore=5, minScore=1, check.keys=T)
describe(igBFIout$scores)
##      vars  n mean   sd median trimmed  mad  min  max range  skew kurtosis
## Ext     1 75 3.48 0.71   3.50    3.49 0.62 1.50 4.92  3.42 -0.16    -0.29
## Agr     2 75 3.92 0.56   4.00    3.93 0.49 2.75 5.00  2.25 -0.26    -0.78
## Con     3 75 3.57 0.60   3.58    3.56 0.74 2.50 4.83  2.33  0.14    -1.10
## Neur    4 75 2.85 0.86   2.83    2.85 0.99 1.33 4.50  3.17 -0.02    -1.02
## Open    5 75 3.85 0.60   3.83    3.86 0.74 2.50 5.00  2.50 -0.03    -0.86
##        se
## Ext  0.08
## Agr  0.06
## Con  0.07
## Neur 0.10
## Open 0.07
igBFIout$rel
##      raw_alpha std.alpha   G6(smc) average_r       S/N        ase     mean
## Ext  0.8634154 0.8639773 0.8862986 0.3461102  6.351716 0.02296216 3.484444
## Agr  0.7958289 0.8278379 0.8649373 0.2860746  4.808479 0.03387611 3.923333
## Con  0.8003343 0.8017935 0.8516812 0.2521147  4.045242 0.03363386 3.573333
## Neur 0.9153863 0.9136382 0.9266957 0.4685373 10.579195 0.01396517 2.846667
## Open 0.8165145 0.8248548 0.8705013 0.2818477  4.709549 0.03084594 3.854444
##             sd        NA
## Ext  0.7087894 0.3551186
## Agr  0.5551019 0.2956795
## Con  0.6007628 0.2318560
## Neur 0.8563313 0.4924166
## Open 0.6035887 0.2620133
igBFIscore <- data.frame(igBFIout$scores, igBFIdata$TID)

#t-tests
t.test(igBFIscore$Ext, twitBFIscore$Ext)
## 
##  Welch Two Sample t-test
## 
## data:  igBFIscore$Ext and twitBFIscore$Ext
## t = 1.0148, df = 146.87, p-value = 0.3119
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1126105  0.3503364
## sample estimates:
## mean of x mean of y 
##  3.484444  3.365581
t.test(igBFIscore$Agr, twitBFIscore$Agr)
## 
##  Welch Two Sample t-test
## 
## data:  igBFIscore$Agr and twitBFIscore$Agr
## t = 1.3323, df = 144.89, p-value = 0.1848
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.06202543  0.31860201
## sample estimates:
## mean of x mean of y 
##  3.923333  3.795045
t.test(igBFIscore$Con, twitBFIscore$Con)
## 
##  Welch Two Sample t-test
## 
## data:  igBFIscore$Con and twitBFIscore$Con
## t = -0.50309, df = 144.45, p-value = 0.6157
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2602022  0.1546166
## sample estimates:
## mean of x mean of y 
##  3.573333  3.626126
t.test(igBFIscore$Open, twitBFIscore$Open)
## 
##  Welch Two Sample t-test
## 
## data:  igBFIscore$Open and twitBFIscore$Open
## t = -0.4638, df = 146.98, p-value = 0.6435
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2384794  0.1478187
## sample estimates:
## mean of x mean of y 
##  3.854444  3.899775
t.test(igBFIscore$Neur, twitBFIscore$Neur)
## 
##  Welch Two Sample t-test
## 
## data:  igBFIscore$Neur and twitBFIscore$Neur
## t = -0.84373, df = 146.31, p-value = 0.4002
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4071026  0.1634990
## sample estimates:
## mean of x mean of y 
##  2.846667  2.968468
#Set up for confidence intervals
Ext.M <- 3.48
Ext.SD <- 0.71
Ext.N <- 75

Agr.M <- 3.92
Agr.SD<-0.56
Agr.N<-75

Con.M<-3.57
Con.SD<-0.60
Con.N<-75

Neur.M<-2.85
Neur.SD<-0.86
Neur.N<-75

Open.M<-3.85
Open.SD<-0.60
Open.N<-75

#Ext CI
error1 <- qt(0.975,df=Ext.N-1)*Ext.SD/sqrt(Ext.N)
Ext.left <- Ext.M-error1
Ext.right <- Ext.M+error1
Ext.left
## [1] 3.316644
Ext.right
## [1] 3.643356
#Agr CI
error2 <- qt(0.975,df=Agr.N-1)*Agr.SD/sqrt(Agr.N)
Agr.left <- Agr.M-error2
Agr.right <- Agr.M+error2
Agr.left
## [1] 3.791156
Agr.right
## [1] 4.048844
#Con CI
error3 <- qt(0.975,df=Con.N-1)*Con.SD/sqrt(Con.N)
Con.left <- Con.M-error3
Con.right <- Con.M+error3
Con.left
## [1] 3.431953
Con.right
## [1] 3.708047
#Open CI
error4 <- qt(0.975,df=Open.N-1)*Open.SD/sqrt(Open.N)
Open.left <- Open.M-error4
Open.right <- Open.M+error4
Open.left
## [1] 3.711953
Open.right
## [1] 3.988047
#Neur CI
error5 <- qt(0.975,df=Neur.N-1)*Open.SD/sqrt(Neur.N)
Neur.left <- Neur.M-error5
Neur.right <- Neur.M+error5
Neur.left
## [1] 2.711953
Neur.right
## [1] 2.988047
#reverse score items
revpcols = c(1,5)
igSECSdata[,revpcols] = 10 - igSECSdata[,revpcols]
twitSECSdata[,revpcols] = 10 - twitSECSdata[,revpcols]
SECSkeys.list <-list("Social" = c(1,3,4,7,8,11,12), "Economic" = c(2,5,6,9,10))

igSECSout <- scoreTest(igSECSdata, SECSkeys.list, rel=T, maxScore=10, minScore=0, check.keys=F)
## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with the total scale and probably 
## should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
## Some items ( X1 ) were negatively correlated with the total scale and 
## probably should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
describe(igSECSout$scores)
##          vars  n mean   sd median trimmed  mad  min  max range  skew
## Social      1 75 6.31 2.39   6.57    6.40 2.75 0.86 10.0  9.14 -0.30
## Economic    2 75 6.00 1.42   6.00    5.97 1.48 3.20  9.4  6.20  0.14
##          kurtosis   se
## Social      -0.98 0.28
## Economic    -0.58 0.16
igSECSscore <- data.frame(igSECSout$scores)

#Set up for confidence intervals

IG.S.M<-6.31
IG.S.SD<-2.39
IG.S.N<-75

IG.E.M<-6.00
IG.E.SD<-1.42
IG.E.N<-75

#IG.Social CI
error1 <- qt(0.975,df=IG.S.N-1)*IG.S.SD/sqrt(IG.S.N)
IG.S.left <- IG.S.M-error1
IG.S.right <- IG.S.M+error1
IG.S.left
## [1] 5.760111
IG.S.right
## [1] 6.859889
#IG.Economic CI
error2 <- qt(0.975,df=IG.E.N-1)*IG.E.SD/sqrt(IG.E.N)
IG.E.left <- IG.E.M-error2
IG.E.right <- IG.E.M+error2
IG.E.left
## [1] 5.673288
IG.E.right
## [1] 6.326712
twitSECSout <- scoreTest(twitSECSdata, SECSkeys.list, rel = T,maxScore = 10, minScore = 0, check.keys = T)
describe(twitSECSout$scores)
##          vars  n mean   sd median trimmed  mad  min max range  skew
## Social      1 74 6.29 2.21   6.57    6.38 2.22 1.71  10  8.29 -0.37
## Economic    2 74 5.86 1.53   5.70    5.83 1.33 2.80  10  7.20  0.34
##          kurtosis   se
## Social       -0.8 0.26
## Economic      0.1 0.18
twitSECSscore <- data.frame(twitSECSout$scores)

T.S.M<-6.29
T.S.SD<-2.21
T.S.N<-75

T.E.M<-5.86
T.E.SD<-1.53
T.E.N<-75

#IG.Social CI
error1 <- qt(0.975,df=T.S.N-1)*T.S.SD/sqrt(T.S.N)
T.S.left <- T.S.M-error1
T.S.right <- T.S.M+error1
T.S.left
## [1] 5.781525
T.S.right
## [1] 6.798475
#IG.Economic CI
error2 <- qt(0.975,df=T.E.N-1)*T.E.SD/sqrt(T.E.N)
T.E.left <- T.E.M-error2
T.E.right <- T.E.M+error2
T.E.left
## [1] 5.507979
T.E.right
## [1] 6.212021
t.test(twitSECSscore$Social, igSECSscore$Social)
## 
##  Welch Two Sample t-test
## 
## data:  twitSECSscore$Social and igSECSscore$Social
## t = -0.050242, df = 146.39, p-value = 0.96
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.7641437  0.7262544
## sample estimates:
## mean of x mean of y 
##  6.293436  6.312381
t.test(twitSECSscore$Economic, igSECSscore$Economic)
## 
##  Welch Two Sample t-test
## 
## data:  twitSECSscore$Economic and igSECSscore$Economic
## t = -0.57052, df = 145.79, p-value = 0.5692
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.6153295  0.3396539
## sample estimates:
## mean of x mean of y 
##  5.862162  6.000000
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
PPDS <- read.table("d.politicalpartychi.csv", header = T, sep = ",")
#PPDS = political party descriptive stats
colnames(PPDS)
##  [1] "ï..SNS"         "PoltiicalParty" "One"            "Two"           
##  [5] "Three"          "Four"           "Five"           "Six"           
##  [9] "Seven"          "R1.D0"
tbl1 = table(PPDS$ï..SNS, PPDS$One)
tbl1
##     
##       0  1
##   IG 70  5
##   TW 70  4
chisq.test(tbl1)
## Warning in chisq.test(tbl1): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl1
## X-squared = 1.2622e-29, df = 1, p-value = 1
tbl2 = table(PPDS$ï..SNS, PPDS$Two)
tbl2
##     
##       0  1
##   IG 64 11
##   TW 66  8
chisq.test(tbl2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl2
## X-squared = 0.21152, df = 1, p-value = 0.6456
tbl3 = table(PPDS$ï..SNS, PPDS$Three)
tbl3
##     
##       0  1
##   IG 67  8
##   TW 59 15
chisq.test(tbl3)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl3
## X-squared = 1.9475, df = 1, p-value = 0.1629
tbl4 = table(PPDS$ï..SNS, PPDS$Four)
tbl4
##     
##       0  1
##   IG 51 24
##   TW 54 20
chisq.test(tbl4)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl4
## X-squared = 0.23594, df = 1, p-value = 0.6272
tbl5 = table(PPDS$ï..SNS, PPDS$Five)
tbl5
##     
##       0  1
##   IG 66  9
##   TW 61 13
chisq.test(tbl5)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl5
## X-squared = 0.52839, df = 1, p-value = 0.4673
tbl6 = table(PPDS$ï..SNS, PPDS$Six)
tbl6
##     
##       0  1
##   IG 60 15
##   TW 61 13
chisq.test(tbl6)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl6
## X-squared = 0.029004, df = 1, p-value = 0.8648
tbl7 = table(PPDS$ï..SNS, PPDS$Seven)
tbl7
##     
##       0  1
##   IG 72  3
##   TW 73  1
chisq.test(tbl7)
## Warning in chisq.test(tbl7): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tbl7
## X-squared = 0.2433, df = 1, p-value = 0.6218
tblaisle = table(PPDS$ï..SNS, PPDS$R1.D0)
tblaisle
##     
##       0  1
##   IG 27 24
##   TW 27 27
chisq.test(tblaisle)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tblaisle
## X-squared = 0.011245, df = 1, p-value = 0.9155