Quick tour of R’s Capabilities

Some add-on packages that we’ll beed:

# install.packages(c("lavaan", "semPlot", "corrplot", "multcomp"))

Load a data ser from the book’s website:

satData <- read.csv("http://goo.gl/UDv12g")
satData$Segment <- factor(satData$Segment)
head(satData)
##   iProdSAT iSalesSAT Segment iProdREC iSalesREC
## 1        6         2       1        4         3
## 2        4         5       3        4         4
## 3        5         3       4        5         4
## 4        3         3       2        4         4
## 5        3         3       3        2         2
## 6        4         4       4        5         4

Plot the correlation matrix (omitting the Segment column):

library(corrplot)
corrplot.mixed(cor(satData[,-3]))

Mean satisfaction for each segment:

aggregate(iProdSAT ~ Segment, satData, mean)
##   Segment iProdSAT
## 1       1 3.462963
## 2       2 3.725191
## 3       3 4.103896
## 4       4 4.708075

Are the differences statistically significant:

sat.anova <- aov(iProdSAT ~ -1 + Segment, satData)
summary(sat.anova)
##            Df Sum Sq Mean Sq F value Pr(>F)    
## Segment     4   8628    2157    2161 <2e-16 ***
## Residuals 496    495       1                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Plot the ANOVA model to visualize confidence intervals for mean product satisfaction by segment:

suppressMessages(suppressWarnings(library(multcomp)))
par(mar=c(4, 8, 4, 2))
plot(glht(sat.anova))

The X axis represents a Likert rating scale ranging 1-7 for product satisfaction.

Structural equation model on the satisfaction data

Latent SATisfaction is observed as items iProdSAT and iSalesSAT. Latent likelihood to RECommend is observed as items iProdREC and i SalesREC. RECommendation varies with SATisfaction:

satModel <- "SAT =~ iProdSAT + iSalesSAT
                REC =~ iProdREC + iSalesREC
                REC ~ SAT"

Fit the model with lavaan:

suppressMessages(suppressWarnings(library(lavaan)))
sat.fit <- cfa(satModel, data=satData)
summary(sat.fit, fit.m=TRUE)
## lavaan (0.5-18) converged normally after  31 iterations
## 
##   Number of observations                           500
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                2.319
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.128
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              278.557
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    0.995
##   Tucker-Lewis Index (TLI)                       0.971
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -3040.385
##   Loglikelihood unrestricted model (H1)      -3039.225
## 
##   Number of free parameters                          9
##   Akaike (AIC)                                6098.769
##   Bayesian (BIC)                              6136.701
##   Sample-size adjusted Bayesian (BIC)         6108.134
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.051
##   90 Percent Confidence Interval          0.000  0.142
##   P-value RMSEA <= 0.05                          0.347
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.012
## 
## Parameter estimates:
## 
##   Information                                 Expected
##   Standard Errors                             Standard
## 
##                    Estimate  Std.err  Z-value  P(>|z|)
## Latent variables:
##   SAT =~
##     iProdSAT          1.000
##     iSalesSAT         1.067    0.173    6.154    0.000
##   REC =~
##     iProdREC          1.000
##     iSalesREC         0.900    0.138    6.528    0.000
## 
## Regressions:
##   REC ~
##     SAT               0.758    0.131    5.804    0.000
## 
## Variances:
##     iProdSAT          0.706    0.088
##     iSalesSAT         0.793    0.100
##     iProdREC          0.892    0.129
##     iSalesREC         0.808    0.107
##     SAT               0.483    0.097
##     REC               0.516    0.115

Visualize the structural model:

library(semPlot)
semPaths(sat.fit, what="est", residuals=FALSE, intercepts=FALSE, nCharNodes=9)

A structural model with path loadings for a model of product satisfaction and likelihood-to-recommend. Satisfaction has a strong relationship to likelihood-to-recommend: coefficient=0.76