#Analisis Jalur
library(readxl)
df<- read_excel("C:/Users/ASUS/Downloads/kepuasan pelanggan (2).xlsx")
head(df)
## # A tibble: 6 × 5
##   produk harga layanan kepuasan loyalitas
##    <dbl> <dbl>   <dbl>    <dbl>     <dbl>
## 1     18    18      16       15        14
## 2     15    18      18       12        12
## 3     18    15      16       14        11
## 4     14    15      15       13        11
## 5     15    15      16       12        11
## 6     17    16      16       13        12
##           vars  n  mean   sd median trimmed  mad min max range  skew kurtosis
## produk       1 30 14.60 3.30   15.0   14.83 2.97   4  20    16 -0.97     1.56
## harga        2 30 15.07 2.12   15.0   15.04 2.22  11  19     8  0.02    -0.86
## layanan      3 30 15.47 2.57   16.0   15.67 1.48   8  21    13 -0.67     0.80
## kepuasan     4 30 12.57 1.87   13.0   12.71 1.48   8  15     7 -0.61    -0.51
## loyalitas    5 30 11.30 1.84   11.5   11.38 0.74   6  15     9 -0.59     0.76
##             se
## produk    0.60
## harga     0.39
## layanan   0.47
## kepuasan  0.34
## loyalitas 0.34

## corrplot 0.92 loaded

specmod <- "kepuasan ~produk + harga + layanan  "
int.model <- lm(specmod, data=df)
summary(int.model)
## 
## Call:
## lm(formula = specmod, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.9883 -1.1432  0.1984  0.8499  2.5063 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  5.33636    2.18443   2.443   0.0217 *
## produk       0.23871    0.10064   2.372   0.0254 *
## harga       -0.02162    0.13057  -0.166   0.8698  
## layanan      0.26320    0.13319   1.976   0.0588 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.417 on 26 degrees of freedom
## Multiple R-squared:  0.4848, Adjusted R-squared:  0.4254 
## F-statistic: 8.157 on 3 and 26 DF,  p-value: 0.0005436
library(QuantPsyc)
## Loading required package: boot
## 
## Attaching package: 'boot'
## The following object is masked from 'package:psych':
## 
##     logit
## Loading required package: 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
## Loading required package: purrr
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## 
## Attaching package: 'QuantPsyc'
## The following object is masked from 'package:base':
## 
##     norm
lm.beta(int.model)
##     produk      harga    layanan 
##  0.4209403 -0.0244733  0.3617342
specmod <- "loyalitas ~ kepuasan"
bhv.model <- lm(specmod, data=df)
summary(bhv.model)
## 
## Call:
## lm(formula = specmod, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.4535 -0.7973  0.1522  0.7004  1.9504 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.2706     1.3846   0.918    0.367    
## kepuasan      0.7981     0.1090   7.321  5.7e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.098 on 28 degrees of freedom
## Multiple R-squared:  0.6568, Adjusted R-squared:  0.6446 
## F-statistic: 53.59 on 1 and 28 DF,  p-value: 5.698e-08
lm.beta(bhv.model)
##  kepuasan 
## 0.8104462
sqrt(1-summary(int.model)$r.squared)
## [1] 0.7177415
sqrt(1-summary(bhv.model)$r.squared)
## [1] 0.5858131
library(lavaan)
## This is lavaan 0.6-12
## lavaan is FREE software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
specmod <- "
# Jalur langsung model A dan B (pada regresi) dianalisis bersamaan dengan kovariansnya juga
kepuasan ~produk + harga + layanan
loyalitas ~ kepuasan

# Kovarians (korelasi antar variabel eksogen)
produk ~~ harga + layanan
harga ~~ layanan
"
fitmod <- sem(specmod, data=df)

summary(fitmod, standardized = TRUE)
## lavaan 0.6-12 ended normally after 34 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        12
## 
##   Number of observations                            30
## 
## Model Test User Model:
##                                                       
##   Test statistic                                16.779
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.001
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   kepuasan ~                                                            
##     produk            0.239    0.094    2.548    0.011    0.239    0.421
##     harga            -0.022    0.122   -0.178    0.859   -0.022   -0.024
##     layanan           0.263    0.124    2.123    0.034    0.263    0.362
##   loyalitas ~                                                           
##     kepuasan          0.798    0.105    7.577    0.000    0.798    0.810
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   produk ~~                                                             
##     harga             1.260    1.253    1.006    0.314    1.260    0.187
##     layanan           4.987    1.750    2.849    0.004    4.987    0.609
##   harga ~~                                                              
##     layanan           1.602    1.003    1.597    0.110    1.602    0.305
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .kepuasan          1.741    0.449    3.873    0.000    1.741    0.515
##    .loyalitas         1.124    0.290    3.873    0.000    1.124    0.343
##     produk           10.507    2.713    3.873    0.000   10.507    1.000
##     harga             4.329    1.118    3.873    0.000    4.329    1.000
##     layanan           6.382    1.648    3.873    0.000    6.382    1.000
fitmeasures(fitmod)
##                npar                fmin               chisq                  df 
##              12.000               0.280              16.779               3.000 
##              pvalue      baseline.chisq         baseline.df     baseline.pvalue 
##               0.001              85.589              10.000               0.000 
##                 cfi                 tli                nnfi                 rfi 
##               0.818               0.392               0.392               0.347 
##                 nfi                pnfi                 ifi                 rni 
##               0.804               0.241               0.833               0.818 
##                logl   unrestricted.logl                 aic                 bic 
##            -299.564            -291.174             623.127             639.942 
##              ntotal                bic2               rmsea      rmsea.ci.lower 
##              30.000             602.579               0.391               0.223 
##      rmsea.ci.upper        rmsea.pvalue                 rmr          rmr_nomean 
##               0.583               0.001               0.372               0.372 
##                srmr        srmr_bentler srmr_bentler_nomean                crmr 
##               0.096               0.096               0.096               0.118 
##         crmr_nomean          srmr_mplus   srmr_mplus_nomean               cn_05 
##               0.118               0.096               0.096              14.973 
##               cn_01                 gfi                agfi                pgfi 
##              21.284               0.854               0.269               0.171 
##                 mfi                ecvi 
##               0.795               1.359
library(semPlot)
semPaths(fitmod, "std", rotation=2, layout = "tree2", curvature = 2, nCharNodes = 0, nDigits = 3,
         sizeMan = 10, sizeInt = 5, sizeLat = 5, edge.label.cex=1.2, exoVar = FALSE, fade=FALSE)