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
cat("\014") # cleans screen
rm(list=ls(all=TRUE)) # remove variables in working memory
setwd("C:/Users/Erik Ernesto Vazquez/Downloads") # sets working directory
Study<-read.csv("Book1.csv",header=T) # reads raw data from Qualtrics
Study<-subset(Study,Study$X.Compras.alimentos.empaquetados.=="Si")
cronbach(cbind(Study[,9:11]))
## $sample.size
## [1] 145
##
## $number.of.items
## [1] 3
##
## $alpha
## [1] 0.9161399
cronbach(cbind(Study[,4:7]))
## $sample.size
## [1] 146
##
## $number.of.items
## [1] 4
##
## $alpha
## [1] 0.8317682
Study$Trust<-(Study$Con.base.en.tu.respuesta.anterior...le.tienes.confianza.a.la.marca.+
Study$X.Consideras.que.es.una.marca.honesta.+Study$X.Consideras.que.es.una.marca.segura.)/3
Study$Loyalty<-(Study$Prefiero.una.marca.de.comida.empaquetada.para.la.mayoría.de.los.productos.que.compro...bimbo..gamesa..nabisco..herdez..del.monte..fud..danone..nestle..etc.+
Study$Estoy.dispuesto.a.hacer.un.esfuerzo.para.buscar.mi.marca.favorita.de.comida.empaquetada...bimbo..gamesa..nabisco..herdez..del.monte..fud..danone..nestle..etc.+
Study$Normalmente.me.importa.mucho.que.marca.de.comida.empaquetada.en.particular.compro.+
Study$Estoy.dispuesto.a.pagar.un.poco.más.por.mi.marca.favorita.)/4
t.test(Study$Trust~Study$Genero)
##
## Welch Two Sample t-test
##
## data: Study$Trust by Study$Genero
## t = 0.077599, df = 142.99, p-value = 0.9383
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.5188188 0.5612176
## sample estimates:
## mean in group Hombre mean in group Mujer
## 7.514706 7.493506
summary(lm(Study$Trust~Study$Edad))
##
## Call:
## lm(formula = Study$Trust ~ Study$Edad)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.6375 -0.6996 0.5099 1.3392 1.5952
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.280644 0.351392 20.719 <2e-16 ***
## Study$Edad 0.007759 0.011264 0.689 0.492
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.653 on 143 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.003306, Adjusted R-squared: -0.003663
## F-statistic: 0.4744 on 1 and 143 DF, p-value: 0.4921
Study$Generation<-ifelse(Study$Edad<23,1,(ifelse(Study$Edad>38,3,2)))
summary(lm(Study$Trust~Study$Genero*Study$Edad))
##
## Call:
## lm(formula = Study$Trust ~ Study$Genero * Study$Edad)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.6174 -0.6816 0.4820 1.3344 1.6237
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.2941671 0.5786585 12.605 <2e-16 ***
## Study$GeneroMujer -0.0464033 0.7430289 -0.062 0.950
## Study$Edad 0.0082900 0.0203863 0.407 0.685
## Study$GeneroMujer:Study$Edad -0.0002551 0.0246862 -0.010 0.992
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.664 on 141 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.003564, Adjusted R-squared: -0.01764
## F-statistic: 0.1681 on 3 and 141 DF, p-value: 0.9177
summary(lm(Study$Trust~Study$Genero*Study$Generation))
##
## Call:
## lm(formula = Study$Trust ~ Study$Genero * Study$Generation)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.5806 -0.5806 0.4508 1.4194 1.6183
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.21429 0.62923 11.465 <2e-16
## Study$GeneroMujer 0.14282 0.77556 0.184 0.854
## Study$Generation 0.16745 0.33217 0.504 0.615
## Study$GeneroMujer:Study$Generation -0.09296 0.40114 -0.232 0.817
##
## (Intercept) ***
## Study$GeneroMujer
## Study$Generation
## Study$GeneroMujer:Study$Generation
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.665 on 141 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.002615, Adjusted R-squared: -0.01861
## F-statistic: 0.1232 on 3 and 141 DF, p-value: 0.9463
summary(lm(Study$Loyalty~Study$Trust))
##
## Call:
## lm(formula = Study$Loyalty ~ Study$Trust)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.4798 -0.9792 0.2703 1.0208 3.2714
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.72592 0.59191 1.226 0.222
## Study$Trust 0.75045 0.07706 9.739 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.525 on 143 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.3988, Adjusted R-squared: 0.3946
## F-statistic: 94.84 on 1 and 143 DF, p-value: < 2.2e-16
t.test(Study$Loyalty~Study$Genero)
##
## Welch Two Sample t-test
##
## data: Study$Loyalty by Study$Genero
## t = 0.080398, df = 141.84, p-value = 0.936
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.6171170 0.6694415
## sample estimates:
## mean in group Hombre mean in group Mujer
## 6.376812 6.350649
summary(lm(Study$Loyalty~Study$Edad))
##
## Call:
## lm(formula = Study$Loyalty ~ Study$Edad)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.3882 -1.1004 0.6169 1.3981 2.6525
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.321353 0.416146 15.190 <2e-16 ***
## Study$Edad 0.001453 0.013361 0.109 0.914
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.962 on 144 degrees of freedom
## Multiple R-squared: 8.209e-05, Adjusted R-squared: -0.006862
## F-statistic: 0.01182 on 1 and 144 DF, p-value: 0.9136
Study$Generation<-ifelse(Study$Edad<23,1,(ifelse(Study$Edad>38,3,2)))
summary(lm(Study$Loyalty~Study$Genero*Study$Edad))
##
## Call:
## lm(formula = Study$Loyalty ~ Study$Genero * Study$Edad)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.3570 -1.0810 0.5847 1.3930 2.6769
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.170251 0.684322 9.017 1.2e-15 ***
## Study$GeneroMujer 0.216319 0.879905 0.246 0.806
## Study$Edad 0.007780 0.024169 0.322 0.748
## Study$GeneroMujer:Study$Edad -0.008954 0.029276 -0.306 0.760
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.975 on 142 degrees of freedom
## Multiple R-squared: 0.0008096, Adjusted R-squared: -0.0203
## F-statistic: 0.03835 on 3 and 142 DF, p-value: 0.9899
summary(lm(Study$Loyalty~Study$Genero*Study$Generation))
##
## Call:
## lm(formula = Study$Loyalty ~ Study$Genero * Study$Generation)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.4516 -0.9803 0.4891 1.4166 2.9171
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.7143 0.7440 7.681 2.35e-12
## Study$GeneroMujer 0.8098 0.9170 0.883 0.379
## Study$Generation 0.3687 0.3924 0.939 0.349
## Study$GeneroMujer:Study$Generation -0.4634 0.4740 -0.978 0.330
##
## (Intercept) ***
## Study$GeneroMujer
## Study$Generation
## Study$GeneroMujer:Study$Generation
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.968 on 142 degrees of freedom
## Multiple R-squared: 0.007103, Adjusted R-squared: -0.01387
## F-statistic: 0.3386 on 3 and 142 DF, p-value: 0.7974