library(reshape2) #  melt
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.2
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## 
## 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, round.POSIXt, trunc.POSIXt, 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("MainStudyCognitiveLoadDataset.csv", header=T)  # reads raw data from Qualtrics

MainStudy<-subset(MainStudy,MainStudy$Q30_Page.Submit>0) ## Valid responses

## Clean NAs
MainStudy[is.na(MainStudy)]<-0

## Reliability of Scale Purchase Intent
cronbach(cbind(MainStudy$Q33_25,MainStudy$Q35_1,MainStudy$Q34_1))
## $sample.size
## [1] 1544
## 
## $number.of.items
## [1] 3
## 
## $alpha
## [1] 0.8993857
## Reliability of Scale Product Quality
cronbach(cbind(MainStudy$Q36_1,MainStudy$Q36_2,MainStudy$Q36_6,MainStudy$Q36_5,
               MainStudy$Q36_3,MainStudy$Q36_4,MainStudy$Q36_10,MainStudy$Q37_1))
## $sample.size
## [1] 1544
## 
## $number.of.items
## [1] 8
## 
## $alpha
## [1] 0.6180858
cronbach(cbind(MainStudy$Q36_1,MainStudy$Q36_2,MainStudy$Q36_6,MainStudy$Q36_5))
## $sample.size
## [1] 1544
## 
## $number.of.items
## [1] 4
## 
## $alpha
## [1] 0.8988028
## Computing Scale scores (items averages)
MainStudy$PurchInt<-(MainStudy$Q33_25+MainStudy$Q35_1+MainStudy$Q34_1)/3
MainStudy$ProdQuality<-(MainStudy$Q36_1+MainStudy$Q36_2+MainStudy$Q36_6+MainStudy$Q36_5)/4

## Verifying equivalency of groups
MainStudy$Group<-paste(MainStudy$FL_144_DO,MainStudy$FL_148_DO)

table(MainStudy$Group,MainStudy$Q40) ## Gender
##                                            
##                                               1   2
##   Block1onedigit Block4Mediacontenthigh      82  80
##   Block1onedigit Block5mediacontentmedium    69  99
##   Block1onedigit Block6mediacontentlow       91 106
##   Block2fivedigits Block4Mediacontenthigh    80 101
##   Block2fivedigits Block5mediacontentmedium  71  89
##   Block2fivedigits Block6mediacontentlow     75  85
##   Block3ninedigits Block4Mediacontenthigh    85  91
##   Block3ninedigits Block5mediacontentmedium  88  98
##   Block3ninedigits Block6mediacontentlow     63  91
chisq.test(MainStudy$Group,MainStudy$Q40) ## Gender
## 
##  Pearson's Chi-squared test
## 
## data:  MainStudy$Group and MainStudy$Q40
## X-squared = 5.507, df = 8, p-value = 0.7023
aggregate(MainStudy$Q25,list(MainStudy$FL_144_DO),mean)
##            Group.1        x
## 1   Block1onedigit 1959.211
## 2 Block2fivedigits 1949.359
## 3 Block3ninedigits 1977.316
aggregate(MainStudy$Q25,list(MainStudy$FL_144_DO),sd)
##            Group.1         x
## 1   Block1onedigit 210.74278
## 2 Block2fivedigits 248.82376
## 3 Block3ninedigits  87.82643
summary(aov(as.numeric(Q25)~as.factor(FL_144_DO),MainStudy)) ## Age is equivalent among groups
##                        Df   Sum Sq Mean Sq F value Pr(>F)  
## as.factor(FL_144_DO)    2   205189  102595   2.712 0.0667 .
## Residuals            1541 58290060   37826                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aov.out<-aov(as.numeric(Q25)~as.factor(FL_144_DO),MainStudy)
TukeyHSD(aov.out) ## Age is balanced among groups
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = as.numeric(Q25) ~ as.factor(FL_144_DO), data = MainStudy)
## 
## $`as.factor(FL_144_DO)`
##                                        diff         lwr      upr     p adj
## Block2fivedigits-Block1onedigit   -9.851345 -38.3215829 18.61889 0.6957866
## Block3ninedigits-Block1onedigit   18.105265 -10.1520377 46.36257 0.2897023
## Block3ninedigits-Block2fivedigits 27.956610  -0.6611393 56.57436 0.0572414
aggregate(MainStudy$Q25,list(MainStudy$FL_148_DO),mean)
##                    Group.1        x
## 1   Block4Mediacontenthigh 1947.243
## 2 Block5mediacontentmedium 1969.261
## 3    Block6mediacontentlow 1969.881
aggregate(MainStudy$Q25,list(MainStudy$FL_148_DO),sd)
##                    Group.1        x
## 1   Block4Mediacontenthigh 259.1341
## 2 Block5mediacontentmedium 151.4395
## 3    Block6mediacontentlow 151.9439
summary(aov(as.numeric(Q25)~as.factor(FL_148_DO),MainStudy)) ## Age is equivalent among groups
##                        Df   Sum Sq Mean Sq F value Pr(>F)
## as.factor(FL_148_DO)    2   171851   85926    2.27  0.104
## Residuals            1541 58323398   37848
aov.out<-aov(as.numeric(Q25)~as.factor(FL_148_DO),MainStudy)
TukeyHSD(aov.out) ## Age is balanced among groups
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = as.numeric(Q25) ~ as.factor(FL_148_DO), data = MainStudy)
## 
## $`as.factor(FL_148_DO)`
##                                                       diff        lwr
## Block5mediacontentmedium-Block4Mediacontenthigh 22.0179258  -6.382692
## Block6mediacontentlow-Block4Mediacontenthigh    22.6378517  -5.804621
## Block6mediacontentlow-Block5mediacontentmedium   0.6199258 -27.891097
##                                                      upr     p adj
## Block5mediacontentmedium-Block4Mediacontenthigh 50.41854 0.1637567
## Block6mediacontentlow-Block4Mediacontenthigh    51.08032 0.1486306
## Block6mediacontentlow-Block5mediacontentmedium  29.13095 0.9985665
## Analysis
table(MainStudy$FL_144_DO)
## 
##                    Block1onedigit Block2fivedigits Block3ninedigits 
##                0              527              501              516
aggregate(MainStudy$PurchInt,list(MainStudy$FL_144_DO),mean)
##            Group.1        x
## 1   Block1onedigit 5.707147
## 2 Block2fivedigits 5.753826
## 3 Block3ninedigits 5.755814
aggregate(MainStudy$PurchInt,list(MainStudy$FL_144_DO),sd)
##            Group.1        x
## 1   Block1onedigit 2.149082
## 2 Block2fivedigits 2.014544
## 3 Block3ninedigits 2.075547
summary(aov(MainStudy$PurchInt~MainStudy$FL_144_DO))
##                       Df Sum Sq Mean Sq F value Pr(>F)
## MainStudy$FL_144_DO    2      1   0.395   0.091  0.913
## Residuals           1541   6677   4.333
aov.out<-aov(PurchInt~as.factor(FL_144_DO),MainStudy)
TukeyHSD(aov.out)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = PurchInt ~ as.factor(FL_144_DO), data = MainStudy)
## 
## $`as.factor(FL_144_DO)`
##                                          diff        lwr       upr
## Block2fivedigits-Block1onedigit   0.046678307 -0.2580329 0.3513895
## Block3ninedigits-Block1onedigit   0.048666578 -0.2537656 0.3510988
## Block3ninedigits-Block2fivedigits 0.001988272 -0.3043017 0.3082782
##                                       p adj
## Block2fivedigits-Block1onedigit   0.9312922
## Block3ninedigits-Block1onedigit   0.9244620
## Block3ninedigits-Block2fivedigits 0.9998721
## There are no significant differences in purchase intent as a consequence of cognitive load, H1 is rejected


table(MainStudy$FL_148_DO)
## 
##                            Block4Mediacontenthigh Block5mediacontentmedium 
##                        0                      519                      514 
##    Block6mediacontentlow 
##                      511
aggregate(MainStudy$ProdQuality,list(MainStudy$FL_148_DO),mean)
##                    Group.1        x
## 1   Block4Mediacontenthigh 6.498073
## 2 Block5mediacontentmedium 6.542802
## 3    Block6mediacontentlow 6.112524
aggregate(MainStudy$ProdQuality,list(MainStudy$FL_148_DO),sd)
##                    Group.1        x
## 1   Block4Mediacontenthigh 1.622640
## 2 Block5mediacontentmedium 1.450236
## 3    Block6mediacontentlow 1.696250
summary(aov(MainStudy$ProdQuality~MainStudy$FL_148_DO))
##                       Df Sum Sq Mean Sq F value   Pr(>F)    
## MainStudy$FL_148_DO    2     57  28.686    11.3 1.34e-05 ***
## Residuals           1541   3910   2.537                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aov.out<-aov(ProdQuality~as.factor(FL_148_DO),MainStudy)
TukeyHSD(aov.out)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = ProdQuality ~ as.factor(FL_148_DO), data = MainStudy)
## 
## $`as.factor(FL_148_DO)`
##                                                        diff        lwr
## Block5mediacontentmedium-Block4Mediacontenthigh  0.04472834 -0.1878164
## Block6mediacontentlow-Block4Mediacontenthigh    -0.38554876 -0.6184362
## Block6mediacontentlow-Block5mediacontentmedium  -0.43027709 -0.6637258
##                                                        upr     p adj
## Block5mediacontentmedium-Block4Mediacontenthigh  0.2772731 0.8938660
## Block6mediacontentlow-Block4Mediacontenthigh    -0.1526613 0.0003155
## Block6mediacontentlow-Block5mediacontentmedium  -0.1968284 0.0000485
## There are significant differences in perceived quality of the product as a consequence of media quality, H2 accepted (partially)

summary(lm(MainStudy$PurchInt~MainStudy$ProdQuality))
## 
## Call:
## lm(formula = MainStudy$PurchInt ~ MainStudy$ProdQuality)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.0721 -0.7684  0.3260  1.0075  5.2639 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            0.46478    0.16774   2.771  0.00566 ** 
## MainStudy$ProdQuality  0.82592    0.02548  32.416  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.605 on 1542 degrees of freedom
## Multiple R-squared:  0.4053, Adjusted R-squared:  0.4049 
## F-statistic:  1051 on 1 and 1542 DF,  p-value: < 2.2e-16
## Prod quality affects purchase intention, H3 accepted



## 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")