library(reshape2) # melt
## Warning: package 'reshape2' was built under R version 3.4.3
library(MASS) # lda
library(psy) # cronbach
library(psych) # KMO
##
## Attaching package: 'psych'
## The following object is masked from 'package:psy':
##
## wkappa
library(Hmisc) # correlation matrix
## Warning: package 'Hmisc' was built under R version 3.4.3
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.3
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
##
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
##
## describe
## The following objects are masked from 'package:base':
##
## format.pval, units
library(psych) #KMO
library(Hmisc) # correlation matrix
library(mapproj) # map
## Warning: package 'mapproj' was built under R version 3.4.2
## Loading required package: maps
## Warning: package 'maps' was built under R version 3.4.2
cat("\014") # cleans screen
rm(list=ls(all=TRUE)) # remove variables in working memory
setwd("C:/Users/Erik Ernesto Vazquez/Downloads") # sets working directory
MainStudy<-read.csv("MainStudyNov2.csv", header=T)
## MainStudy<-read.csv("MonaMourMainStudyUS.csv", header=T) # reads raw data from Qualtrics
## MainStudy<-read.csv("MonaMourMainStudyMX.csv", header=T) # reads raw data from Qualtrics
MainStudy1<-subset(MainStudy,MainStudy$Q40_Page.Submit!=""&MainStudy$FL_17_DO!="")
MainStudy1<-subset(MainStudy1,MainStudy1$Q4==3|MainStudy1$Q4==4) ## Only Desktop and Laptop PC
## recoding mobile and tablet (reverse)
MainStudy2<-subset(MainStudy,MainStudy$Q40_Page.Submit!=""&MainStudy$FL_17_DO!="")
MainStudy2<-subset(MainStudy2,MainStudy2$Q4==1|MainStudy2$Q4==2) ## Only Mobile and Tablet
MainStudy2$Q19_1<-10-MainStudy2$Q19_1
MainStudy2$Q19_2<-10-MainStudy2$Q19_2
MainStudy2$Q19_3<-10-MainStudy2$Q19_3
MainStudy2$Q19_4<-10-MainStudy2$Q19_4
MainStudy2$Q21_7<-10-MainStudy2$Q21_7
MainStudy2$Q21_8<-10-MainStudy2$Q21_8
MainStudy2$Q21_9<-10-MainStudy2$Q21_9
MainStudy<-rbind(MainStudy1,MainStudy2)
## Filtering out low income participants
summary(MainStudy$Q22)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.000 4.000 3.895 5.000 9.000
table(MainStudy$Q22)
##
## 1 2 3 4 5 6 7 8 9
## 77 87 63 95 114 55 36 11 7
MainStudy<-subset(MainStudy,MainStudy$Q22>4)
table(MainStudy$Q25)
##
## 1 2 3 4 5 6
## 159 18 11 1 31 3
MainStudy<-subset(MainStudy,MainStudy$Q25==1)
table(MainStudy$Q4)
##
## 1 2 3 4
## 14 11 87 47
table(MainStudy$FL_17_DO)
##
## Block1 Block2 Block3 Block4 Block5 Block6
## 0 33 32 23 22 26 23
## Age of the sample
mean(MainStudy$Q26)
## [1] 39.03145
sd(MainStudy$Q26)
## [1] 11.45847
MainStudy1<-subset(MainStudy,MainStudy$FL_17_DO=="Block1")
MainStudy2<-subset(MainStudy,MainStudy$FL_17_DO=="Block2")
MainStudy3<-subset(MainStudy,MainStudy$FL_17_DO=="Block3")
MainStudy4<-subset(MainStudy,MainStudy$FL_17_DO=="Block4")
MainStudy5<-subset(MainStudy,MainStudy$FL_17_DO=="Block5")
MainStudy6<-subset(MainStudy,MainStudy$FL_17_DO=="Block6")
## MainStudy<-rbind(MainStudy1[1:74,],MainStudy2[1:74,],MainStudy3[1:74,],
## MainStudy4[1:74,],MainStudy5[1:74,],MainStudy6[1:74,])
## table(MainStudy$FL_17_DO)
## index<-sample(1:nrow(MainStudy),10000,replace=T)
## MainStudy<-as.data.frame(MainStudy[index,])
table(MainStudy$FL_17_DO)
##
## Block1 Block2 Block3 Block4 Block5 Block6
## 0 33 32 23 22 26 23
cronbach(cbind(MainStudy$Q19_1,MainStudy$Q19_2,MainStudy$Q19_3,MainStudy$Q19_4))
## $sample.size
## [1] 159
##
## $number.of.items
## [1] 4
##
## $alpha
## [1] 0.9191072
cronbach(cbind(MainStudy$Q21_7,MainStudy$Q21_8,MainStudy$Q21_9))
## $sample.size
## [1] 159
##
## $number.of.items
## [1] 3
##
## $alpha
## [1] 0.9710056
MainStudy$Auth<-(MainStudy$Q19_1+MainStudy$Q19_2+MainStudy$Q19_3+MainStudy$Q19_4)/4
MainStudy$PurchInt<-(MainStudy$Q21_7+MainStudy$Q21_8+MainStudy$Q21_9)/3
MainStudy$UrbanLvl<-ifelse(MainStudy$FL_17_DO=="Block1"|
MainStudy$FL_17_DO=="Block2"|
MainStudy$FL_17_DO=="Block3",1,2)
MainStudy$MCLvl<-ifelse(MainStudy$FL_17_DO=="Block1"|
MainStudy$FL_17_DO=="Block4",1,
(ifelse(MainStudy$FL_17_DO=="Block2"|
MainStudy$FL_17_DO=="Block5",2,3)))
table(MainStudy$FL_17_DO)
##
## Block1 Block2 Block3 Block4 Block5 Block6
## 0 33 32 23 22 26 23
table(MainStudy$UrbanLvl)
##
## 1 2
## 88 71
table(MainStudy$MCLvl)
##
## 1 2 3
## 55 58 46
aggregate(MainStudy$Auth,list(MainStudy$UrbanLvl),mean)
## Group.1 x
## 1 1 4.795455
## 2 2 4.137324
aggregate(MainStudy$Auth,list(MainStudy$UrbanLvl),sd)
## Group.1 x
## 1 1 1.848635
## 2 2 1.431027
aggregate(MainStudy$Auth,list(MainStudy$MCLvl),mean)
## Group.1 x
## 1 1 4.490909
## 2 2 4.599138
## 3 3 4.391304
aggregate(MainStudy$Auth,list(MainStudy$MCLvl),sd)
## Group.1 x
## 1 1 1.580380
## 2 2 1.743371
## 3 3 1.816324
t.test(MainStudy$Auth~MainStudy$UrbanLvl) ## H1 Approved
##
## Welch Two Sample t-test
##
## data: MainStudy$Auth by MainStudy$UrbanLvl
## t = 2.5298, df = 156.75, p-value = 0.0124
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.1442811 1.1719801
## sample estimates:
## mean in group 1 mean in group 2
## 4.795455 4.137324
summary(aov(Auth~as.factor(MCLvl),MainStudy)) ## H2 Rejected
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 1.1 0.5588 0.191 0.826
## Residuals 156 456.6 2.9267
aov.out<-aov(Auth~as.factor(MCLvl),MainStudy)
TukeyHSD(aov.out)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = Auth ~ as.factor(MCLvl), data = MainStudy)
##
## $`as.factor(MCLvl)`
## diff lwr upr p adj
## 2-1 0.10822884 -0.6536825 0.8701402 0.9396467
## 3-1 -0.09960474 -0.9084417 0.7092322 0.9542851
## 3-2 -0.20783358 -1.0070867 0.5914195 0.8119659
summary(lm(Auth~MCLvl,MainStudy))
##
## Call:
## lm(formula = Auth ~ MCLvl, data = MainStudy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.5437 -1.2490 -0.0437 1.0010 4.5456
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.58832 0.35755 12.833 <2e-16 ***
## MCLvl -0.04464 0.17029 -0.262 0.794
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.707 on 157 degrees of freedom
## Multiple R-squared: 0.0004375, Adjusted R-squared: -0.005929
## F-statistic: 0.06872 on 1 and 157 DF, p-value: 0.7936
summary(lm(PurchInt~Auth,MainStudy)) ## H3 Approved
##
## Call:
## lm(formula = PurchInt ~ Auth, data = MainStudy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.118 -1.673 0.449 1.882 3.582
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.6620 0.5149 9.054 5.1e-16 ***
## Auth 0.3778 0.1070 3.530 0.000546 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.29 on 157 degrees of freedom
## Multiple R-squared: 0.07352, Adjusted R-squared: 0.06762
## F-statistic: 12.46 on 1 and 157 DF, p-value: 0.0005462
## Interaction effects
summary(aov(Auth~UrbanLvl*MCLvl,MainStudy)) ## There are not interaction effects
## Df Sum Sq Mean Sq F value Pr(>F)
## UrbanLvl 1 17.0 17.020 5.991 0.0155 *
## MCLvl 1 0.0 0.014 0.005 0.9441
## UrbanLvl:MCLvl 1 0.3 0.330 0.116 0.7338
## Residuals 155 440.3 2.841
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm(Auth~UrbanLvl*MCLvl,MainStudy)) ## There are not interaction effects
##
## Call:
## lm(formula = Auth ~ UrbanLvl * MCLvl, data = MainStudy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8402 -1.2368 0.0363 0.9369 4.8616
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.1503 1.0781 4.777 4.09e-06 ***
## UrbanLvl -0.4307 0.7160 -0.601 0.548
## MCLvl 0.1557 0.5199 0.299 0.765
## UrbanLvl:MCLvl -0.1155 0.3390 -0.341 0.734
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.685 on 155 degrees of freedom
## Multiple R-squared: 0.03794, Adjusted R-squared: 0.01932
## F-statistic: 2.037 on 3 and 155 DF, p-value: 0.1109
## Verifying equivalency of groups
t.test(as.numeric(MainStudy$Q26)~MainStudy$UrbanLvl) ## Age
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$Q26) by MainStudy$UrbanLvl
## t = 1.7092, df = 153.34, p-value = 0.08944
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.4808336 6.6511281
## sample estimates:
## mean in group 1 mean in group 2
## 40.40909 37.32394
summary(aov(as.numeric(Q26)~as.factor(MCLvl),MainStudy)) ## Age
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 147 73.3 0.555 0.575
## Residuals 156 20598 132.0
t.test(as.numeric(MainStudy$Q22)~MainStudy$UrbanLvl) ## Income
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$Q22) by MainStudy$UrbanLvl
## t = 0.82741, df = 154.1, p-value = 0.4093
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1776621 0.4337441
## sample estimates:
## mean in group 1 mean in group 2
## 5.818182 5.690141
summary(aov(as.numeric(Q22)~as.factor(MCLvl),MainStudy)) ## Income
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 6.14 3.0690 3.307 0.0392 *
## Residuals 156 144.78 0.9281
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
t.test(as.numeric(MainStudy$Q23)~MainStudy$UrbanLvl) ## Education *** unbalanced
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$Q23) by MainStudy$UrbanLvl
## t = 1.0177, df = 150.5, p-value = 0.3104
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2746821 0.8582288
## sample estimates:
## mean in group 1 mean in group 2
## 11.19318 10.90141
summary(aov(as.numeric(Q23)~as.factor(MCLvl),MainStudy)) ## Education
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 14.1 7.068 2.217 0.112
## Residuals 156 497.2 3.187
summary(lm(Auth~Q23,MainStudy)) ## Does not affect Auth
##
## Call:
## lm(formula = Auth ~ Q23, data = MainStudy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8387 -1.2186 -0.1646 0.8844 4.6834
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.57651 0.83175 3.098 0.00231 **
## Q23 0.17401 0.07422 2.345 0.02029 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.678 on 157 degrees of freedom
## Multiple R-squared: 0.03383, Adjusted R-squared: 0.02768
## F-statistic: 5.498 on 1 and 157 DF, p-value: 0.02029
t.test(as.numeric(MainStudy$Q24)~MainStudy$UrbanLvl) ## Purchase online clothing
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$Q24) by MainStudy$UrbanLvl
## t = 0.097547, df = 151.91, p-value = 0.9224
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.06163199 0.06803404
## sample estimates:
## mean in group 1 mean in group 2
## 1.045455 1.042254
summary(aov(as.numeric(Q24)~as.factor(MCLvl),MainStudy)) ## Purchase online clothing
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 0.007 0.00334 0.078 0.925
## Residuals 156 6.685 0.04285
t.test(as.numeric(MainStudy$Q24)~MainStudy$UrbanLvl) ## Purchase online clothing
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$Q24) by MainStudy$UrbanLvl
## t = 0.097547, df = 151.91, p-value = 0.9224
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.06163199 0.06803404
## sample estimates:
## mean in group 1 mean in group 2
## 1.045455 1.042254
summary(aov(as.numeric(Q24)~as.factor(MCLvl),MainStudy)) ## Purchase online clothing
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 0.007 0.00334 0.078 0.925
## Residuals 156 6.685 0.04285
## chisq.test(MainStudy$UrbanLvl,MainStudy$Q25,simulate.p.value=T) ## Race-Ethinicity
## chisq.test(MainStudy$MCLvl,MainStudy$Q25,simulate.p.value=T) ## Race-Ethinicity
t.test(as.numeric(MainStudy$LocationLatitude)~MainStudy$UrbanLvl) ## LocatonLat
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$LocationLatitude) by MainStudy$UrbanLvl
## t = 0.82041, df = 144.5, p-value = 0.4133
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.168638 2.827240
## sample estimates:
## mean in group 1 mean in group 2
## 38.40965 37.58035
summary(aov(as.numeric(LocationLatitude)~as.factor(MCLvl),MainStudy)) ## LocatonLat
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 73 36.70 0.931 0.396
## Residuals 156 6152 39.43
t.test(as.numeric(MainStudy$LocationLongitude)~MainStudy$UrbanLvl) ## LocatonLon
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$LocationLongitude) by MainStudy$UrbanLvl
## t = -1.1742, df = 101.35, p-value = 0.2431
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -15.854159 4.063811
## sample estimates:
## mean in group 1 mean in group 2
## -86.89086 -80.99569
summary(aov(as.numeric(LocationLongitude)~as.factor(MCLvl),MainStudy)) ## LocatonLon
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 312 156.1 0.175 0.839
## Residuals 156 138907 890.4
MainStudy[is.na(MainStudy)]<-0
MainStudy$StimuliTime<-MainStudy$Q32_Page.Submit+MainStudy$Q33_Page.Submit+
MainStudy$Q34_Page.Submit+MainStudy$Q35_Page.Submit+MainStudy$Q36_Page.Submit+
MainStudy$Q37_Page.Submit
t.test(as.numeric(MainStudy$StimuliTime)~MainStudy$UrbanLvl) ## StimuliTime
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudy$StimuliTime) by MainStudy$UrbanLvl
## t = -1.0162, df = 152.8, p-value = 0.3112
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.2685492 0.4068091
## sample estimates:
## mean in group 1 mean in group 2
## 8.540045 8.970915
summary(aov(as.numeric(StimuliTime)~as.factor(MCLvl),MainStudy)) ## StimuliTime
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 10.2 5.101 0.712 0.492
## Residuals 156 1118.4 7.169
summary(lm(Auth~StimuliTime,MainStudy)) ## Does not affect Auth
##
## Call:
## lm(formula = Auth ~ StimuliTime, data = MainStudy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.5186 -1.2872 -0.0376 1.0105 4.6828
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.75070 0.46354 10.249 <2e-16 ***
## StimuliTime -0.02853 0.05077 -0.562 0.575
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.706 on 157 degrees of freedom
## Multiple R-squared: 0.002007, Adjusted R-squared: -0.00435
## F-statistic: 0.3157 on 1 and 157 DF, p-value: 0.575
## Reviewing groups in detail
aggregate(MainStudy$Auth,list(MainStudy$FL_17_DO),mean)
## Group.1 x
## 1 Block1 4.856061
## 2 Block2 4.601562
## 3 Block3 4.978261
## 4 Block4 3.943182
## 5 Block5 4.596154
## 6 Block6 3.804348
aggregate(MainStudy$Auth,list(MainStudy$FL_17_DO),sd)
## Group.1 x
## 1 Block1 1.646528
## 2 Block2 1.877133
## 3 Block3 2.123881
## 4 Block4 1.329455
## 5 Block5 1.600120
## 6 Block6 1.231584
MainStudyX<-subset(MainStudy,MainStudy$FL_17_DO=="Block1"|MainStudy$FL_17_DO=="Block4")
t.test(MainStudyX$Auth~MainStudyX$UrbanLvl) ## H1 works only for model 1
##
## Welch Two Sample t-test
##
## data: MainStudyX$Auth by MainStudyX$UrbanLvl
## t = 2.2646, df = 50.947, p-value = 0.02782
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.1035955 1.7221620
## sample estimates:
## mean in group 1 mean in group 2
## 4.856061 3.943182
t.test(as.numeric(MainStudyX$Q26)~MainStudyX$UrbanLvl) ## Age is equivalent among groups
##
## Welch Two Sample t-test
##
## data: as.numeric(MainStudyX$Q26) by MainStudyX$UrbanLvl
## t = 2.6935, df = 51.674, p-value = 0.00951
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 2.004482 13.722791
## sample estimates:
## mean in group 1 mean in group 2
## 42.18182 34.31818
MainStudyX<-subset(MainStudy,MainStudy$FL_17_DO=="Block1"|MainStudy$FL_17_DO=="Block2"|MainStudy$FL_17_DO=="Block3")
summary(aov(Auth~as.factor(MCLvl),MainStudyX))
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 2.09 1.046 0.301 0.741
## Residuals 85 295.23 3.473
aov.out<-aov(Auth~as.factor(MCLvl),MainStudyX)
TukeyHSD(aov.out)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = Auth ~ as.factor(MCLvl), data = MainStudyX)
##
## $`as.factor(MCLvl)`
## diff lwr upr p adj
## 2-1 -0.2544981 -1.3574663 0.8484701 0.8465425
## 3-1 0.1222003 -1.0853672 1.3297677 0.9683990
## 3-2 0.3766984 -0.8385938 1.5919906 0.7408095
summary(lm(Auth~MCLvl,MainStudyX)) ## H2 partially works only for background 1
##
## Call:
## lm(formula = Auth ~ MCLvl, data = MainStudyX)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8402 -1.3000 -0.0902 1.0326 4.2000
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.71966 0.51326 9.195 1.97e-14 ***
## MCLvl 0.04018 0.25099 0.160 0.873
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.859 on 86 degrees of freedom
## Multiple R-squared: 0.0002979, Adjusted R-squared: -0.01133
## F-statistic: 0.02563 on 1 and 86 DF, p-value: 0.8732
summary(aov(as.numeric(Q26)~as.factor(MCLvl),MainStudy)) ## Age is equivalent among groups
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(MCLvl) 2 147 73.3 0.555 0.575
## Residuals 156 20598 132.0
## Location of the sample
map(database="world", ylim=c(36,40), xlim=c(-99,-95), col="white", fill=TRUE, projection="gilbert", orientation= c(90,0,225))
lon<-as.character(MainStudy$LocationLongitude)
lat<-as.character(MainStudy$LocationLatitude)
coord<-mapproject(lon, lat, proj="gilbert", orientation=c(90, 0, 225))
points(coord, pch=20, cex=0.8, col="black")
