library(openxlsx)
d5.7 = read.xlsx('C:/Users/12290/Desktop/多元统计表格/mvexer5.xlsx',sheet = 'E5.7')
d5.7
## 实验号 充磁量 定位角度 线圈匝数 输出力矩 是否启动
## 1 1 900 10 70 160 0
## 2 2 900 11 80 215 1
## 3 3 900 12 90 180 0
## 4 4 1100 10 70 168 0
## 5 5 1100 11 80 236 1
## 6 6 1100 12 90 190 0
## 7 7 1300 10 70 157 1
## 8 8 1300 11 80 205 1
## 9 9 1300 12 90 140 0
attach(d5.7)
x1=d5.7$充磁量
x2=d5.7$定位角度
x3=d5.7$线圈匝数
y=d5.7$输出力矩
Y=d5.7$是否启动
#相关系数的计算与假设检验
cor(x1,y)
## [1] -0.2473469
cor.test(x1,y)
##
## Pearson's product-moment correlation
##
## data: x1 and y
## t = -0.67541, df = 7, p-value = 0.5211
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.7828681 0.4986946
## sample estimates:
## cor
## -0.2473469
cor(x2,y)
## [1] 0.1166731
cor.test(x2,y)
##
## Pearson's product-moment correlation
##
## data: x2 and y
## t = 0.31081, df = 7, p-value = 0.765
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.5934307 0.7246455
## sample estimates:
## cor
## 0.1166731
cor(x3,y)
## [1] 0.1166731
cor.test(x3,y)
##
## Pearson's product-moment correlation
##
## data: x3 and y
## t = 0.31081, df = 7, p-value = 0.765
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.5934307 0.7246455
## sample estimates:
## cor
## 0.1166731
plot(d5.7[-1],gap=0)
根据P值和散点图来看,每一个单独变量与输出力矩之间都没有呈现线性关系
fm=lm(y~x1+x2+x3+x1*x2+x1*x3+x2*x3+x1*x2*x3)
#整体方差分析
anova(fm)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## x1 1 468.2 468.2 1.2644 0.34268
## x2 1 104.2 104.2 0.2813 0.63259
## x1:x2 1 342.2 342.2 0.9243 0.40727
## x2:x3 1 5582.7 5582.7 15.0771 0.03026 *
## x1:x2:x3 1 44.1 44.1 0.1191 0.75284
## Residuals 3 1110.8 370.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
P(x2:x3)<0.05,说明定位角度和线圈匝数对输出力矩有显著影响
#将输出力矩与是否启动成功建立一个logistic回归模型
logit.glm<-glm(Y~y,family = binomial)
pre1<-predict(logit.glm,data.frame(y=291))
p1<-exp(pre1)/(1+exp(pre1))
p1
## 1
## 0.9972859
library(MASS)
ld=lda(Y~y) #线性判别分析函数
ld
## Call:
## lda(Y ~ y)
##
## Prior probabilities of groups:
## 0 1
## 0.5555556 0.4444444
##
## Group means:
## y
## 0 167.60
## 1 203.25
##
## Coefficients of linear discriminants:
## LD1
## y 0.03807743
lp=predict(ld) #根据线性判别模型预测所属类别
Y1=lp$class #预测的所属类别结果
data.frame(Y,Y1)
## Y Y1
## 1 0 0
## 2 1 1
## 3 0 0
## 4 0 0
## 5 1 1
## 6 0 1
## 7 1 0
## 8 1 1
## 9 0 0
九个预测值中只有一个出错,因此该判别函数可靠度较高