library(openxlsx)
library(corrplot)
library(psych)
library(car)
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
phoneData<-read.xlsx(xlsxFile = 'questionnaire.xlsx',sheet = 'data')
brand<-phoneData$brand #被调查的品牌
age<-phoneData$q29 #被调查者年龄
major<-phoneData$q30 #被调查者专业
degree<-phoneData$q31 #被调查者最高学历
brandInUse<-phoneData$q32 #被调查者使用的手机品牌
brand<-factor(brand,levels = c(2,4,6,7),labels = c('Sumsang','Apple','HTC','Huawei')) #将brand转换为因子类型
myFun<-function(data,levels,labels) #自定义一个函数,去除缺失值,并将向量转换为因子类型
{
data<-data[!is.na(data)]
data<-factor(data,levels,labels)
return(data)
}
age<-myFun(age,c(1,2,3),c('18-25岁','26-30岁','31-35岁'))
major<-myFun(major,c(1,2,3,4,5),c('理科','工科','人文','经管','其他'))
#degree<-myFun(degree,c(1,3,4,7),c('中专及以下','大专','本科','硕士及以上'))
#####################################
#因为在填答问卷的时候,被调查者自己的手机品牌是自己填写的,而不是标准的选项,因此就有可能出现同一品牌不同写法,比如索尼爱立信和索爱表示的是个同一个手机品牌,下面对该变量单独处理
brandInUse<-brandInUse[!is.na(brandInUse)] #删除缺失值
brandInUse<-factor(brandInUse) #转换为因子类型
summary(brandInUse) #可以看到上面说的状况
## _HTC_ _iphone htc
## 12 7 4
## HTC iphone iPhone
## 8 4 4
## iphone 4s iphone4 LG
## 2 6 4
## ME525+ motorola MOTOROLA
## 2 8 9
## oppo palm TCL
## 2 7 2
## 贝尔丰 波导 海信Hisense
## 2 4 4
## 黑莓 华为 康佳
## 2 10 2
## 酷派 联想 魅族
## 2 7 2
## 摩托罗拉 诺基亚 诺基亚,iphone,三星
## 11 84 6
## 诺基亚_ 苹果 三星
## 6 20 26
## 山寨 索爱 索爱_
## 2 8 6
## 索尼爱立信 天语 小米
## 9 2 12
brandInUse<-gsub('_','',brandInUse) #去除下划线
brandInUse[brandInUse=='htc']<-'HTC' #将htc HTC合并为HTC
brandInUse[brandInUse=='索尼爱立信']<-'索爱' #将索尼爱立信改成索爱
brandInUse[brandInUse %in% c('motorola','MOTOROLA','摩托罗拉')]<-'MOTO' #摩托罗拉相关的改成MOTO
brandInUse[grep('*iphone*',brandInUse,ignore.case = TRUE)]<-'苹果' #包含有iphone的全部改为苹果
sort(table(brandInUse),decreasing = TRUE) #可以看出排在前列的基本是诺基亚、苹果、三星等品牌
## brandInUse
## 诺基亚 苹果 MOTO 三星 HTC 索爱
## 90 49 28 26 24 23
## 小米 华为 palm 联想 LG 波导
## 12 10 7 7 4 4
## 海信Hisense ME525+ oppo TCL 贝尔丰 黑莓
## 4 2 2 2 2 2
## 康佳 酷派 魅族 山寨 天语
## 2 2 2 2 2
brandInUse[!(brandInUse %in% c('诺基亚','苹果','MOTO','三星','HTC','索爱'))]<-'其他'
brand_table<-sort(prop.table(table(brandInUse)),decreasing = TRUE)
#################################处理最高学历##############
#因为最高学历的“中专及以下”和“硕士及以上”的数量比较小,因此将二者合并为其他
degree<-degree[!(is.na(degree))]
degree[degree==1 | degree==7]<-'其他'
degree[degree==3]<-'大专'
degree[degree==4]<-'本科'
degree<-as.factor(degree)
可以看到,当时还处于诺基亚的霸主时代,苹果、摩托罗拉、三星、HTC和索爱分处2-6位。
barplot(c(brand_table[-2],brand_table[2]),main = '被调查者使用手机品牌统计',ylim=c(0,0.3))
大多数被调查者是在校大学生,因此其年龄也大多分布在18-25岁。
barplot(prop.table(table(age)),ylim = c(0,1.00),main = '被调查者年龄统计')
经管类的大学生所占的比例最高,达到了70%。
barplot(prop.table(sort(table(major),decreasing = TRUE)),ylim=c(0,0.8),main = '被调查者就读专业统计')
本科和大专学历的占到全部被调查者人数的90%以上。
barplot(prop.table(sort(table(degree),decreasing = TRUE)),ylim=c(0,0.5),main = '被调查者最高学历统计')
首先,将q1-q28共28个属性值赋予phoneData_attrs
phoneData_attrs<-phoneData[,3:30]
查看每一行是否具有缺失值
sum(!complete.cases(phoneData_attrs))
## [1] 3
由于只有3行数据有缺失,所占样本比值=3/424=0.7%,因此可以直接将这三行数据删除
phoneData_attrs<-phoneData_attrs[complete.cases(phoneData_attrs),]
然后,绘制出这28个变量的相关图,观察变量之间的相关性
library(corrplot)
corrplot(cor(phoneData_attrs))
#将彼此相关的区域框出来
intervals<-c(0,8,2,12,3,3)
xleft<-cumsum(intervals)[1:5]+0.5
ybottom<-rev(cumsum(rev(intervals)))[2:6]+0.5
xright<-cumsum(intervals)[2:6]+0.5
ytop<-c(ybottom[2:5],0.5)
rect(xleft,ybottom,xright,ytop,border = '#B22222',lwd = 1.5)
从上面的相关图可以看出,28个变量之间都具有正向的相关关系,而且存在某些簇,该簇内所有的变量之间都具有较强的相关关系。对应于用户体验、性价比、象征价值、满意度和忠诚度,相关图中框出了相对应的变量。 鉴于以上分析,本文拟采用因子分析方法,探索用户体验、性价比、象征价值三个因子对于满意度、忠诚度的影响作用。
library(psych) #包内的fa()函数由于因子分析
independent<-phoneData_attrs[,1:22] #拟做回归分析的自变量
dependent<-phoneData_attrs[,23:28] #拟做回归分析的因变量
###################对前22个变量做因子分析###################
fa_indep<-fa(independent,nfactors = 3,rotate = 'varimax',fm = 'pa') #社会调查一般采用主成分法提取公因子,因子旋转采用方差最大化方法
cumsum(fa_indep$values)[3]/22 #前三个公因子的方差贡献率为51%,无法直接使用这三个公因子,考虑去除一些与其他变量相关性比较低的变量。
## [1] 0.5084897
indepCorMat<-cor(independent)
indepCorMat[indepCorMat<0.3]=0 #这样输出的相关图中相关性低于0.3的将会显示空白
corrplot(indepCorMat)
#从相关图的结果来看,将q6,q8,q9,q12,q13,q17,q18,q19,q22删去,还剩下13个变量
independent2<-independent[,-c(6,8,9,12,13,19,22,17,18)]
corrplot(cor(independent2)) #查看剩下的13的变量的相关性
#######################对剩下的13个变量做因子分析#############
fa_indep2<-fa(independent2,nfactors = 3,rotate = 'varimax',fm = 'pa')
cumsum(fa_indep2$values)[3]/13 #方差贡献率达到了60%,在社会调查中,已经足以做因子分析
## [1] 0.5995008
#查看一下具体的输出结果
fa_indep2
## Factor Analysis using method = pa
## Call: fa(r = independent2, nfactors = 3, rotate = "varimax", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
## PA2 PA1 PA3 h2 u2 com
## q1 0.70 0.29 0.29 0.66 0.34 1.7
## q2 0.57 0.45 0.11 0.54 0.46 2.0
## q3 0.66 0.28 0.33 0.61 0.39 1.9
## q4 0.64 0.42 0.22 0.63 0.37 2.0
## q5 0.63 0.22 0.35 0.57 0.43 1.9
## q7 0.52 0.31 0.15 0.39 0.61 1.8
## q10 0.32 0.24 0.55 0.47 0.53 2.0
## q11 0.37 0.71 0.18 0.68 0.32 1.7
## q14 0.47 0.59 0.28 0.65 0.35 2.4
## q15 0.26 0.71 0.47 0.79 0.21 2.0
## q16 0.30 0.65 0.34 0.64 0.36 2.0
## q20 0.41 0.66 0.23 0.66 0.34 2.0
## q21 0.27 0.43 0.51 0.52 0.48 2.5
##
## PA2 PA1 PA3
## SS loadings 3.18 3.15 1.47
## Proportion Var 0.24 0.24 0.11
## Cumulative Var 0.24 0.49 0.60
## Proportion Explained 0.41 0.40 0.19
## Cumulative Proportion 0.41 0.81 1.00
##
## Mean item complexity = 2
## Test of the hypothesis that 3 factors are sufficient.
##
## The degrees of freedom for the null model are 78 and the objective function was 8.01 with Chi Square of 3324.8
## The degrees of freedom for the model are 42 and the objective function was 0.23
##
## The root mean square of the residuals (RMSR) is 0.02
## The df corrected root mean square of the residuals is 0.03
##
## The harmonic number of observations is 421 with the empirical chi square 28.48 with prob < 0.94
## The total number of observations was 421 with Likelihood Chi Square = 95.78 with prob < 4.4e-06
##
## Tucker Lewis Index of factoring reliability = 0.969
## RMSEA index = 0.055 and the 90 % confidence intervals are 0.038 0.062
## BIC = -158.01
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## PA2 PA1 PA3
## Correlation of scores with factors 0.86 0.86 0.71
## Multiple R square of scores with factors 0.74 0.74 0.51
## Minimum correlation of possible factor scores 0.48 0.48 0.01
可以看出,在因子分析结果中,前三个公因子累计方差贡献率达到60%。其中,PA2在q1,q2,q3,q4,q5,q7上的载荷较大,代表“用户体验”因子;PA1在q11,q14,q15,q16,q20上的载荷较大,代表“象征价值”因子;PA3在q10上的载荷较大,代表“性价比”因子. 三个公因子的因子得分存储在fa_indep2$scores变量里。 接下来,对q23,…,q28共六个变量进行因子分析,查看其分析结果。
fa_dep<-fa(dependent,nfactors = 2,rotate = 'varimax',fm='pa')
cumsum(fa_dep$values)[3]/6 #累积方差贡献率达到了62%,可以做因子分析
## [1] 0.6272286
#查看具体的结果
fa_dep
## Factor Analysis using method = pa
## Call: fa(r = dependent, nfactors = 2, rotate = "varimax", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
## PA1 PA2 h2 u2 com
## q23 0.75 0.44 0.76 0.24 1.6
## q24 0.72 0.32 0.62 0.38 1.4
## q25 0.64 0.50 0.67 0.33 1.9
## q26 0.41 0.71 0.67 0.33 1.6
## q27 0.37 0.77 0.73 0.27 1.4
## q28 0.23 0.46 0.27 0.73 1.5
##
## PA1 PA2
## SS loadings 1.86 1.85
## Proportion Var 0.31 0.31
## Cumulative Var 0.31 0.62
## Proportion Explained 0.50 0.50
## Cumulative Proportion 0.50 1.00
##
## Mean item complexity = 1.6
## Test of the hypothesis that 2 factors are sufficient.
##
## The degrees of freedom for the null model are 15 and the objective function was 3.11 with Chi Square of 1295.96
## The degrees of freedom for the model are 4 and the objective function was 0.02
##
## The root mean square of the residuals (RMSR) is 0.01
## The df corrected root mean square of the residuals is 0.02
##
## The harmonic number of observations is 421 with the empirical chi square 1.87 with prob < 0.76
## The total number of observations was 421 with Likelihood Chi Square = 7.64 with prob < 0.11
##
## Tucker Lewis Index of factoring reliability = 0.989
## RMSEA index = 0.046 and the 90 % confidence intervals are 0 0.073
## BIC = -16.53
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## PA1 PA2
## Correlation of scores with factors 0.84 0.83
## Multiple R square of scores with factors 0.70 0.69
## Minimum correlation of possible factor scores 0.40 0.38
可以看出,PA1在q23,q24,q25上的载荷较大,代表“满意度”因子,PA2在q26,q27,q28上的载荷较大,代表“忠诚度”因子。其因子得分存储在fa_dep$scores变量里。
根据两次因子分析的结果,计算因子得分,将结果存储在数据框reduction中。
usrExp<-fa_indep2$scores[,1] #用户体验
symbVal<-fa_indep2$scores[,2] #象征价值
cstPfm<-fa_indep2$scores[,3] #性价比
satisfaction<-fa_dep$scores[,1] #满意度
loyalty<-fa_dep$scores[,2]
reduction<-data.frame(usrExp,symbVal,cstPfm,satisfaction,loyalty) #因子得分
summary(reduction)
## usrExp symbVal cstPfm
## Min. :-5.11075 Min. :-3.26087 Min. :-2.931169
## 1st Qu.:-0.50989 1st Qu.:-0.55930 1st Qu.:-0.385082
## Median : 0.07858 Median : 0.08563 Median : 0.005662
## Mean : 0.00000 Mean : 0.00000 Mean : 0.000000
## 3rd Qu.: 0.60041 3rd Qu.: 0.60766 3rd Qu.: 0.475674
## Max. : 2.22189 Max. : 2.56300 Max. : 1.983427
## satisfaction loyalty
## Min. :-2.49179 Min. :-3.19187
## 1st Qu.:-0.56177 1st Qu.:-0.48142
## Median : 0.07316 Median : 0.04957
## Mean : 0.00000 Mean : 0.00000
## 3rd Qu.: 0.63242 3rd Qu.: 0.58056
## Max. : 2.68954 Max. : 1.85174
从summary()的结果来看,因子得分是经过标准化的,因此可以直接用于回归建模。
#探究满意度与三个自变量的关系
lm.satis<-lm(formula = satisfaction~usrExp+symbVal+cstPfm,data = reduction)
summary(lm.satis)
##
## Call:
## lm(formula = satisfaction ~ usrExp + symbVal + cstPfm, data = reduction)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.15079 -0.29793 0.01691 0.30727 3.06019
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.962e-16 2.809e-02 0.000 1
## usrExp 2.261e-01 3.351e-02 6.747 5.08e-11 ***
## symbVal 4.195e-01 3.415e-02 12.284 < 2e-16 ***
## cstPfm 4.338e-01 4.168e-02 10.408 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5763 on 417 degrees of freedom
## Multiple R-squared: 0.5288, Adjusted R-squared: 0.5254
## F-statistic: 156 on 3 and 417 DF, p-value: < 2.2e-16
#探究忠诚度与三个自变量的关系
lm.loya<-lm(formula = loyalty~usrExp+symbVal+cstPfm,data = reduction)
summary(lm.loya)
##
## Call:
## lm(formula = loyalty ~ usrExp + symbVal + cstPfm, data = reduction)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.35906 -0.27012 0.02808 0.32904 2.24262
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.714e-16 2.853e-02 0.000 1
## usrExp 3.667e-01 3.404e-02 10.773 < 2e-16 ***
## symbVal 4.212e-01 3.468e-02 12.143 < 2e-16 ***
## cstPfm 2.419e-01 4.234e-02 5.714 2.1e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5854 on 417 degrees of freedom
## Multiple R-squared: 0.5085, Adjusted R-squared: 0.5049
## F-statistic: 143.8 on 3 and 417 DF, p-value: < 2.2e-16
根据4.2部分的回归分析,可以得出如下回归模型:
满意度=0.226x用户体验+0.420x象征价值+0.434x性价比
忠诚度=0.367x用户体验+0.421x象征价值+0.242x性价比
该模型表示,如果想提高产品的满意度,应该想办法提提高产品的性价比,也就是说,性价比是用户非常看重的一个方面。另一方面,如何留住顾客,提高用户的忠诚度,则需要提升用户体验。